Skip to content

Commit

Permalink
feat(f2v): Move to new file actions api
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Aug 18, 2023
1 parent 76e586d commit 5a9c43b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/services/FilesActionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
import { encodePath } from '@nextcloud/paths'

/**
* @param {string} name the file name
* @param {object} context the file context
* @param {Node} The file to open
* @param node
*/
export default function(name, context) {
export default function(node) {
// replace potential leading double slashes
const path = `${context.dir}/${name}`.replace(/^\/\//, '/')
const path = `${node.dirname}/${node.basename}`.replace(/^\/\//, '/')
const oldQuery = location.search.replace(/^\?/, '')
const onClose = () => OC.Util.History.pushState(oldQuery)
if (!context.fileInfoModel && context.fileList) {
/* if (!context.fileInfoModel && context.fileList) {
context.fileInfoModel = context.fileList.getModelForFile(name)
}
if (context.fileInfoModel) {
pushToHistory({ fileid: context.fileInfoModel.get('id') })
}
OCA.Viewer.open({ path, onPrev: pushToHistory, onNext: pushToHistory, onClose })
} */
OCA.Viewer.open({ path, /* onPrev: pushToHistory, onNext: pushToHistory, */ onClose })
}

/**
Expand Down
47 changes: 28 additions & 19 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ import axios from '@nextcloud/axios'
import '@nextcloud/dialogs/dist/index.css'
import { showError } from '@nextcloud/dialogs'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { registerFileAction, FileAction, Permission } from '@nextcloud/files'
import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
Expand Down Expand Up @@ -270,7 +271,7 @@ export default {
isSidebarShown: false,
isFullscreenMode: false,
canSwipe: true,
isStandalone: !(OCA && OCA.Files && 'fileActions' in OCA.Files),
isStandalone: !(OCA && OCA.Files && 'fileActions' in OCA.Files), // FIXME this probably needs some adjustment
theme: null,
root: getRootPath(),
handlerId: '',
Expand Down Expand Up @@ -524,6 +525,8 @@ export default {
this.Sidebar = OCA.Files.Sidebar.state
}
this.registerFileAction()
logger.info(`${this.handlers.length} viewer handlers registered`, { handlers: this.handlers })
})
Expand Down Expand Up @@ -822,8 +825,8 @@ export default {
return
}
// register file action and groups
this.registerAction({ mime, group: handler.group })
// register groups
this.registerGroups({ mime, group: handler.group })
// register mime's component
this.components[mime] = handler.component
Expand Down Expand Up @@ -859,8 +862,8 @@ export default {
return
}
// register file action and groups if the request alias had a group
this.registerAction({ mime, group: this.mimeGroups[alias] })
// register groups if the request alias had a group
this.registerGroups({ mime, group: this.mimeGroups[alias] })
// register mime's component
this.components[mime] = this.components[alias]
Expand All @@ -871,20 +874,7 @@ export default {
}
},
registerAction({ mime, group }) {
if (!this.isStandalone) {
// unregistered handler, let's go!
OCA.Files.fileActions.registerAction({
name: 'view',
displayName: t('viewer', 'View'),
mime,
permissions: OC.PERMISSION_READ,
actionHandler: filesActionHandler,
})
OCA.Files.fileActions.setDefault(mime, 'view')
}
// register groups
registerGroups({ mime, group }) {
if (group) {
this.mimeGroups[mime] = group
// init if undefined
Expand All @@ -895,6 +885,25 @@ export default {
}
},
registerFileAction() {
if (!this.isStandalone) {
registerFileAction(new FileAction({
id: 'view',
displayName() {
return t('viewer', 'View')
},
iconSvgInline: () => '',
default: true,
enabled: (nodes) => {
return nodes.filter((node) => node.permissions & Permission.READ
&& this.Viewer.mimetypes.indexOf(node.mime) !== -1,
).length > 0
},
exec: filesActionHandler,
}))
}
},
/**
* Close the viewer
*/
Expand Down

0 comments on commit 5a9c43b

Please sign in to comment.