-
Notifications
You must be signed in to change notification settings - Fork 156
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
web-app-external: view mode #9879
Changes from all commits
5a0d15e
1dcffe6
5cb3069
3702a68
0c04d8d
b65157a
da2b90b
f31fbad
05ed300
0cd57cc
47800c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,20 +28,34 @@ import { PropType, computed, defineComponent, unref, nextTick, ref, watch, VNode | |
import { useTask } from 'vue-concurrency' | ||
import { useGettext } from 'vue3-gettext' | ||
|
||
import { Resource } from '@ownclouders/web-client/src' | ||
import { Resource, SpaceResource } from '@ownclouders/web-client/src' | ||
import { urlJoin } from '@ownclouders/web-client/src/utils' | ||
import { queryItemAsString, useRequest, useRouteQuery, useStore } from '@ownclouders/web-pkg' | ||
import { configurationManager } from '@ownclouders/web-pkg' | ||
import { | ||
isSameResource, | ||
queryItemAsString, | ||
useConfigurationManager, | ||
useRequest, | ||
useRouteQuery, | ||
useStore | ||
} from '@ownclouders/web-pkg' | ||
import { | ||
isProjectSpaceResource, | ||
isPublicSpaceResource, | ||
isShareSpaceResource | ||
} from '@ownclouders/web-client/src/helpers' | ||
|
||
export default defineComponent({ | ||
name: 'ExternalApp', | ||
props: { | ||
resource: { type: Object as PropType<Resource>, required: true } | ||
space: { type: Object as PropType<SpaceResource>, required: true }, | ||
resource: { type: Object as PropType<Resource>, required: true }, | ||
isReadOnly: { type: Boolean, required: true } | ||
}, | ||
emits: ['update:applicationName'], | ||
setup(props, { emit }) { | ||
const language = useGettext() | ||
const store = useStore() | ||
const configurationManager = useConfigurationManager() | ||
|
||
const { $gettext } = language | ||
const { makeRequest } = useRequest() | ||
|
@@ -73,8 +87,15 @@ export default defineComponent({ | |
}) | ||
} | ||
|
||
const loadAppUrl = useTask(function* () { | ||
const loadAppUrl = useTask(function* (signal, viewMode: string) { | ||
try { | ||
if (props.isReadOnly && viewMode === 'write') { | ||
store.dispatch('showErrorMessage', { | ||
title: $gettext('Cannot open file in edit mode as it is read-only') | ||
}) | ||
return | ||
} | ||
|
||
const fileId = props.resource.fileId | ||
const baseUrl = urlJoin( | ||
configurationManager.serverUrl, | ||
|
@@ -84,7 +105,8 @@ export default defineComponent({ | |
const query = stringify({ | ||
file_id: fileId, | ||
lang: language.current, | ||
...(unref(applicationName) && { app_name: unref(applicationName) }) | ||
...(unref(applicationName) && { app_name: unref(applicationName) }), | ||
...(viewMode && { view_mode: viewMode }) | ||
}) | ||
|
||
const url = `${baseUrl}?${query}` | ||
|
@@ -132,12 +154,56 @@ export default defineComponent({ | |
} | ||
}).restartable() | ||
|
||
const determineOpenAsPreview = (appName: string) => { | ||
const openAsPreview = configurationManager.options.editor.openAsPreview | ||
return ( | ||
openAsPreview === true || (Array.isArray(openAsPreview) && openAsPreview.includes(appName)) | ||
) | ||
} | ||
|
||
// switch to write mode when edit is clicked | ||
const catchClickMicrosoftEdit = (event) => { | ||
try { | ||
if (JSON.parse(event.data)?.MessageId === 'UI_Edit') { | ||
loadAppUrl.perform('write') | ||
} | ||
} catch (e) {} | ||
} | ||
watch( | ||
props.resource, | ||
() => { | ||
loadAppUrl.perform() | ||
applicationName, | ||
(newAppName, oldAppName) => { | ||
if (determineOpenAsPreview(newAppName) && newAppName !== oldAppName) { | ||
window.addEventListener('message', catchClickMicrosoftEdit) | ||
} else { | ||
window.removeEventListener('message', catchClickMicrosoftEdit) | ||
} | ||
}, | ||
{ | ||
immediate: true | ||
} | ||
) | ||
dschmidt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
watch( | ||
[props.resource], | ||
([newResource], [oldResource]) => { | ||
if (isSameResource(newResource, oldResource)) { | ||
return | ||
} | ||
|
||
debugger | ||
dschmidt marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dschmidt you forgot to delete it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll drop it in my PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doh 😂 |
||
|
||
let viewMode = props.isReadOnly ? 'view' : 'write' | ||
if ( | ||
determineOpenAsPreview(unref(applicationName)) && | ||
(isShareSpaceResource(props.space) || | ||
isPublicSpaceResource(props.space) || | ||
isProjectSpaceResource(props.space)) | ||
) { | ||
viewMode = 'view' | ||
} | ||
loadAppUrl.perform(viewMode) | ||
}, | ||
{ immediate: true } | ||
{ immediate: true, deep: true } | ||
) | ||
|
||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to create an enum for the viewMode since its used at multiple locations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems overkill to me tbh. In theory we could also support more modes which are defined by the backend... this is just some specific handling for an edge case