From a1d6ed72397a230a64e188b4ba2dec6872e3d516 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Mon, 7 Feb 2022 10:00:07 +0100 Subject: [PATCH 1/3] Work around OCA.Viewer.file not set when editing in richworkspace mode. Signed-off-by: Claus-Justus Heine --- src/components/MenuBubble.vue | 4 +++- src/helpers/links.js | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/MenuBubble.vue b/src/components/MenuBubble.vue index 472e62a224d..62353cc77f5 100644 --- a/src/components/MenuBubble.vue +++ b/src/components/MenuBubble.vue @@ -151,7 +151,9 @@ export default { client.getFileInfo(file).then((_status, fileInfo) => { const path = optimalPath(this.filePath, `${fileInfo.path}/${fileInfo.name}`) const encodedPath = path.split('/').map(encodeURIComponent).join('/') - command({ href: `${encodedPath}?fileId=${fileInfo.id}` }) + // add context to hack around unset OCA.Viewer.file being unset + // when editing Readme.md in "Richworkspace"-mode, + command({ href: `${encodedPath}?fileId=${fileInfo.id}&context=${this.filePath}` }) this.hideLinkMenu() }) }, false, [], true, undefined, startPath) diff --git a/src/helpers/links.js b/src/helpers/links.js index 18f556b5c99..ba67660e90c 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -55,10 +55,11 @@ const domHref = function(node) { if (ref.match(/^[a-zA-Z]*:/)) { return ref } - const match = ref.match(/^([^?]*)\?fileId=(\d+)/) + const match = ref.match(/^([^?]*)\?fileId=(\d+)(&context=([^&]*))?/) if (match) { const [, relPath, id] = match - const currentDir = basedir(OCA.Viewer.file) + const file = match[4] || OCA.Viewer.file + const currentDir = basedir(file) const dir = absolutePath(currentDir, basedir(relPath)) return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`) } From 28d75fb6bf705f96840462d728b391b6de386ef2 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Mon, 7 Feb 2022 11:38:43 +0100 Subject: [PATCH 2/3] 2nd-try: fix linked files not working in richworkspace editor. Introduce a global property OCA.Text.RichWorkspaceFilePath which is used in helpers/links.js if the Viewer-property OCA.Viewer.file is not available. This fixes the problem that opening linked files from the enriched workspace does not work, as OCA.Viewer.file is empty in this case. So somehow the base MD-file has to be to communicated to domHref() in links.js. Signed-off-by: Claus-Justus Heine --- src/components/EditorWrapper.vue | 1 + src/components/MenuBubble.vue | 4 +++- src/files.js | 1 + src/helpers/links.js | 4 ++-- src/public.js | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/EditorWrapper.vue b/src/components/EditorWrapper.vue index 6e48b03b8d0..210a12b3e5e 100644 --- a/src/components/EditorWrapper.vue +++ b/src/components/EditorWrapper.vue @@ -291,6 +291,7 @@ export default { this.$parent.$emit('error', 'No valid file provided') return } + OCA.Text.RichWorkspaceFilePath = this.relativePath const guestName = localStorage.getItem('nick') ? localStorage.getItem('nick') : getRandomGuestName() this.syncService = new SyncService({ shareToken: this.shareToken, diff --git a/src/components/MenuBubble.vue b/src/components/MenuBubble.vue index 62353cc77f5..eb832c5cf79 100644 --- a/src/components/MenuBubble.vue +++ b/src/components/MenuBubble.vue @@ -153,7 +153,9 @@ export default { const encodedPath = path.split('/').map(encodeURIComponent).join('/') // add context to hack around unset OCA.Viewer.file being unset // when editing Readme.md in "Richworkspace"-mode, - command({ href: `${encodedPath}?fileId=${fileInfo.id}&context=${this.filePath}` }) + OCA.Text.RichWorkspaceFilePath = this.filePath + command({ href: `${encodedPath}?fileId=${fileInfo.id}` }) + OCA.Text.RichWorkspaceFilePath = '' this.hideLinkMenu() }) }, false, [], true, undefined, startPath) diff --git a/src/files.js b/src/files.js index b7ddd97b462..1f8a782e032 100644 --- a/src/files.js +++ b/src/files.js @@ -60,4 +60,5 @@ if (workspaceAvailable) { OCA.Text = { RichWorkspaceEnabled: workspaceEnabled, + RichWorkspaceFilePath: '', } diff --git a/src/helpers/links.js b/src/helpers/links.js index ba67660e90c..73e2eae405a 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -55,10 +55,10 @@ const domHref = function(node) { if (ref.match(/^[a-zA-Z]*:/)) { return ref } - const match = ref.match(/^([^?]*)\?fileId=(\d+)(&context=([^&]*))?/) + const match = ref.match(/^([^?]*)\?fileId=(\d+)/) if (match) { const [, relPath, id] = match - const file = match[4] || OCA.Viewer.file + const file = OCA.Viewer.file || OCA.Text.RichWorkspaceFilePath const currentDir = basedir(file) const dir = absolutePath(currentDir, basedir(relPath)) return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`) diff --git a/src/public.js b/src/public.js index cf28f0ce022..40d607d02f5 100644 --- a/src/public.js +++ b/src/public.js @@ -58,4 +58,5 @@ documentReady(() => { OCA.Text = { RichWorkspaceEnabled: loadState('text', 'workspace_available'), + RichWorkspaceFilePath: '', } From aec77abab2936ac626d877c4078fbbc4ac92bae7 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Thu, 10 Feb 2022 00:16:09 +0100 Subject: [PATCH 3/3] Define globale OCA.Text object when loading EditorWrapper view viewer.js. --- src/viewer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/viewer.js b/src/viewer.js index ae046543ecc..2712921166a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -37,3 +37,7 @@ if (typeof OCA.Viewer === 'undefined') { theme: 'default', }) } + +OCA.Text = { + RichWorkspaceFilePath: '', +}