|
| 1 | +<template> |
| 2 | + <div class="fm d-flex flex-column" v-bind:class="{ 'fm-full-screen': fullScreen }"> |
| 3 | + <navbar-block /> |
| 4 | + <div class="fm-body d-flex"> |
| 5 | + <notification-block /> |
| 6 | + <context-menu /> |
| 7 | + <modal-block v-if="showModal" /> |
| 8 | + <template v-if="windowsConfig === 1"> |
| 9 | + <left-manager class="col" manager="left" /> |
| 10 | + </template> |
| 11 | + <template v-else-if="windowsConfig === 2"> |
| 12 | + <folder-tree class="col-4 col-md-3" /> |
| 13 | + <left-manager class="col-8 col-md-9" manager="left" /> |
| 14 | + </template> |
| 15 | + <template v-else-if="windowsConfig === 3"> |
| 16 | + <left-manager |
| 17 | + class="col-12 col-sm-6" |
| 18 | + manager="left" |
| 19 | + v-on:click.native="selectManager('left')" |
| 20 | + v-on:contextmenu.native="selectManager('left')" |
| 21 | + > |
| 22 | + </left-manager> |
| 23 | + <right-manager |
| 24 | + class="col-12 col-sm-6" |
| 25 | + manager="right" |
| 26 | + v-on:click.native="selectManager('right')" |
| 27 | + v-on:contextmenu.native="selectManager('right')" |
| 28 | + > |
| 29 | + </right-manager> |
| 30 | + </template> |
| 31 | + </div> |
| 32 | + <info-block /> |
| 33 | + </div> |
| 34 | +</template> |
| 35 | + |
| 36 | +<script> |
| 37 | +/* eslint-disable import/no-duplicates, no-param-reassign */ |
| 38 | +import { mapState } from 'vuex'; |
| 39 | +// Axios |
| 40 | +import HTTP from '../http/axios'; |
| 41 | +import EventBus from '../emitter'; |
| 42 | +// Components |
| 43 | +import NavbarBlock from './blocks/NavbarBlock.vue'; |
| 44 | +import FolderTree from './tree/FolderTree.vue'; |
| 45 | +import LeftManager from './manager/Manager.vue'; |
| 46 | +import RightManager from './manager/Manager.vue'; |
| 47 | +import ModalBlock from './modals/ModalBlock.vue'; |
| 48 | +import InfoBlock from './blocks/InfoBlock.vue'; |
| 49 | +import ContextMenu from './blocks/ContextMenu.vue'; |
| 50 | +import NotificationBlock from './blocks/NotificationBlock.vue'; |
| 51 | +// Mixins |
| 52 | +import translate from '../mixins/translate'; |
| 53 | +
|
| 54 | +export default { |
| 55 | + name: 'FileManager', |
| 56 | + mixins: [translate], |
| 57 | + components: { |
| 58 | + NavbarBlock, |
| 59 | + FolderTree, |
| 60 | + LeftManager, |
| 61 | + RightManager, |
| 62 | + ModalBlock, |
| 63 | + InfoBlock, |
| 64 | + ContextMenu, |
| 65 | + NotificationBlock, |
| 66 | + }, |
| 67 | + props: { |
| 68 | + /** |
| 69 | + * LFM manual settings |
| 70 | + */ |
| 71 | + settings: { |
| 72 | + type: Object, |
| 73 | + default() { |
| 74 | + return {}; |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + data() { |
| 79 | + return { |
| 80 | + interceptorIndex: { |
| 81 | + request: null, |
| 82 | + response: null, |
| 83 | + }, |
| 84 | + }; |
| 85 | + }, |
| 86 | + created() { |
| 87 | + // manual settings |
| 88 | + this.$store.commit('fm/settings/manualSettings', this.settings); |
| 89 | +
|
| 90 | + // initiate Axios |
| 91 | + this.$store.commit('fm/settings/initAxiosSettings'); |
| 92 | + this.setAxiosConfig(); |
| 93 | + this.requestInterceptor(); |
| 94 | + this.responseInterceptor(); |
| 95 | +
|
| 96 | + // initialize app settings |
| 97 | + this.$store.dispatch('fm/initializeApp'); |
| 98 | + }, |
| 99 | + destroyed() { |
| 100 | + // reset state |
| 101 | + this.$store.dispatch('fm/resetState'); |
| 102 | +
|
| 103 | + // delete events |
| 104 | + EventBus.all.clear(); |
| 105 | +
|
| 106 | + // eject interceptors |
| 107 | + HTTP.interceptors.request.eject(this.interceptorIndex.request); |
| 108 | + HTTP.interceptors.response.eject(this.interceptorIndex.response); |
| 109 | + }, |
| 110 | + computed: { |
| 111 | + ...mapState('fm', { |
| 112 | + windowsConfig: (state) => state.settings.windowsConfig, |
| 113 | + activeManager: (state) => state.settings.activeManager, |
| 114 | + showModal: (state) => state.modal.showModal, |
| 115 | + fullScreen: (state) => state.settings.fullScreen, |
| 116 | + }), |
| 117 | + }, |
| 118 | + methods: { |
| 119 | + /** |
| 120 | + * Axios default config |
| 121 | + */ |
| 122 | + setAxiosConfig() { |
| 123 | + HTTP.defaults.baseURL = this.$store.getters['fm/settings/baseUrl']; |
| 124 | + HTTP.defaults.headers = this.$store.getters['fm/settings/headers']; |
| 125 | + }, |
| 126 | +
|
| 127 | + /** |
| 128 | + * Add axios request interceptor |
| 129 | + */ |
| 130 | + requestInterceptor() { |
| 131 | + this.interceptorIndex.request = HTTP.interceptors.request.use( |
| 132 | + (config) => { |
| 133 | + // loading spinner + |
| 134 | + this.$store.commit('fm/messages/addLoading'); |
| 135 | +
|
| 136 | + return config; |
| 137 | + }, |
| 138 | + (error) => { |
| 139 | + // loading spinner - |
| 140 | + this.$store.commit('fm/messages/subtractLoading'); |
| 141 | + return Promise.reject(error); |
| 142 | + } |
| 143 | + ); |
| 144 | + }, |
| 145 | +
|
| 146 | + /** |
| 147 | + * Add axios response interceptor |
| 148 | + */ |
| 149 | + responseInterceptor() { |
| 150 | + this.interceptorIndex.response = HTTP.interceptors.response.use( |
| 151 | + (response) => { |
| 152 | + // loading spinner - |
| 153 | + this.$store.commit('fm/messages/subtractLoading'); |
| 154 | +
|
| 155 | + // create notification, if find message text |
| 156 | + if (Object.prototype.hasOwnProperty.call(response.data, 'result')) { |
| 157 | + if (response.data.result.message) { |
| 158 | + const message = { |
| 159 | + status: response.data.result.status, |
| 160 | + message: Object.prototype.hasOwnProperty.call( |
| 161 | + this.lang.response, |
| 162 | + response.data.result.message |
| 163 | + ) |
| 164 | + ? this.lang.response[response.data.result.message] |
| 165 | + : response.data.result.message, |
| 166 | + }; |
| 167 | +
|
| 168 | + // show notification |
| 169 | + EventBus.emit('addNotification', message); |
| 170 | +
|
| 171 | + // set action result |
| 172 | + this.$store.commit('fm/messages/setActionResult', message); |
| 173 | + } |
| 174 | + } |
| 175 | +
|
| 176 | + return response; |
| 177 | + }, |
| 178 | + (error) => { |
| 179 | + // loading spinner - |
| 180 | + this.$store.commit('fm/messages/subtractLoading'); |
| 181 | +
|
| 182 | + const errorMessage = { |
| 183 | + status: 0, |
| 184 | + message: '', |
| 185 | + }; |
| 186 | +
|
| 187 | + const errorNotificationMessage = { |
| 188 | + status: 'error', |
| 189 | + message: '', |
| 190 | + }; |
| 191 | +
|
| 192 | + // add message |
| 193 | + if (error.response) { |
| 194 | + errorMessage.status = error.response.status; |
| 195 | +
|
| 196 | + if (error.response.data.message) { |
| 197 | + const trMessage = Object.prototype.hasOwnProperty.call( |
| 198 | + this.lang.response, |
| 199 | + error.response.data.message |
| 200 | + ) |
| 201 | + ? this.lang.response[error.response.data.message] |
| 202 | + : error.response.data.message; |
| 203 | +
|
| 204 | + errorMessage.message = trMessage; |
| 205 | + errorNotificationMessage.message = trMessage; |
| 206 | + } else { |
| 207 | + errorMessage.message = error.response.statusText; |
| 208 | + errorNotificationMessage.message = error.response.statusText; |
| 209 | + } |
| 210 | + } else if (error.request) { |
| 211 | + errorMessage.status = error.request.status; |
| 212 | + errorMessage.message = error.request.statusText || 'Network error'; |
| 213 | + errorNotificationMessage.message = error.request.statusText || 'Network error'; |
| 214 | + } else { |
| 215 | + errorMessage.message = error.message; |
| 216 | + errorNotificationMessage.message = error.message; |
| 217 | + } |
| 218 | +
|
| 219 | + // set error message |
| 220 | + this.$store.commit('fm/messages/setError', errorMessage); |
| 221 | +
|
| 222 | + // show notification |
| 223 | + EventBus.emit('addNotification', errorNotificationMessage); |
| 224 | +
|
| 225 | + return Promise.reject(error); |
| 226 | + } |
| 227 | + ); |
| 228 | + }, |
| 229 | +
|
| 230 | + /** |
| 231 | + * Select manager (when shown 2 file manager windows) |
| 232 | + * @param managerName |
| 233 | + */ |
| 234 | + selectManager(managerName) { |
| 235 | + if (this.activeManager !== managerName) { |
| 236 | + this.$store.commit('fm/setActiveManager', managerName); |
| 237 | + } |
| 238 | + }, |
| 239 | + }, |
| 240 | +}; |
| 241 | +</script> |
| 242 | + |
| 243 | +<style lang="scss"> |
| 244 | +.fm { |
| 245 | + position: relative; |
| 246 | + height: 100%; |
| 247 | + padding: 1rem; |
| 248 | + background-color: white; |
| 249 | +
|
| 250 | + &:-moz-full-screen { |
| 251 | + background-color: white; |
| 252 | + } |
| 253 | +
|
| 254 | + &:-webkit-full-screen { |
| 255 | + background-color: white; |
| 256 | + } |
| 257 | +
|
| 258 | + &:fullscreen { |
| 259 | + background-color: white; |
| 260 | + } |
| 261 | +
|
| 262 | + .fm-body { |
| 263 | + flex: 1 1 auto; |
| 264 | + overflow: hidden; |
| 265 | + position: relative; |
| 266 | + padding-top: 1rem; |
| 267 | + padding-bottom: 1rem; |
| 268 | + border-top: 1px solid #6c757d; |
| 269 | + border-bottom: 1px solid #6c757d; |
| 270 | + } |
| 271 | +
|
| 272 | + .unselectable { |
| 273 | + user-select: none; |
| 274 | + } |
| 275 | +} |
| 276 | +
|
| 277 | +.fm-error { |
| 278 | + color: white; |
| 279 | + background-color: #dc3545; |
| 280 | + border-color: #dc3545; |
| 281 | +} |
| 282 | +
|
| 283 | +.fm-danger { |
| 284 | + color: #dc3545; |
| 285 | + background-color: white; |
| 286 | + border-color: #dc3545; |
| 287 | +} |
| 288 | +
|
| 289 | +.fm-warning { |
| 290 | + color: #ffc107; |
| 291 | + background-color: white; |
| 292 | + border-color: #ffc107; |
| 293 | +} |
| 294 | +
|
| 295 | +.fm-success { |
| 296 | + color: #198754; |
| 297 | + background-color: white; |
| 298 | + border-color: #198754; |
| 299 | +} |
| 300 | +
|
| 301 | +.fm-info { |
| 302 | + color: #0dcaf0; |
| 303 | + background-color: white; |
| 304 | + border-color: #0dcaf0; |
| 305 | +} |
| 306 | +
|
| 307 | +.fm.fm-full-screen { |
| 308 | + width: 100%; |
| 309 | + height: 100%; |
| 310 | + padding-bottom: 0; |
| 311 | +} |
| 312 | +</style> |
0 commit comments