Skip to content

Commit

Permalink
Allow opening files outside of the file system in viewer
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
juliusknorr committed Aug 7, 2023
1 parent c11f7ad commit 246f158
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,29 @@
-->

<template>
<Editor :file-id="fileid"
<Editor v-if="isEditable"
:file-id="fileid"
:relative-path="filename"
:active="active"
:autofocus="autofocus"
:share-token="shareToken"
:mime="mime"
:show-outline-outside="showOutlineOutside" />
<Component :is="readerComponent" v-else :content="content" />
</template>

<script>
import axios from '@nextcloud/axios'
import PlainTextReader from './PlainTextReader.vue'
import RichTextReader from './RichTextReader.vue'

import { getSharingToken } from '../helpers/token.js'

export default {
name: 'ViewerComponent',
components: {
RichTextReader,
PlainTextReader,
Editor: () => import(/* webpackChunkName: "editor" */'./Editor.vue'),
},
props: {
Expand Down Expand Up @@ -67,6 +75,58 @@ export default {
type: Boolean,
default: false,
},
permissions: {
type: String,
default: '',
},
source: {
type: String,
default: undefined,
},
},
data() {
return {
content: '',
}
},
computed: {
/** @return {boolean} */
isEditable() {
return this.permissions.includes('W')
},

/** @return {boolean} */
readerComponent() {
return this.mime === 'text/markdown' ? RichTextReader : PlainTextReader
},
},

watch: {
active() {
this.loadFileContent()
},
},

beforeMount() {
// FIXME Dirty fix to avoid recreating the component on stable16
if (typeof this.$parent.$parent !== 'undefined' && this.$parent.$parent.onResize) {
window.removeEventListener('resize', this.$parent.$parent.onResize)
}
},

mounted() {
this.loadFileContent()
},

methods: {
async loadFileContent() {
if (!this.isEditable && this.content === '') {
const response = await axios.get(this.source)
this.content = response.data
this.contentLoaded = true
this.$emit('update:loaded', true)
}
},
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ if (typeof OCA.Viewer === 'undefined') {
component: ViewerComponent,
group: null,
theme: 'default',
canCompare: true,
})
}

0 comments on commit 246f158

Please sign in to comment.