Skip to content

Commit

Permalink
Merge pull request #5256 from owncloud/file-editor-handler-tweaks
Browse files Browse the repository at this point in the history
Add mode prop for opening file editors
  • Loading branch information
kulmann authored Jun 15, 2021
2 parents beba161 + f02ff7c commit 1139e2c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/enhancement-editor-mode
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: File editor mode

We've added a parameter called `mode` to the different ways of opening a file editor.
The mode can be `edit` or `create` and reflects whether the file editor was opened
in an editing mode or in a creation mode.

https://github.com/owncloud/web/issues/5226
https://github.com/owncloud/web/pull/5256
4 changes: 2 additions & 2 deletions packages/web-app-files/src/components/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import pathUtil from 'path'
import isEmpty from 'lodash-es/isEmpty'
import Mixins from '../mixins'
import MixinFileActions from '../mixins/fileActions'
import MixinFileActions, { EDITOR_MODE_CREATE } from '../mixins/fileActions'
import MixinRoutes from '../mixins/routes'
import MixinScrollToResource from '../mixins/filesListScrolling'
import { buildResource } from '../helpers/resources'
Expand Down Expand Up @@ -419,7 +419,7 @@ export default {
if (this.newFileAction) {
const fileId = resource.fileInfo['{http://owncloud.org/ns}fileid']
this.$_fileActions_openEditor(this.newFileAction, path, fileId)
this.$_fileActions_openEditor(this.newFileAction, path, fileId, EDITOR_MODE_CREATE)
this.hideModal()
return
Expand Down
30 changes: 17 additions & 13 deletions packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const actionsMixins = [
'delete'
]

export const EDITOR_MODE_EDIT = 'edit'
export const EDITOR_MODE_CREATE = 'create'

export default {
mixins: [Copy, Delete, Download, Favorite, Fetch, Move, Navigate, Rename, Restore],
computed: {
Expand Down Expand Up @@ -53,7 +56,8 @@ export default {
)
},
icon: this.apps.meta[editor.app].icon,
handler: item => this.$_fileActions_openEditor(editor, item.path, item.id),
handler: item =>
this.$_fileActions_openEditor(editor, item.path, item.id, EDITOR_MODE_EDIT),
isEnabled: ({ resource }) => {
if (editor.routes?.length > 0 && !checkRoute(editor.routes, this.$route.name)) {
return false
Expand All @@ -74,25 +78,26 @@ export default {
methods: {
...mapActions(['openFile']),

$_fileActions_openEditor(editor, filePath, fileId) {
$_fileActions_openEditor(editor, filePath, fileId, mode) {
if (editor.handler) {
return editor.handler({
config: this.configuration,
extensionConfig: editor.config,
filePath,
fileId
fileId,
mode
})
}

// TODO: Refactor in the store
this.openFile({
filePath: filePath
filePath
})

if (editor.newTab) {
const path = this.$router.resolve({
name: editor.routeName,
params: { filePath: filePath }
params: { filePath, fileId, mode }
}).href
const target = `${editor.routeName}-${filePath}`
const win = window.open(path, target)
Expand All @@ -103,15 +108,14 @@ export default {
return
}

const routeName = editor.routeName || editor.app
const params = {
filePath,
contextRouteName: this.$route.name
}

this.$router.push({
name: routeName,
params
name: editor.routeName || editor.app,
params: {
filePath,
fileId,
mode,
contextRouteName: this.$route.name
}
})
},

Expand Down

0 comments on commit 1139e2c

Please sign in to comment.