Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mode prop for opening file editors #5256

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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