Skip to content

Commit

Permalink
feat: implement delete multiple action
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed Nov 25, 2024
1 parent 19b4095 commit 00e4c15
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,24 @@ export const useFilesStore = function(...args) {
await axios.delete(generateOcsUrl(url, {
fileId: file.nodeId,
}))
.then(() => {

Check failure on line 226 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 6 tabs but found 5
del(this.files, file.nodeId)

Check failure on line 227 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 7 tabs but found 6
const index = this.ordered.indexOf(file.nodeId)

Check failure on line 228 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 7 tabs but found 6
if (index > -1) {

Check failure on line 229 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 7 tabs but found 6
this.ordered.splice(index, 1)

Check failure on line 230 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 8 tabs but found 7
}

Check failure on line 231 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 7 tabs but found 6
})

Check failure on line 232 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 6 tabs but found 5
}
del(this.files, file.nodeId)

const index = this.ordered.indexOf(file.nodeId)
if (index > -1) {
this.ordered.splice(index, 1)
}
},
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);

Check failure on line 241 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Extra semicolon
del(this.files, ...toRemove)
this.loading = false
},
changeStatus(files, status) {
Object.entries(files).filter(([key, file]) => {

Check failure on line 246 in src/store/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

Array.prototype.filter() expects a return value from arrow function
Expand Down
57 changes: 52 additions & 5 deletions src/views/FilesList/FilesListTableHeaderActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@
{{ action.displayName(selectionStore.selected) }}
</NcActionButton>
</NcActions>
<NcDialog v-if="confirmDelete"
:name="t('libresign', 'Confirm')"
:can-close="!deleting"
:open.sync="confirmDelete">
{{ t('libresign', 'The signature request will be deleted. Do you confirm this action?') }}
<NcCheckboxRadioSwitch type="switch"
:checked.sync="deleteFile"
:disabled="deleting">
{{ t('libresign', 'Also delete the file.') }}
</NcCheckboxRadioSwitch>
<template #actions>
<NcButton type="primary"
:disabled="deleting"
@click="doDelete()">
<template #icon>
<NcLoadingIcon v-if="deleting" :size="20" />
</template>
{{ t('libresign', 'Ok') }}
</NcButton>
<NcButton type="secondary"
:disabled="deleting"
@click="confirmDelete = false">
{{ t('libresign', 'Cancel') }}
</NcButton>
</template>
</NcDialog>
</div>
</template>

Expand All @@ -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'
Expand All @@ -44,6 +73,9 @@ export default {
components: {
NcActions,
NcActionButton,
NcButton,
NcCheckboxRadioSwitch,
NcDialog,
NcIconSvgWrapper,
NcLoadingIcon,
},
Expand All @@ -62,6 +94,10 @@ export default {
return {
enabledMenuActions: [],
loading: null,
toDelete: [],
confirmDelete: false,
deleteFile: true,
deleting: false,
}
},
computed: {
Expand All @@ -75,28 +111,39 @@ export default {
displayName: () => t('libresign', 'Delete'),
iconSvgInline: () => svgDelete,
execBatch: (files) => {
this.confirmDelete = true
this.toDelete = files
return files.map(() => (null));

Check failure on line 116 in src/views/FilesList/FilesListTableHeaderActions.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Extra semicolon
},
})
},
methods: {
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)
// Check if all actions returned null
if (!results.some(result => result !== null)) {
// If the actions returned null, we stay silent
this.selectionStore.reset()
return
}
Expand Down Expand Up @@ -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
})
},
},
Expand Down

0 comments on commit 00e4c15

Please sign in to comment.