Skip to content

Commit af5f241

Browse files
committed
dynamic config, fix small bugs, add serbian translation
1 parent c9e2381 commit af5f241

File tree

14 files changed

+351
-105
lines changed

14 files changed

+351
-105
lines changed

README.md

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
77
![Laravel File Manager](https://raw.github.com/alexusmai/vue-laravel-file-manager/master/src/assets/laravel-file-manager.gif?raw=true)
88

9-
# v 2.0.0
9+
# v 2.4.0
1010

11-
* Audio player (mp3, ogg, wav, aac), Video player (webm, mp4) - ([Plyr](https://github.com/sampotts/plyr))
12-
* Code editor - ([Code Mirror](https://github.com/codemirror/codemirror))
13-
* Image cropper - ([Cropper.js](https://github.com/fengyuanchen/cropperjs))
14-
* Zip / Unzip - only for local disks
11+
Now you can overwrite default settings using props
1512

1613

1714
## Installation
@@ -52,6 +49,32 @@ Vue.use(FileManager, {store});
5249
You can overwrite some default settings
5350

5451
```
52+
// In the new version 2.4.0 and higher
53+
<file-manager v-bind:settings="settings"></file-manager>
54+
55+
...
56+
// settings object structure
57+
settings: {
58+
// axios headers
59+
headers: {
60+
'X-Requested-With': 'XMLHttpRequest',
61+
Authorization: `Bearer ${window.localStorage.getItem('user-token')}`,
62+
},
63+
baseUrl: 'http://test.loc/file-manager/', // overwrite base url Axios
64+
windowsConfig: 2, // overwrite config
65+
lang: 'de', // set language
66+
translation: { // add new translation
67+
name: de,
68+
content: {
69+
about: 'Über',
70+
back: 'Zurück',
71+
... see lang file structure
72+
},
73+
},
74+
},
75+
...
76+
77+
// Old versions
5578
Vue.use(FileManager, {
5679
store, // required
5780
@@ -67,10 +90,10 @@ Vue.use(FileManager, {
6790
'X-CSRF-TOKEN': 'set laravel csrf token here...'
6891
},
6992
70-
baseUrl: 'http://my_url/file-manager/', // overwrite base url Axios
93+
baseUrl: 'http://my_url/file-manager/', // overwrite base url Axios
7194
windowsConfig: 2,
72-
lang: 'de', // set language
73-
translation: { // add new translation
95+
lang: 'de', // set language
96+
translation: { // add new translation
7497
name: de,
7598
content: {
7699
about: 'Über',
@@ -86,6 +109,20 @@ Now vue component is registered and you can use it in your app
86109
<file-manager></file-manager>
87110
```
88111

112+
## Available Props
113+
114+
### settings - Object
115+
116+
| Attribute | Type | Example | Required | Description |
117+
| --------- | ---- | ------- | -------- | ----------- |
118+
| headers | Object | {'X-Requested-With': 'XMLHttpRequest'} | No | Axios Headers |
119+
| baseUrl | String | 'http://my_url:80/file-manager/' | No | Axios base URL |
120+
| windowsConfig | Int | 2 | No | 1 - only one manager, 2 - manager with folder tree, 3 - two managers |
121+
| lang | String | 'de' | No | Set language |
122+
| translation | Object | { ... see lang file structure }, | No | Add new translation |
123+
124+
## CSRF, Bootstrap, FontAwesome
125+
89126
Don't forget add a csrf token to head block in your Laravel view and add bootstrap 4 and fontawesome 5 styles
90127
```
91128
<!-- CSRF Token -->

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laravel-file-manager",
3-
"version": "2.3.2",
3+
"version": "2.4.0",
44
"description": "File manager for Laravel",
55
"keywords": [
66
"laravel",

src/FileManager.vue

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,24 @@ export default {
5858
ContextMenu,
5959
Notification,
6060
},
61-
computed: {
62-
...mapState('fm', {
63-
windowsConfig: state => state.settings.windowsConfig,
64-
activeManager: state => state.settings.activeManager,
65-
showModal: state => state.modal.showModal,
66-
fullScreen: state => state.settings.fullScreen,
67-
}),
61+
props: {
62+
/**
63+
* LFM manual settings
64+
*/
65+
settings: {
66+
type: Object,
67+
default() {
68+
return {};
69+
},
70+
},
6871
},
6972
created() {
70-
// initiate Axios settings - baseUrl and headers
71-
this.$store.commit('fm/settings/initAxiosSettings');
73+
// manual settings
74+
this.$store.commit('fm/settings/manualSettings', this.settings);
7275
73-
// add axios request interceptor
76+
// initiate Axios
77+
this.$store.commit('fm/settings/initAxiosSettings');
7478
this.requestInterceptor();
75-
76-
// add axios response interceptor
7779
this.responseInterceptor();
7880
7981
// initialize app settings
@@ -91,16 +93,29 @@ export default {
9193
});
9294
*/
9395
},
96+
destroyed() {
97+
// reset state
98+
this.$store.dispatch('fm/resetState');
99+
100+
// delete events
101+
EventBus.$off(['contextMenu', 'addNotification']);
102+
},
103+
computed: {
104+
...mapState('fm', {
105+
windowsConfig: state => state.settings.windowsConfig,
106+
activeManager: state => state.settings.activeManager,
107+
showModal: state => state.modal.showModal,
108+
fullScreen: state => state.settings.fullScreen,
109+
}),
110+
},
94111
methods: {
95112
/**
96113
* Add axios request interceptor
97114
*/
98115
requestInterceptor() {
99116
HTTP.interceptors.request.use((config) => {
100-
// overwrite base url
117+
// overwrite base url and headers
101118
config.baseURL = this.$store.getters['fm/settings/baseUrl'];
102-
103-
// overwrite headers
104119
config.headers = this.$store.getters['fm/settings/headers'];
105120
106121
// loading spinner +
@@ -110,7 +125,6 @@ export default {
110125
}, (error) => {
111126
// loading spinner -
112127
this.$store.commit('fm/messages/subtractLoading');
113-
// Do something with request error
114128
return Promise.reject(error);
115129
});
116130
},

src/components/blocks/mixins/contextMenu.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,5 @@ export default {
101101

102102
return extension.toLowerCase() === 'zip';
103103
},
104-
105-
/**
106-
* Generate link for downloading selected file
107-
* @returns {string}
108-
*/
109-
downloadLink() {
110-
return `${this.$store.getters['fm/settings/baseUrl']}download?disk=${this.selectedDisk}&path=${encodeURIComponent(this.selectedItems[0].path)}`;
111-
},
112104
},
113105
};

src/components/blocks/mixins/contextMenuActions.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import HTTP from '../../../http/get';
2+
13
/**
24
* Context menu actions
35
* {name}Action
@@ -74,17 +76,24 @@ export default {
7476
* Download file
7577
*/
7678
downloadAction() {
77-
// download file
7879
const tempLink = document.createElement('a');
7980
tempLink.style.display = 'none';
80-
tempLink.href = this.downloadLink();
8181
tempLink.setAttribute('download', this.selectedItems[0].basename);
82-
tempLink.setAttribute('target', '_blank');
83-
document.body.appendChild(tempLink);
84-
// click link
85-
tempLink.click();
86-
// remove link
87-
document.body.removeChild(tempLink);
82+
83+
// download file with authorization
84+
if (this.$store.getters['fm/settings/authHeader']) {
85+
HTTP.download(this.selectedDisk, this.selectedItems[0].path).then((response) => {
86+
tempLink.href = window.URL.createObjectURL(new Blob([response.data]));
87+
document.body.appendChild(tempLink);
88+
tempLink.click();
89+
document.body.removeChild(tempLink);
90+
});
91+
} else {
92+
tempLink.href = `${this.$store.getters['fm/settings/baseUrl']}download?disk=${this.selectedDisk}&path=${encodeURIComponent(this.selectedItems[0].path)}`;
93+
document.body.appendChild(tempLink);
94+
tempLink.click();
95+
document.body.removeChild(tempLink);
96+
}
8897
},
8998

9099
/**

src/components/manager/TableView.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
v-show="sortSettings.direction === 'up'"></i>
3131
</template>
3232
</th>
33-
<th v-on:click="sortBy('date')">
33+
<th class="w-auto" v-on:click="sortBy('date')">
3434
{{ lang.manager.table.date }}
3535
<template v-if="sortSettings.field === 'date'">
3636
<i class="fas fa-sort-amount-down"
@@ -71,8 +71,7 @@
7171
v-on:contextmenu.prevent="contextMenu(file, $event)">
7272
<td class="fm-content-item unselectable"
7373
v-bind:class="(acl && file.acl === 0) ? 'text-hidden' : ''">
74-
<i class="far"
75-
v-bind:class="extensionToIcon(file.extension)"></i>
74+
<i class="far" v-bind:class="extensionToIcon(file.extension)"></i>
7675
{{ file.filename ? file.filename : file.basename }}
7776
</td>
7877
<td>{{ bytesToHuman(file.size) }}</td>
@@ -143,6 +142,7 @@ export default {
143142
td {
144143
white-space: nowrap;
145144
overflow: hidden;
145+
text-overflow: ellipsis;
146146
}
147147
148148
tr:hover {
@@ -159,6 +159,7 @@ export default {
159159
160160
.fm-content-item {
161161
cursor: pointer;
162+
max-width: 1px;
162163
}
163164
164165
.text-hidden {

src/http/get.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,17 @@ export default {
9393
params: { disk, path },
9494
});
9595
},
96+
97+
/**
98+
* Download file
99+
* @param disk
100+
* @param path
101+
* @return {*}
102+
*/
103+
download(disk, path) {
104+
return HTTP.get('download', {
105+
responseType: 'arraybuffer',
106+
params: { disk, path },
107+
});
108+
},
96109
};

src/init.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@ import FileManager from './FileManager.vue';
44
/**
55
* Install
66
*
7-
* options = {
8-
* store, // required
9-
*
10-
* // not required params
11-
* headers: {'Authorization': 'Bearer ...'}, // add header
12-
* OR
13-
* headers: {'X-CSRF-TOKEN': 'token'}, // overwrite default header Axios
14-
* baseUrl: 'http://my_url:80/file-manager/', // overwrite base url Axios
15-
* windowsConfig: 2, // overwrite config
16-
* lang: 'de',
17-
* translation: {
18-
* name: de,
19-
* content: {
20-
* about: 'Über',
21-
* back: 'Zurück',
22-
* ... see lang file structure
23-
* },
24-
* },
25-
* }
26-
*
277
* @param Vue
288
* @param options
299
*/
@@ -33,6 +13,4 @@ export default function install(Vue, options = {}) {
3313
Vue.component('file-manager', FileManager);
3414

3515
options.store.registerModule('fm', store);
36-
37-
options.store.commit('fm/settings/manualSettings', options);
3816
}

0 commit comments

Comments
 (0)