From a3516769de570573363917f401ebb12065e3faf1 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Tue, 31 Aug 2021 14:08:47 +0200 Subject: [PATCH] team folder browsing with static team folder details --- config/vuefilemanager.php | 4 +- public/mix-manifest.json | 44 ++++++++++-- .../components/FilesView/DesktopToolbar.vue | 17 +++-- .../js/components/FilesView/FileItemList.vue | 33 ++------- .../Teams/Components/TeamFolderPreview.vue | 10 ++- .../Teams/Components/TeamMembersButton.vue | 12 ++-- resources/js/helpers/functionHelpers.js | 19 ++++-- resources/js/store/index.js | 2 + resources/js/store/modules/fileBrowser.js | 29 -------- resources/js/store/modules/teams.js | 68 +++++++++++++++++++ resources/js/views/FileView/TeamFolders.vue | 1 + .../Console/Commands/SetupDevEnvironment.php | 50 +++++++------- src/App/Users/Models/User.php | 7 +- src/App/Users/Models/UserSettings.php | 1 - .../Controllers/BrowseFolderController.php | 10 ++- .../BrowseLatestFilesController.php | 2 +- .../BrowseSharedItemsController.php | 4 +- .../BrowseTrashContentController.php | 5 +- .../SearchFilesAndFoldersController.php | 4 +- .../VisitorBrowseFolderController.php | 5 +- ...VisitorSearchFilesAndFoldersController.php | 4 +- .../Controllers/UploadFileController.php | 7 +- src/Domain/Files/Resources/FileResource.php | 7 +- .../Controllers/CreateFolderController.php | 2 +- src/Domain/Folders/Models/Folder.php | 44 +++++++----- .../Folders/Resources/FolderResource.php | 13 ++-- .../Actions/RenameFileOrFolderAction.php | 3 - .../RenameFileOrFolderController.php | 2 +- .../VisitorRenameFileOrFolderController.php | 5 +- .../Controllers/LanguageController.php | 4 +- .../Sharing/Actions/SendViaEmailAction.php | 2 +- .../Sharing/Resources/ShareResource.php | 3 +- .../BrowseSharedWithMeController.php | 2 +- .../ConvertFolderIntoTeamFolderController.php | 6 +- .../Controllers/InvitationsController.php | 6 +- .../Controllers/TeamFoldersController.php | 68 ++++++++++--------- src/Domain/Teams/DTO/CreateTeamFolderData.php | 1 - .../Requests/ConvertIntoTeamFolderRequest.php | 1 - .../Requests/CreateTeamFolderRequest.php | 1 - .../UpdateTeamFolderMembersRequest.php | 1 - .../Resources/TeamInvitationResource.php | 1 - .../Teams/Resources/TeamMemberResource.php | 1 - tests/Domain/Browsing/BrowseTest.php | 1 - tests/Domain/Sharing/UserShareTest.php | 2 +- tests/Domain/Sharing/VisitorBrowseTest.php | 2 +- tests/Domain/Teams/TeamsTest.php | 26 ++++++- 46 files changed, 317 insertions(+), 225 deletions(-) create mode 100644 resources/js/store/modules/teams.js diff --git a/config/vuefilemanager.php b/config/vuefilemanager.php index 99e8e9a6..80b5475a 100644 --- a/config/vuefilemanager.php +++ b/config/vuefilemanager.php @@ -10,6 +10,6 @@ return [ 'chunk_size' => env('CHUNK_SIZE', '128'), 'colors' => [ - '#9ad2bf', '#9ad2cd', '#d29a9a', '#d2ce9a', '#9aadd2', '#c59ad2' - ] + '#9ad2bf', '#9ad2cd', '#d29a9a', '#d2ce9a', '#9aadd2', '#c59ad2', + ], ]; diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 67b18c23..bf0bedd3 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -8,7 +8,7 @@ "/chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~chunks/~3e4fdd8b.js": "/chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~chunks/~3e4fdd8b.js?id=0017a8e827fd7058a08c", "/chunks/admin~chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-item~6fce3876.js": "/chunks/admin~chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-item~6fce3876.js?id=3dc49e837aec52b13e76", "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~26d67489.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~26d67489.js?id=a76bb79a48dc94c9c4b7", - "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.js?id=87cd1e20835b211e4afe", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.js?id=f409162be0eaf9d30d51", "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~f312a84e.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/shared~f312a84e.js?id=004c11df35e63517608d", "/chunks/admin~chunks/platform.js": "/chunks/admin~chunks/platform.js?id=0e511f0ceaac7257bf25", "/chunks/admin~chunks/platform~chunks/settings.js": "/chunks/admin~chunks/platform~chunks/settings.js?id=346cac257119a5ef00ef", @@ -59,7 +59,7 @@ "/chunks/plan-subscribers.js": "/chunks/plan-subscribers.js?id=0dd0a5efe0e3cb511c48", "/chunks/plans.js": "/chunks/plans.js?id=e93cd9c42177eadc8825", "/chunks/platform.js": "/chunks/platform.js?id=7ec7f91183a9e46e3f41", - "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=c6d55fbaeae45421f8c2", + "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=6000d49dae81f57df3d0", "/chunks/profile.js": "/chunks/profile.js?id=658aa03af778cc2cc100", "/chunks/profile~chunks/settings-password.js": "/chunks/profile~chunks/settings-password.js?id=ddb7be518c092ed392ca", "/chunks/purchase-code.js": "/chunks/purchase-code.js?id=e8597a21a38c153e3c88", @@ -83,7 +83,7 @@ "/chunks/stripe-credentials.js": "/chunks/stripe-credentials.js?id=1be90d8d2e093bf0f28b", "/chunks/subscription-plans.js": "/chunks/subscription-plans.js?id=1ca763d2fca8a949cec8", "/chunks/subscription-service.js": "/chunks/subscription-service.js?id=e6411871b271e4ecbe03", - "/chunks/team-folders.js": "/chunks/team-folders.js?id=2bb147d346bb1b8b9eba", + "/chunks/team-folders.js": "/chunks/team-folders.js?id=d65cc54f7b872f260f24", "/chunks/trash.js": "/chunks/trash.js?id=b098bf0e2f2df3e67539", "/chunks/upgrade-billing.js": "/chunks/upgrade-billing.js?id=8879f5c458f08648405a", "/chunks/upgrade-billing~chunks/upgrade-plan.js": "/chunks/upgrade-billing~chunks/upgrade-plan.js?id=e365ae16373be9dbd458", @@ -100,5 +100,41 @@ "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~25aaad73.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~25aaad73.js?id=0de519ac9b2c2754e0c2", "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~81c8aec0.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~81c8aec0.js?id=ca3b57f70682c1c315f7", "/vendors~chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunk~3c02639c.js": "/vendors~chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunk~3c02639c.js?id=e31953d811b86273037b", - "/vendors~chunks/admin~chunks/platform~chunks/settings~chunks/shared.js": "/vendors~chunks/admin~chunks/platform~chunks/settings~chunks/shared.js?id=90d4a5c68188a1bbce59" + "/vendors~chunks/admin~chunks/platform~chunks/settings~chunks/shared.js": "/vendors~chunks/admin~chunks/platform~chunks/settings~chunks/shared.js?id=90d4a5c68188a1bbce59", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.0818cc29c25f5f240268.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.0818cc29c25f5f240268.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.91ad9e0a10e2894f0126.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.91ad9e0a10e2894f0126.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.c0808c26031abef99fd9.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.c0808c26031abef99fd9.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.f48bc62b4a85bede9f94.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.f48bc62b4a85bede9f94.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.a422b86f72b7f92b765a.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.a422b86f72b7f92b765a.hot-update.js", + "/js/main.837402788cdee8d4a10c.hot-update.js": "/js/main.837402788cdee8d4a10c.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.f5cb1393ef7ae678b240.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.f5cb1393ef7ae678b240.hot-update.js", + "/js/main.5900077b64cbc13fa6c3.hot-update.js": "/js/main.5900077b64cbc13fa6c3.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.cb34f48ec7eebf88bd2c.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.cb34f48ec7eebf88bd2c.hot-update.js", + "/js/main.e2b032e1dd929d894d6b.hot-update.js": "/js/main.e2b032e1dd929d894d6b.hot-update.js", + "/chunks/team-folders.9b5c7ec2b56681d04b80.hot-update.js": "/chunks/team-folders.9b5c7ec2b56681d04b80.hot-update.js", + "/chunks/team-folders.6ed12125fb188ff0e4f7.hot-update.js": "/chunks/team-folders.6ed12125fb188ff0e4f7.hot-update.js", + "/chunks/team-folders.981e26a54a1a429abb65.hot-update.js": "/chunks/team-folders.981e26a54a1a429abb65.hot-update.js", + "/js/main.c0a000a4fd50bfd81531.hot-update.js": "/js/main.c0a000a4fd50bfd81531.hot-update.js", + "/js/main.52e334c3af340dcba411.hot-update.js": "/js/main.52e334c3af340dcba411.hot-update.js", + "/js/main.517a156f5d8b35949d24.hot-update.js": "/js/main.517a156f5d8b35949d24.hot-update.js", + "/js/main.fc2a78bcdc6351ea0150.hot-update.js": "/js/main.fc2a78bcdc6351ea0150.hot-update.js", + "/js/main.24f35f1b5d886dece9e0.hot-update.js": "/js/main.24f35f1b5d886dece9e0.hot-update.js", + "/js/main.7939adb468b346eb4b8b.hot-update.js": "/js/main.7939adb468b346eb4b8b.hot-update.js", + "/js/main.bac529c7fb88541be8f9.hot-update.js": "/js/main.bac529c7fb88541be8f9.hot-update.js", + "/chunks/platform~chunks/shared.ccb8eddb695edf2fdaa4.hot-update.js": "/chunks/platform~chunks/shared.ccb8eddb695edf2fdaa4.hot-update.js", + "/chunks/platform~chunks/shared.c771c789cd06949a6bae.hot-update.js": "/chunks/platform~chunks/shared.c771c789cd06949a6bae.hot-update.js", + "/js/main.dcbb83cfdea23411178c.hot-update.js": "/js/main.dcbb83cfdea23411178c.hot-update.js", + "/chunks/platform~chunks/shared.f4d7ed56a4e959bfbb99.hot-update.js": "/chunks/platform~chunks/shared.f4d7ed56a4e959bfbb99.hot-update.js", + "/chunks/platform~chunks/shared.1d3338176e8ae0405579.hot-update.js": "/chunks/platform~chunks/shared.1d3338176e8ae0405579.hot-update.js", + "/chunks/platform~chunks/shared.8ae100bba419fd79aee9.hot-update.js": "/chunks/platform~chunks/shared.8ae100bba419fd79aee9.hot-update.js", + "/chunks/platform~chunks/shared.a4e66d62a2efa13ab52b.hot-update.js": "/chunks/platform~chunks/shared.a4e66d62a2efa13ab52b.hot-update.js", + "/chunks/platform~chunks/shared.3110c2a312eabdb18116.hot-update.js": "/chunks/platform~chunks/shared.3110c2a312eabdb18116.hot-update.js", + "/chunks/platform~chunks/shared.93f5dff162e79ca46fd2.hot-update.js": "/chunks/platform~chunks/shared.93f5dff162e79ca46fd2.hot-update.js", + "/chunks/team-folders.961ec4f67b5db08258a9.hot-update.js": "/chunks/team-folders.961ec4f67b5db08258a9.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.87fb3d6a2092b1aca5f8.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.87fb3d6a2092b1aca5f8.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.7e54e4fe2704e29af89d.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.7e54e4fe2704e29af89d.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.69b50aa8397c39fb3a7b.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.69b50aa8397c39fb3a7b.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.855b1071699829b8ef36.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.855b1071699829b8ef36.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.cbd5b81577bd1e5f68df.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.cbd5b81577bd1e5f68df.hot-update.js", + "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.f8708232f16a94aada33.hot-update.js": "/chunks/admin~chunks/files~chunks/my-shared-items~chunks/platform~chunks/recent-uploads~chunks/settin~d04310d2.f8708232f16a94aada33.hot-update.js" } diff --git a/resources/js/components/FilesView/DesktopToolbar.vue b/resources/js/components/FilesView/DesktopToolbar.vue index f78a17c1..8bb21d15 100644 --- a/resources/js/components/FilesView/DesktopToolbar.vue +++ b/resources/js/components/FilesView/DesktopToolbar.vue @@ -45,8 +45,8 @@ - @@ -118,14 +118,22 @@ }, computed: { ...mapGetters([ + 'currentTeamFolder', 'isVisibleSidebar', 'FilePreviewType', 'currentFolder', 'sharedDetail', 'clipboard', ]), + teamFolder() { + return this.currentTeamFolder ? this.currentTeamFolder : this.clipboard[0] + }, isLoadedFolder() { - return this.sharedDetail && this.sharedDetail.data.attributes.item_id === this.$route.params.id + if (this.$isThisRoute(this.$route, ['Public'])) { + return this.sharedDetail && this.sharedDetail.data.attributes.item_id === this.$route.params.id + } + + return this.$route.params.id }, hasCapacity() { // Check if storage limitation is set @@ -216,7 +224,8 @@ if (this.isLoadedFolder) this.$router.back() }, showTeamFolderMenu() { - events.$emit('popover:open', 'team-folder') + if (this.currentTeamFolder || this.clipboard[0]) + events.$emit('popover:open', 'team-folder') }, showCreateMenu() { events.$emit('popover:open', 'desktop-create') diff --git a/resources/js/components/FilesView/FileItemList.vue b/resources/js/components/FilesView/FileItemList.vue index 983d6aa3..154f99ae 100644 --- a/resources/js/components/FilesView/FileItemList.vue +++ b/resources/js/components/FilesView/FileItemList.vue @@ -16,12 +16,12 @@
- + {{ item.data.attributes.mimetype | limitCharacters }} - + @@ -42,11 +42,6 @@
- - - {{ item.data.attributes.filesize }}, {{ timeStamp }} @@ -220,17 +215,7 @@ export default { if (!this.mobileMultiSelect && this.$isMobile()) { if (this.isFolder) { - let route = this.$router.currentRoute.name - - if (route === 'Public') { - this.$router.push({name: 'Public', params: {token: this.$route.params.token, id: this.item.data.id}}) - } else if (route === 'Trash') { - this.$router.push({name: 'Trash', params: {id: this.item.data.id}}) - } else if (['Files', 'MySharedItems'].includes(route)) { - this.$router.push({name: 'Files', params: {id: this.item.data.id}}) - } else if (route === 'TeamFolders') { - this.$router.push({name: 'TeamFolders', params: {id: this.item.data.id}}) - } + this.$goToFileView(this.item.data.id) } else { if (this.isImage || this.isVideo || this.isAudio || this.isPdf) { @@ -263,17 +248,7 @@ export default { // Clear selected items after open another folder this.$store.commit('CLIPBOARD_CLEAR') - let route = this.$router.currentRoute.name - - if (route === 'Public') { - this.$router.push({name: 'Public', params: {token: this.$route.params.token, id: this.item.data.id}}) - } else if (route === 'Trash') { - this.$router.push({name: 'Trash', params: {id: this.item.data.id}}) - } else if (['Files', 'MySharedItems'].includes(route)) { - this.$router.push({name: 'Files', params: {id: this.item.data.id}}) - } else if (route === 'TeamFolders') { - this.$router.push({name: 'TeamFolders', params: {id: this.item.data.id}}) - } + this.$goToFileView(this.item.data.id) } }, renameItem: debounce(function (e) { diff --git a/resources/js/components/Teams/Components/TeamFolderPreview.vue b/resources/js/components/Teams/Components/TeamFolderPreview.vue index fbf8ae83..a1a92d48 100644 --- a/resources/js/components/Teams/Components/TeamFolderPreview.vue +++ b/resources/js/components/Teams/Components/TeamFolderPreview.vue @@ -3,7 +3,7 @@
The Team Project Last update a week ago - +
@@ -19,8 +19,12 @@ }, computed: { ...mapGetters([ - 'clipboard' - ]) + 'currentTeamFolder', + 'clipboard', + ]), + teamFolder() { + return this.currentTeamFolder ? this.currentTeamFolder : this.clipboard[0] + } } } diff --git a/resources/js/components/Teams/Components/TeamMembersButton.vue b/resources/js/components/Teams/Components/TeamMembersButton.vue index 9d56b432..4a2c75fb 100644 --- a/resources/js/components/Teams/Components/TeamMembersButton.vue +++ b/resources/js/components/Teams/Components/TeamMembersButton.vue @@ -1,9 +1,9 @@ @@ -18,8 +18,12 @@ }, computed: { ...mapGetters([ - 'clipboard' - ]) + 'currentTeamFolder', + 'clipboard', + ]), + teamFolder() { + return this.currentTeamFolder ? this.currentTeamFolder : this.clipboard[0] + } }, } diff --git a/resources/js/helpers/functionHelpers.js b/resources/js/helpers/functionHelpers.js index 6b72a047..d043070f 100644 --- a/resources/js/helpers/functionHelpers.js +++ b/resources/js/helpers/functionHelpers.js @@ -81,12 +81,6 @@ const FunctionHelpers = { return '/invoice/' + customer + '/' + id } - Vue.prototype.$openImageOnNewTab = function (source) { - let win = window.open(source, '_blank') - - win.focus() - } - Vue.prototype.$uploadFiles = async function (files) { if (files.length === 0) return @@ -207,6 +201,19 @@ const FunctionHelpers = { anchor.click() } + Vue.prototype.$goToFileView = function (id) { + + let locations = { + 'Public': {name: 'Public', params: {token: this.$route.params.token, id: id}}, + 'TeamFolders': {name: 'TeamFolders', params: {id: id}}, + 'MySharedItems': {name: 'Files', params: {id: id}}, + 'Trash': {name: 'Trash', params: {id: id}}, + 'Files': {name: 'Files', params: {id: id}}, + } + + this.$router.push(locations[this.$router.currentRoute.name]) + } + Vue.prototype.$isThisRoute = function (route, locations) { return locations.includes(route.name) diff --git a/resources/js/store/index.js b/resources/js/store/index.js index 14be0e1f..21f9994a 100644 --- a/resources/js/store/index.js +++ b/resources/js/store/index.js @@ -5,6 +5,7 @@ import fileFunctions from './modules/fileFunctions' import fileBrowser from './modules/fileBrowser' import userAuth from './modules/userAuth' import sharing from './modules/sharing' +import teams from './modules/teams' import app from './modules/app' Vue.use(Vuex) @@ -15,6 +16,7 @@ export default new Vuex.Store({ fileBrowser, userAuth, sharing, + teams, app, } }) \ No newline at end of file diff --git a/resources/js/store/modules/fileBrowser.js b/resources/js/store/modules/fileBrowser.js index e46a75e8..526555c7 100644 --- a/resources/js/store/modules/fileBrowser.js +++ b/resources/js/store/modules/fileBrowser.js @@ -46,35 +46,6 @@ const actions = { } }) }, - getTeamFolder: ({commit, getters}, id) => { - commit('LOADING_STATE', {loading: true, data: []}) - - axios - .get(`${getters.api}/teams/folders/${id}/${getters.sorting.URI}`) - .then(response => { - commit('LOADING_STATE', {loading: false, data: response.data.folders.data}) - commit('SET_CURRENT_FOLDER', response.data.root) - - events.$emit('scrollTop') - }) - .catch(error => { - - // Redirect if unauthenticated - if ([401, 403].includes(error.response.status)) { - - commit('SET_AUTHORIZED', false) - router.push({name: 'SignIn'}) - - } else { - - // Show error message - events.$emit('alert:open', { - title: i18n.t('popup_error.title'), - message: i18n.t('popup_error.message'), - }) - } - }) - }, getRecentUploads: ({commit, getters}) => { commit('LOADING_STATE', {loading: true, data: []}) diff --git a/resources/js/store/modules/teams.js b/resources/js/store/modules/teams.js new file mode 100644 index 00000000..6531052e --- /dev/null +++ b/resources/js/store/modules/teams.js @@ -0,0 +1,68 @@ +import router from "../../router"; +import {events} from "../../bus"; +import i18n from "../../i18n"; +import axios from "axios"; + +const defaultState = { + currentTeamFolder: undefined, +} + +const actions = { + getTeamFolder: ({commit, getters}, id) => { + commit('LOADING_STATE', {loading: true, data: []}) + + if (typeof id === 'undefined') { + commit('SET_CURRENT_TEAM_FOLDER', null) + } + + axios + .get(`${getters.api}/teams/folders/${id}/${getters.sorting.URI}`) + .then(response => { + let folders = response.data.folders.data + let files = response.data.files.data + + commit('LOADING_STATE', {loading: false, data: folders.concat(files)}) + commit('SET_CURRENT_FOLDER', response.data.root) + + if (! getters.currentTeamFolder || getters.currentTeamFolder.data.id !== response.data.teamFolder.data.id) { + commit('SET_CURRENT_TEAM_FOLDER', response.data.teamFolder) + } + + events.$emit('scrollTop') + }) + .catch(error => { + + // Redirect if unauthenticated + if ([401, 403].includes(error.response.status)) { + + commit('SET_AUTHORIZED', false) + router.push({name: 'SignIn'}) + + } else { + + // Show error message + events.$emit('alert:open', { + title: i18n.t('popup_error.title'), + message: i18n.t('popup_error.message'), + }) + } + }) + }, +} + +const mutations = { + SET_CURRENT_TEAM_FOLDER(state, payload) { + state.currentTeamFolder = payload + } +} + +const getters = { + currentTeamFolder: state => state.currentTeamFolder, +} + +export default { + state: defaultState, + getters, + actions, + mutations +} \ No newline at end of file diff --git a/resources/js/views/FileView/TeamFolders.vue b/resources/js/views/FileView/TeamFolders.vue index 5f15a425..80545ad4 100644 --- a/resources/js/views/FileView/TeamFolders.vue +++ b/resources/js/views/FileView/TeamFolders.vue @@ -210,6 +210,7 @@ events.$on('context-menu:show', (event, item) => this.item = item) events.$on('mobile-context-menu:show', item => this.item = item) + events.$on('context-menu:current-folder', folder => this.item = folder) events.$on('action:confirmed', data => { diff --git a/src/App/Console/Commands/SetupDevEnvironment.php b/src/App/Console/Commands/SetupDevEnvironment.php index caa60be6..3a9296d1 100644 --- a/src/App/Console/Commands/SetupDevEnvironment.php +++ b/src/App/Console/Commands/SetupDevEnvironment.php @@ -1,18 +1,17 @@ setUpFaker(); } @@ -743,34 +741,36 @@ class SetupDevEnvironment extends Command ->get(); collect([$members[0]->id, $members[1]->id]) - ->each(fn($id) => DB::table('team_folder_members') - ->insert([ - 'folder_id' => $companyProjectFolder->id, - 'user_id' => $id, - 'permission' => 'can-edit', - ]) + ->each( + fn ($id) => DB::table('team_folder_members') + ->insert([ + 'folder_id' => $companyProjectFolder->id, + 'user_id' => $id, + 'permission' => 'can-edit', + ]) ); collect([$members[2]->id, $members[3]->id]) - ->each(fn($id) => DB::table('team_folder_members') - ->insert([ - 'folder_id' => $financeDocumentsFolder->id, - 'user_id' => $id, - 'permission' => 'can-edit', - ]) + ->each( + fn ($id) => DB::table('team_folder_members') + ->insert([ + 'folder_id' => $financeDocumentsFolder->id, + 'user_id' => $id, + 'permission' => 'can-edit', + ]) ); // Create invitations collect([$members[4], $members[5]]) - ->each(fn($user) => TeamFolderInvitation::factory() - ->create([ - 'email' => $user->email, - 'folder_id' => $companyProjectFolder->id, - 'status' => 'pending', - 'permission' => 'can-edit', - ]) + ->each( + fn ($user) => TeamFolderInvitation::factory() + ->create([ + 'email' => $user->email, + 'folder_id' => $companyProjectFolder->id, + 'status' => 'pending', + 'permission' => 'can-edit', + ]) ); - } private function create_share_records(): void diff --git a/src/App/Users/Models/User.php b/src/App/Users/Models/User.php index 2d370f1a..b05f61c7 100644 --- a/src/App/Users/Models/User.php +++ b/src/App/Users/Models/User.php @@ -1,5 +1,4 @@ $this->usedCapacity, 'used_formatted' => Metric::bytes($this->usedCapacity)->format(), @@ -104,7 +103,7 @@ class User extends Authenticatable implements MustVerifyEmail } return [ - 'used' => (float)get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity), + 'used' => (float) get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity), 'used_formatted' => get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity) . '%', 'capacity' => $this->settings->storage_capacity, 'capacity_formatted' => format_gigabytes($this->settings->storage_capacity), @@ -117,7 +116,7 @@ class User extends Authenticatable implements MustVerifyEmail public function getUsedCapacityAttribute(): int { return $this->filesWithTrashed - ->map(fn($item) => $item->getRawOriginal())->sum('filesize'); + ->map(fn ($item) => $item->getRawOriginal())->sum('filesize'); } /** diff --git a/src/App/Users/Models/UserSettings.php b/src/App/Users/Models/UserSettings.php index 9e095087..fd20bb04 100644 --- a/src/App/Users/Models/UserSettings.php +++ b/src/App/Users/Models/UserSettings.php @@ -3,7 +3,6 @@ namespace App\Users\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; class UserSettings extends Model { diff --git a/src/Domain/Browsing/Controllers/BrowseFolderController.php b/src/Domain/Browsing/Controllers/BrowseFolderController.php index 5a72838b..41553a36 100644 --- a/src/Domain/Browsing/Controllers/BrowseFolderController.php +++ b/src/Domain/Browsing/Controllers/BrowseFolderController.php @@ -1,16 +1,14 @@ fakeUploadFile)($request); } diff --git a/src/Domain/Files/Resources/FileResource.php b/src/Domain/Files/Resources/FileResource.php index 68119d0f..e63f55ec 100644 --- a/src/Domain/Files/Resources/FileResource.php +++ b/src/Domain/Files/Resources/FileResource.php @@ -1,5 +1,4 @@ [ - $this->mergeWhen($this->shared, fn() => [ + $this->mergeWhen($this->shared, fn () => [ 'shared' => new ShareResource($this->shared), ]), - $this->mergeWhen($this->parent, fn() => [ + $this->mergeWhen($this->parent, fn () => [ 'parent' => [ 'data' => [ 'type' => 'folder', @@ -54,7 +53,7 @@ class FileResource extends JsonResource ], ], ]), - ] + ], ], ]; } diff --git a/src/Domain/Folders/Controllers/CreateFolderController.php b/src/Domain/Folders/Controllers/CreateFolderController.php index 90b4ddca..22a7396a 100644 --- a/src/Domain/Folders/Controllers/CreateFolderController.php +++ b/src/Domain/Folders/Controllers/CreateFolderController.php @@ -2,9 +2,9 @@ namespace Domain\Folders\Controllers; use Auth; -use Domain\Folders\Resources\FolderResource; use Illuminate\Http\Response; use App\Http\Controllers\Controller; +use Domain\Folders\Resources\FolderResource; use Domain\Folders\Actions\CreateFolderAction; use Domain\Folders\Requests\CreateFolderRequest; use Support\Demo\Actions\FakeCreateFolderAction; diff --git a/src/Domain/Folders/Models/Folder.php b/src/Domain/Folders/Models/Folder.php index cc8ecd0c..8a03e94b 100644 --- a/src/Domain/Folders/Models/Folder.php +++ b/src/Domain/Folders/Models/Folder.php @@ -203,6 +203,16 @@ class Folder extends Model ->withPivot('permission'); } + public function parents(): HasMany + { + return $this->hasMany(Folder::class, 'id', 'parent_id'); + } + + public function teamRoot(): HasMany + { + return $this->parents()->with('teamRoot'); + } + // Delete all folder children public static function boot() { @@ -214,30 +224,28 @@ class Folder extends Model static::deleting(function ($item) { if ($item->isForceDeleting()) { - $item->trashedChildren()->each(function ($folder) { - $folder->forceDelete(); - }); + $item + ->trashedChildren() + ->each(fn ($folder) => $folder->forceDelete()); } else { - $item->children()->each(function ($folder) { - $folder->delete(); - }); + $item + ->children() + ->each(fn ($folder) => $folder->delete()); - $item->files()->each(function ($file) { - $file->delete(); - }); + $item + ->files() + ->each(fn ($file) => $file->delete()); } }); + // Restore children folders and files static::restoring(function ($item) { - // Restore children folders - $item->trashedChildren()->each(function ($folder) { - $folder->restore(); - }); - - // Restore children files - $item->trashedFiles()->each(function ($files) { - $files->restore(); - }); + $item + ->trashedChildren() + ->each(fn ($folder) => $folder->restore()); + $item + ->trashedFiles() + ->each(fn ($files) => $files->restore()); }); } } diff --git a/src/Domain/Folders/Resources/FolderResource.php b/src/Domain/Folders/Resources/FolderResource.php index 2b26d622..2f7dac96 100644 --- a/src/Domain/Folders/Resources/FolderResource.php +++ b/src/Domain/Folders/Resources/FolderResource.php @@ -1,11 +1,10 @@ [ - $this->mergeWhen($this->teamMembers, fn() => [ + $this->mergeWhen($this->teamMembers, fn () => [ 'members' => new TeamMembersCollection($this->teamMembers), ]), - $this->mergeWhen($this->teamInvitations, fn() => [ + $this->mergeWhen($this->teamInvitations, fn () => [ 'invitations' => new TeamInvitationsCollection($this->teamInvitations), ]), - $this->mergeWhen($this->shared, fn() => [ + $this->mergeWhen($this->shared, fn () => [ 'shared' => new ShareResource($this->shared), ]), - $this->mergeWhen($this->parent, fn() => [ + $this->mergeWhen($this->parent, fn () => [ 'parent' => [ 'data' => [ 'type' => 'folder', diff --git a/src/Domain/Items/Actions/RenameFileOrFolderAction.php b/src/Domain/Items/Actions/RenameFileOrFolderAction.php index 495289ab..f98c1eff 100644 --- a/src/Domain/Items/Actions/RenameFileOrFolderAction.php +++ b/src/Domain/Items/Actions/RenameFileOrFolderAction.php @@ -1,8 +1,6 @@ input('type'), $id); diff --git a/src/Domain/Items/Controllers/RenameFileOrFolderController.php b/src/Domain/Items/Controllers/RenameFileOrFolderController.php index ad5014cc..7dd218f9 100644 --- a/src/Domain/Items/Controllers/RenameFileOrFolderController.php +++ b/src/Domain/Items/Controllers/RenameFileOrFolderController.php @@ -25,7 +25,7 @@ class RenameFileOrFolderController extends Controller public function __invoke( RenameItemRequest $request, string $id, - ): FileResource|FolderResource|array { + ): FileResource | FolderResource | array { if (is_demo_account(Auth::user()->email)) { return ($this->fakeRenameFileOrFolder)($request, $id); } diff --git a/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php b/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php index 844cdacd..3c3e92ac 100644 --- a/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php +++ b/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php @@ -1,12 +1,11 @@ $this->permission, 'protected' => $this->is_protected, 'item_id' => $this->item_id, - 'expire_in' => (int)$this->expire_in, + 'expire_in' => (int) $this->expire_in, 'token' => $this->token, 'link' => $this->link, 'type' => $this->type, diff --git a/src/Domain/Teams/Controllers/BrowseSharedWithMeController.php b/src/Domain/Teams/Controllers/BrowseSharedWithMeController.php index 1afea588..b61a306c 100644 --- a/src/Domain/Teams/Controllers/BrowseSharedWithMeController.php +++ b/src/Domain/Teams/Controllers/BrowseSharedWithMeController.php @@ -16,7 +16,7 @@ class BrowseSharedWithMeController $relations = [ 'parent:id,name', - 'shared:token,id,item_id,permission,is_protected,expire_in' + 'shared:token,id,item_id,permission,is_protected,expire_in', ]; if ($rootId) { diff --git a/src/Domain/Teams/Controllers/ConvertFolderIntoTeamFolderController.php b/src/Domain/Teams/Controllers/ConvertFolderIntoTeamFolderController.php index 146cefb5..1a7a10ce 100644 --- a/src/Domain/Teams/Controllers/ConvertFolderIntoTeamFolderController.php +++ b/src/Domain/Teams/Controllers/ConvertFolderIntoTeamFolderController.php @@ -1,11 +1,11 @@ update([ 'team_folder' => 1, 'parent_id' => null, diff --git a/src/Domain/Teams/Controllers/InvitationsController.php b/src/Domain/Teams/Controllers/InvitationsController.php index 3f673f23..77bdc151 100644 --- a/src/Domain/Teams/Controllers/InvitationsController.php +++ b/src/Domain/Teams/Controllers/InvitationsController.php @@ -10,11 +10,9 @@ use Illuminate\Contracts\Routing\ResponseFactory; class InvitationsController extends Controller { - public function update( TeamFolderInvitation $invitation - ): ResponseFactory|Response { - + ): ResponseFactory | Response { $user = User::where('email', $invitation->email) ->firstOrFail(); @@ -34,7 +32,7 @@ class InvitationsController extends Controller public function destroy( TeamFolderInvitation $invitation - ): ResponseFactory|Response { + ): ResponseFactory | Response { $invitation->update([ 'status' => 'rejected', ]); diff --git a/src/Domain/Teams/Controllers/TeamFoldersController.php b/src/Domain/Teams/Controllers/TeamFoldersController.php index f1b31dfe..852e3562 100644 --- a/src/Domain/Teams/Controllers/TeamFoldersController.php +++ b/src/Domain/Teams/Controllers/TeamFoldersController.php @@ -1,25 +1,23 @@ where('parent_id', $rootId) - ->where('team_folder', $isHomepage) + $rootId = Str::isUuid($id) ? $id : null; + $requestedFolder = $rootId ? Folder::findOrFail($rootId) : null; + + $folders = Folder::where('parent_id', $rootId) + ->where('team_folder', ! Str::isUuid($id)) ->where('user_id', Auth::id()) ->sortable() ->get(); - if (Str::isUuid($id)) { - $files = File::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in']) - ->where('folder_id', $rootId) + if ($requestedFolder) { + // Get root team folder + $teamRootIdResults = recursiveFind( + $requestedFolder->teamRoot->toArray(), + 'id' + ); + + $teamRootId = end($teamRootIdResults); + + $teamRootFolder = $teamRootId + ? Folder::findOrFail($teamRootId) + : $requestedFolder; + + // Get files + $files = File::where('folder_id', $rootId) ->where('user_id', Auth::id()) ->sortable() ->get(); @@ -57,15 +62,16 @@ class TeamFoldersController extends Controller // Collect folders and files to single array return [ - 'folders' => new FolderCollection($folders), - 'files' => new FilesCollection($files), - 'root' => $requestedFolder, + 'folders' => new FolderCollection($folders), + 'files' => new FilesCollection($files), + 'root' => $requestedFolder ? new FolderResource($requestedFolder) : null, + 'teamFolder' => $teamRootFolder ? new FolderResource($teamRootFolder) : null, ]; } public function store( CreateTeamFolderRequest $request, - ): ResponseFactory|Response { + ): ResponseFactory | Response { $data = CreateTeamFolderData::fromRequest($request); $folder = Folder::create([ @@ -85,7 +91,7 @@ class TeamFoldersController extends Controller Folder $folder, UpdateInvitationsAction $updateInvitations, UpdateMembersAction $updateMembers, - ): ResponseFactory|Response { + ): ResponseFactory | Response { $updateInvitations( $folder, $request->input('invitations') @@ -99,7 +105,7 @@ class TeamFoldersController extends Controller return response(new FolderResource($folder), 201); } - public function destroy(Folder $folder): ResponseFactory|Response + public function destroy(Folder $folder): ResponseFactory | Response { // Delete existing invitations DB::table('team_folder_invitations') diff --git a/src/Domain/Teams/DTO/CreateTeamFolderData.php b/src/Domain/Teams/DTO/CreateTeamFolderData.php index e3d51344..c3f30547 100644 --- a/src/Domain/Teams/DTO/CreateTeamFolderData.php +++ b/src/Domain/Teams/DTO/CreateTeamFolderData.php @@ -1,5 +1,4 @@ 'shared', 'attributes' => [ 'permission' => $share->permission, - 'protected' => false, + 'protected' => false, 'item_id' => $share->item_id, 'expire_in' => $share->expire_in, 'token' => $share->token, diff --git a/tests/Domain/Teams/TeamsTest.php b/tests/Domain/Teams/TeamsTest.php index b92d6a29..ce0dd805 100644 --- a/tests/Domain/Teams/TeamsTest.php +++ b/tests/Domain/Teams/TeamsTest.php @@ -1,5 +1,4 @@ create([ + 'team_folder' => 1, + ]); + + $level_1 = Folder::factory() + ->create([ + 'parent_id' => $teamFolder->id, + ]); + + $level_2 = Folder::factory() + ->create([ + 'parent_id' => $level_1->id, + ]); + + $teamRoot = recursiveFind($level_2->teamRoot->toArray(), 'id'); + + $this->assertEquals($teamFolder->id, end($teamRoot)); + } + /** * @test */