feat(files): add dir file action parameter

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
pull/37866/head
John Molakvoæ 2023-04-21 15:40:27 +07:00
parent 6e29560475
commit 1de3666e16
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
4 changed files with 14 additions and 8 deletions

@ -27,10 +27,11 @@ import TrashCan from '@mdi/svg/svg/trash-can.svg?raw'
import { registerFileAction, FileAction } from '../services/FileAction.ts'
import logger from '../logger.js'
import type { Navigation } from '../services/Navigation.ts'
registerFileAction(new FileAction({
id: 'delete',
displayName(nodes: Node[], view) {
displayName(nodes: Node[], view: Navigation) {
return view.id === 'trashbin'
? t('files_trashbin', 'Delete permanently')
: t('files', 'Delete')
@ -57,8 +58,8 @@ registerFileAction(new FileAction({
return false
}
},
async execBatch(nodes: Node[], view) {
return Promise.all(nodes.map(node => this.exec(node, view)))
async execBatch(nodes: Node[], view: Navigation, dir: string) {
return Promise.all(nodes.map(node => this.exec(node, view, dir)))
},
order: 100,

@ -503,7 +503,7 @@ export default Vue.extend({
this.loading = action.id
Vue.set(this.source, '_loading', true)
const success = await action.exec(this.source, this.currentView)
const success = await action.exec(this.source, this.currentView, this.dir)
// If the action returns null, we stay silent
if (success === null) {
@ -529,7 +529,7 @@ export default Vue.extend({
event.preventDefault()
event.stopPropagation()
// Execute the first default action if any
this.enabledDefaultActions[0].exec(this.source, this.currentView)
this.enabledDefaultActions[0].exec(this.source, this.currentView, this.dir)
}
},

@ -103,6 +103,10 @@ export default Vue.extend({
},
computed: {
dir() {
// Remove any trailing slash but leave root slash
return (this.$route?.query?.dir || '/').replace(/^(.+)\/$/, '$1')
},
enabledActions() {
return actions
.filter(action => action.execBatch)
@ -165,7 +169,7 @@ export default Vue.extend({
})
// Dispatch action execution
const results = await action.execBatch(this.nodes, this.currentView)
const results = await action.execBatch(this.nodes, this.currentView, this.dir)
// Check if all actions returned null
if (!results.some(result => result !== null)) {

@ -22,6 +22,7 @@
import type { Node } from '@nextcloud/files'
import logger from '../logger'
import type { Navigation } from './Navigation'
declare global {
interface Window {
@ -48,14 +49,14 @@ interface FileActionData {
* @returns true if the action was executed, false otherwise
* @throws Error if the action failed
*/
exec: (file: Node, view) => Promise<boolean|null>,
exec: (file: Node, view: Navigation, dir: string) => Promise<boolean|null>,
/**
* Function executed on multiple files action
* @returns true if the action was executed successfully,
* false otherwise and null if the action is silent/undefined.
* @throws Error if the action failed
*/
execBatch?: (files: Node[], view) => Promise<(boolean|null)[]>
execBatch?: (files: Node[], view: Navigation, dir: string) => Promise<(boolean|null)[]>
/** This action order in the list */
order?: number,
/** Make this action the default */