From 902e7a50febb569132ffa3cbb6c2863d1f9fdc90 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 25 Nov 2024 13:02:04 -0300 Subject: [PATCH] feat: implement delete multiple action Signed-off-by: Vitor Mattos --- src/store/files.js | 26 +++++---- .../FilesList/FilesListTableHeaderActions.vue | 57 +++++++++++++++++-- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/store/files.js b/src/store/files.js index 009cd1f135..14b80ad205 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -239,22 +239,24 @@ export const useFilesStore = function(...args) { await axios.delete(generateOcsUrl(url, { fileId: file.nodeId, })) + .then(() => { + del(this.files, file.nodeId) + const index = this.ordered.indexOf(file.nodeId) + if (index > -1) { + this.ordered.splice(index, 1) + } + }) } - del(this.files, file.nodeId) - const index = this.ordered.indexOf(file.nodeId) - if (index > -1) { - this.ordered.splice(index, 1) - } }, - changeStatus(files, status) { - Object.entries(files).filter(([key, file]) => { - set( - this.files[file.nodeId], - 'status', - status, - ) + async deleteMultiple(nodeIds, deleteFile) { + this.loading = true + nodeIds.forEach(async nodeId => { + await this.delete(this.files[nodeId], deleteFile) }) + const toRemove = nodeIds.filter(nodeId => (!this.files[nodeId]?.uuid)) + del(this.files, ...toRemove) + this.loading = false }, async getAllFiles(filter) { if (this.loading || this.loadedAll) { diff --git a/src/views/FilesList/FilesListTableHeaderActions.vue b/src/views/FilesList/FilesListTableHeaderActions.vue index df54eecc90..590d34d3d7 100644 --- a/src/views/FilesList/FilesListTableHeaderActions.vue +++ b/src/views/FilesList/FilesListTableHeaderActions.vue @@ -21,6 +21,32 @@ {{ action.displayName(selectionStore.selected) }} + + {{ t('libresign', 'The signature request will be deleted. Do you confirm this action?') }} + + {{ t('libresign', 'Also delete the file.') }} + + + @@ -31,6 +57,9 @@ import { showError, showSuccess } from '@nextcloud/dialogs' import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js' import NcActions from '@nextcloud/vue/dist/Components/NcActions.js' +import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' +import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' +import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js' import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js' import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js' @@ -44,6 +73,9 @@ export default { components: { NcActions, NcActionButton, + NcButton, + NcCheckboxRadioSwitch, + NcDialog, NcIconSvgWrapper, NcLoadingIcon, }, @@ -62,6 +94,10 @@ export default { return { enabledMenuActions: [], loading: null, + toDelete: [], + confirmDelete: false, + deleteFile: true, + deleting: false, } }, computed: { @@ -75,6 +111,9 @@ export default { displayName: () => t('libresign', 'Delete'), iconSvgInline: () => svgDelete, execBatch: (files) => { + this.confirmDelete = true + this.toDelete = files + return files.map(() => (null)) }, }) }, @@ -82,13 +121,22 @@ export default { registerAction(action) { this.enabledMenuActions = [...this.enabledMenuActions, action] }, + doDelete() { + this.deleting = true + this.filesStore.deleteMultiple(this.toDelete, this.deleteFile) + .then(() => { + this.toDelete = [] + this.selectionStore.reset() + this.deleting = false + }) + }, async onActionClick(action) { const displayName = action.displayName(this.selectionStore.selected) const selectionSources = this.selectionStore.selected try { // Set loading markers this.loading = action.id - this.changeStatusOfSelectedFiles('loading') + this.changeLoadingStatusOfSelectedFiles('loading') // Dispatch action execution const results = await action.execBatch(this.selectionStore.selected) @@ -96,7 +144,6 @@ export default { // Check if all actions returned null if (!results.some(result => result !== null)) { // If the actions returned null, we stay silent - this.selectionStore.reset() return } @@ -126,12 +173,12 @@ export default { } finally { // Remove loading markers this.loading = null - this.changeStatusOfSelectedFiles() + this.changeLoadingStatusOfSelectedFiles() } }, - changeStatusOfSelectedFiles(status) { + changeLoadingStatusOfSelectedFiles(status) { this.selectionStore.selected.forEach(nodeId => { - this.filesStore.files[nodeId].status = status + this.filesStore.files[nodeId].loading = status }) }, },