From cc0436b8f3418a343e88b133c97d0f2dd5a3061c Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Mon, 23 Aug 2021 09:32:21 +0200 Subject: [PATCH] refactoring part 1 --- public/mix-manifest.json | 22 ++++++-- resources/js/App.vue | 4 +- .../FilePreview/FilePreviewToolbar.vue | 4 +- .../js/components/FilesView/FileItemGrid.vue | 2 +- .../js/components/FilesView/FileItemList.vue | 2 +- resources/js/helpers/functionHelpers.js | 52 +++++++------------ resources/js/store/modules/fileFunctions.js | 26 +++++----- resources/js/store/modules/sharing.js | 1 - 8 files changed, 54 insertions(+), 59 deletions(-) diff --git a/public/mix-manifest.json b/public/mix-manifest.json index f6ed40c3..d43c6335 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -60,7 +60,7 @@ "/chunks/plan-subscribers.js": "/chunks/plan-subscribers.js?id=0dd0a5efe0e3cb511c48", "/chunks/plans.js": "/chunks/plans.js?id=5a3c28288952fcad96e5", "/chunks/platform.js": "/chunks/platform.js?id=1961d3ff45861ab12b2e", - "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=7dec07de559c752d108a", + "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=7e1b520699fcd958093d", "/chunks/platform~chunks/shared/file-browser.js": "/chunks/platform~chunks/shared/file-browser.js?id=b142ad8801528b166787", "/chunks/platform~chunks/shared~chunks/shared/file-browser.js": "/chunks/platform~chunks/shared~chunks/shared/file-browser.js?id=6ba92eab6a45cbab3af5", "/chunks/profile.js": "/chunks/profile.js?id=658aa03af778cc2cc100", @@ -130,11 +130,11 @@ "/chunks/admin~chunks/platform~chunks/settings~chunks/shared/files.js": "/chunks/admin~chunks/platform~chunks/settings~chunks/shared/files.js?id=dba77fc6b158bc3c2e4e", "/chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-items~chunks/page~477ccadb.js": "/chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-items~chunks/page~477ccadb.js?id=914f040c5966894873f8", "/chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-items~chunks/page~9b5759a9.js": "/chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-items~chunks/page~9b5759a9.js?id=eb26643e072aa1f2b4b5", - "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared/files~chunks/trash.js": "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared/files~chunks/trash.js?id=55e78339ed8a448de2a3", + "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared/files~chunks/trash.js": "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared/files~chunks/trash.js?id=61760c506a36f8fc3414", "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~chunks/share~c3a97969.js": "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~chunks/share~c3a97969.js?id=5cda983d60a85c9168e9", "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~chunks/share~cd83f396.js": "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~chunks/share~cd83f396.js?id=f9f2e41ad11f62057c58", "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/settings-subscription~chunks/shared~f23e39b6.js": "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/settings-subscription~chunks/shared~f23e39b6.js?id=5216516ba11c29601c91", - "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/shared/single-f~222c7501.js": "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/shared/single-f~222c7501.js?id=968b0922210751711d85", + "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/shared/single-f~222c7501.js": "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/shared/single-f~222c7501.js?id=6966f455db86cfa3ac1d", "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/trash.js": "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/trash.js?id=21ce7c8e1167b492c6fc", "/chunks/platform~chunks/shared/files.js": "/chunks/platform~chunks/shared/files.js?id=a1891e149640c9a838f4", "/chunks/platform~chunks/shared~chunks/shared/files.js": "/chunks/platform~chunks/shared~chunks/shared/files.js?id=1ed2d41883a929aa1bc7", @@ -266,5 +266,19 @@ "/chunks/shared/files.9c1f5a1e2142e3917cc8.hot-update.js": "/chunks/shared/files.9c1f5a1e2142e3917cc8.hot-update.js", "/chunks/shared.cde14eab29cace2a2532.hot-update.js": "/chunks/shared.cde14eab29cace2a2532.hot-update.js", "/chunks/shared.c56b0776a832cb5d3a20.hot-update.js": "/chunks/shared.c56b0776a832cb5d3a20.hot-update.js", - "/chunks/shared.2d4c2d5eb7cd67286673.hot-update.js": "/chunks/shared.2d4c2d5eb7cd67286673.hot-update.js" + "/chunks/shared.2d4c2d5eb7cd67286673.hot-update.js": "/chunks/shared.2d4c2d5eb7cd67286673.hot-update.js", + "/js/main.2dc33fb9c4c6daf1358a.hot-update.js": "/js/main.2dc33fb9c4c6daf1358a.hot-update.js", + "/js/main.b36245a10a02aa233608.hot-update.js": "/js/main.b36245a10a02aa233608.hot-update.js", + "/js/main.b1f085f0208db9506ffe.hot-update.js": "/js/main.b1f085f0208db9506ffe.hot-update.js", + "/js/main.50f565ef11d298310391.hot-update.js": "/js/main.50f565ef11d298310391.hot-update.js", + "/js/main.0b9340d217f336c8e552.hot-update.js": "/js/main.0b9340d217f336c8e552.hot-update.js", + "/js/main.20c42794e0de43739151.hot-update.js": "/js/main.20c42794e0de43739151.hot-update.js", + "/js/main.283cd45c38cab2fffdae.hot-update.js": "/js/main.283cd45c38cab2fffdae.hot-update.js", + "/chunks/platform~chunks/shared.14dd2f98211f4e775e23.hot-update.js": "/chunks/platform~chunks/shared.14dd2f98211f4e775e23.hot-update.js", + "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared/files~chunks/trash.078cc5f518d5567c3f64.hot-update.js": "/chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared/files~chunks/trash.078cc5f518d5567c3f64.hot-update.js", + "/js/main.ef3b071eeedace9f1412.hot-update.js": "/js/main.ef3b071eeedace9f1412.hot-update.js", + "/js/main.d8795fe465011e10f4c2.hot-update.js": "/js/main.d8795fe465011e10f4c2.hot-update.js", + "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/shared/single-f~222c7501.d8795fe465011e10f4c2.hot-update.js": "/chunks/files~chunks/my-shared-items~chunks/recent-uploads~chunks/shared/files~chunks/shared/single-f~222c7501.d8795fe465011e10f4c2.hot-update.js", + "/js/main.4fea36154a307113ca40.hot-update.js": "/js/main.4fea36154a307113ca40.hot-update.js", + "/js/main.02000e1bbba29a831689.hot-update.js": "/js/main.02000e1bbba29a831689.hot-update.js" } diff --git a/resources/js/App.vue b/resources/js/App.vue index fa6530c7..fe965f76 100644 --- a/resources/js/App.vue +++ b/resources/js/App.vue @@ -108,7 +108,9 @@ export default { }) }, mounted() { - this.$checkOS() + if (this.$isWIndows()) { + document.body.classList.add('windows') + } } } diff --git a/resources/js/components/FilePreview/FilePreviewToolbar.vue b/resources/js/components/FilePreview/FilePreviewToolbar.vue index dc904b3c..e223f020 100644 --- a/resources/js/components/FilePreview/FilePreviewToolbar.vue +++ b/resources/js/components/FilePreview/FilePreviewToolbar.vue @@ -115,9 +115,7 @@ return activeIndex }, canShareItem() { - return this.$isThisLocation([ - 'base', 'latest', 'shared' - ]) + return this.$isThisRoute(this.$route, ['Files', 'RecentUploads', 'MySharedItems']) }, }, methods: { diff --git a/resources/js/components/FilesView/FileItemGrid.vue b/resources/js/components/FilesView/FileItemGrid.vue index 4f28c113..630131e0 100644 --- a/resources/js/components/FilesView/FileItemGrid.vue +++ b/resources/js/components/FilesView/FileItemGrid.vue @@ -121,7 +121,7 @@ export default { }, canEditName() { return !this.$isMobile() - && !this.$isThisLocation(['trash', 'trash-root']) + && !this.$isThisRoute(this.$route, ['Trash']) && !this.$checkPermission('visitor') && !(this.sharedDetail && this.sharedDetail.type === 'file') }, diff --git a/resources/js/components/FilesView/FileItemList.vue b/resources/js/components/FilesView/FileItemList.vue index f160f68b..910083ad 100644 --- a/resources/js/components/FilesView/FileItemList.vue +++ b/resources/js/components/FilesView/FileItemList.vue @@ -117,7 +117,7 @@ export default { return mimetypes.includes(this.item.mimetype) && this.item.type === 'audio' }, canEditName() { - return !this.$isMobile() && !this.$isThisLocation(['trash', 'trash-root']) && !this.$checkPermission('visitor') && !(this.sharedDetail && this.sharedDetail.type === 'file') + return !this.$isMobile() && !this.$isThisRoute(this.$route, ['Trash']) && !this.$checkPermission('visitor') && !(this.sharedDetail && this.sharedDetail.type === 'file') }, canDrag() { return !this.isDeleted && this.$checkPermission(['master', 'editor']) diff --git a/resources/js/helpers/functionHelpers.js b/resources/js/helpers/functionHelpers.js index 29342a1a..08f46ac1 100644 --- a/resources/js/helpers/functionHelpers.js +++ b/resources/js/helpers/functionHelpers.js @@ -212,20 +212,6 @@ const FunctionHelpers = { return locations.includes(route.name) } - Vue.prototype.$isThisLocation = function (location) { - - // Get current location - let currentLocation = store.getters.currentFolder && store.getters.currentFolder.location ? store.getters.currentFolder.location : undefined - - // Check if type is object - if (typeof location === 'Object' || location instanceof Object) { - return location.includes(currentLocation) - - } else { - return currentLocation === location - } - } - Vue.prototype.$checkPermission = function (type) { let currentPermission = store.getters.permission @@ -239,22 +225,6 @@ const FunctionHelpers = { } } - Vue.prototype.$isMobile = function () { - const toMatch = [ - /Android/i, - /webOS/i, - /iPhone/i, - /iPad/i, - /iPod/i, - /BlackBerry/i, - /Windows Phone/i - ] - - return toMatch.some(toMatchItem => { - return navigator.userAgent.match(toMatchItem) - }) - } - Vue.prototype.$isSomethingWrong = function () { events.$emit('alert:open', { title: i18n.t('popup_error.title'), @@ -305,10 +275,8 @@ const FunctionHelpers = { } // Detect windows - Vue.prototype.$checkOS = function () { - if (navigator.userAgent.indexOf('Windows') != -1) { - document.body.classList.add('windows') - } + Vue.prototype.$isWIndows = function () { + return navigator.userAgent.indexOf('Windows') != -1 } // Check if device is Apple @@ -328,6 +296,22 @@ const FunctionHelpers = { }) } + Vue.prototype.$isMobile = function () { + const toMatch = [ + /Android/i, + /webOS/i, + /iPhone/i, + /iPad/i, + /iPod/i, + /BlackBerry/i, + /Windows Phone/i + ] + + return toMatch.some(toMatchItem => { + return navigator.userAgent.match(toMatchItem) + }) + } + Vue.prototype.$closePopup = function () { events.$emit('popup:close') } diff --git a/resources/js/store/modules/fileFunctions.js b/resources/js/store/modules/fileFunctions.js index 96447c92..3b85c423 100644 --- a/resources/js/store/modules/fileFunctions.js +++ b/resources/js/store/modules/fileFunctions.js @@ -104,11 +104,10 @@ const actions = { events.$emit('newFolder:focus', response.data.id) }, 10) - if (! Vue.prototype.$isThisRoute(router, ['Public'])) - dispatch('getAppData') - - if (Vue.prototype.$isThisRoute(router, ['Public'])) + if (Vue.prototype.$isThisRoute(router.currentRoute, ['Public'])) dispatch('getFolderTree') + else + dispatch('getAppData') }) .catch(() => Vue.prototype.$isSomethingWrong()) @@ -132,9 +131,9 @@ const actions = { .then(response => { commit('CHANGE_ITEM_NAME', response.data) - if (data.type === 'folder' && getters.currentFolder.location !== 'public') + if (data.type === 'folder' && ! Vue.prototype.$isThisRoute(router.currentRoute, ['Public'])) dispatch('getAppData') - if (data.type === 'folder' && getters.currentFolder.location === 'public') + if (data.type === 'folder' && Vue.prototype.$isThisRoute(router.currentRoute, ['Public'])) dispatch('getFolderTree') }) .catch(() => Vue.prototype.$isSomethingWrong()) @@ -179,7 +178,7 @@ const actions = { commit('SHIFT_FROM_FILE_QUEUE') // Check if user is in uploading folder, if yes, than show new file - if (response.data.folder_id == getters.currentFolder.id) { + if (response.data.folder_id === getters.currentFolder.id) { // Add uploaded item into view commit('ADD_NEW_ITEMS', response.data) @@ -283,7 +282,7 @@ const actions = { items.forEach(data => { itemsToDelete.push({ - force_delete: data.deleted_at ? true : false, + force_delete: !!data.deleted_at, type: data.type, id: data.id }) @@ -325,7 +324,7 @@ const actions = { }) .then(() => { - itemsToDelete.forEach(data => { + /*itemsToDelete.forEach(data => { // If is folder, update app data if (data.type === 'folder') { @@ -339,13 +338,12 @@ const actions = { } } } - }) + })*/ - if (getters.currentFolder.location !== 'public') - dispatch('getAppData') - - if (getters.currentFolder.location === 'public') + if (Vue.prototype.$isThisRoute(router.currentRoute, ['Public'])) dispatch('getFolderTree') + else + dispatch('getAppData') }) .catch(() => Vue.prototype.$isSomethingWrong()) diff --git a/resources/js/store/modules/sharing.js b/resources/js/store/modules/sharing.js index e896eb19..916250c9 100644 --- a/resources/js/store/modules/sharing.js +++ b/resources/js/store/modules/sharing.js @@ -42,7 +42,6 @@ const actions = { }) }, getSingleFile: ({commit}) => { - axios.get(`/api/browse/file/${router.currentRoute.params.token}`) .then(response => { commit('STORE_SHARED_FILE', response.data)