Skip to content
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
4 changes: 2 additions & 2 deletions js/editor-rich.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions js/text-public.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ object-assign
* @license MIT
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.6.14
* (c) 2014-2021 Evan You
Expand All @@ -44,3 +51,5 @@ object-assign
* (c) 2021 Evan You
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

70 changes: 4 additions & 66 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ const registerFileActionFallback = () => {
const FilesWorkspacePlugin = {

el: null,
vm: null,

attach(fileList) {
if (fileList.id !== 'files' && fileList.id !== 'files.public') {
Expand All @@ -150,51 +149,6 @@ const FilesWorkspacePlugin = {
render: this.render.bind(this),
priority: 10,
})

const PROPERTY_WORKSPACE_FILE = `{${OC.Files.Client.NS_NEXTCLOUD}}rich-workspace-file`

const oldGetWebdavProperties = fileList._getWebdavProperties
fileList._getWebdavProperties = function() {
return [
...oldGetWebdavProperties.apply(this, arguments),
PROPERTY_WORKSPACE_FILE,
]
}

let readmeId = null

fileList.filesClient.addFileInfoParser((response, data) => {
if (data.mimetype === 'httpd/unix-directory') {
const props = response.propStat[0].properties
const dir = data.path + (data.path.endsWith('/') ? '' : '/') + data.name
if (dir === fileList.getCurrentDirectory()) {
readmeId = props[PROPERTY_WORKSPACE_FILE]
this.vm.folder = {
permissions: data.permissions,
}
this.vm.loaded = true
// in case no file is found we are done
this.vm.ready = true
}
}
if (readmeId && data.id === readmeId) {
if (data.mimetype !== 'text/markdown') {
console.warn('Expected workspace file to be markdown:', data)
}
this.open(data)
return
}
/*
* Handle the creation of 'Readme.md'.
* The PROPFIND after the creation does not include the parent dir.
*/
if (data.name === 'Readme.md'
&& data.mimetype === 'text/markdown'
&& data.path === fileList.getCurrentDirectory()) {
this.open(data)
}
})

},

render(fileList) {
Expand All @@ -209,37 +163,21 @@ const FilesWorkspacePlugin = {
Vue.prototype.n = window.n
Vue.prototype.OCA = window.OCA
const View = Vue.extend(RichWorkspace)
this.vm = new View({
const vm = new View({
propsData: {
file: null,
folder: null,
path: fileList.getCurrentDirectory(),
},
store,
}).$mount(this.el)

fileList.$el.on('urlChanged', data => {
this.vm.file = null
this.vm.folder = null
vm.path = data.dir.toString()
})
fileList.$el.on('changeDirectory', data => {
this.vm.file = null
this.vm.folder = null
vm.path = data.dir.toString()
})
})
},

open(data) {
const previous = this.vm.file
const id = parseInt(data.id)
this.vm.file = {
...data,
id,
}
if (previous?.id !== id) {
// Editor loads new file. Wait for it to be ready.
this.vm.ready = false
}
},
}

export {
Expand Down
68 changes: 56 additions & 12 deletions src/views/RichWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
v-show="ready"
:key="file.path"
:file-id="file.id"
:relative-path="filepath"
:relative-path="file.path"
:share-token="shareToken"
:active="true"
:autohide="true"
Expand All @@ -46,26 +46,29 @@
</template>

<script>
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { subscribe } from '@nextcloud/event-bus'

const IS_PUBLIC = !!(document.getElementById('isPublic'))
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)

export default {
name: 'RichWorkspace',
components: {
EditorWrapper: () => import(/* webpackChunkName: "editor" */'./../components/EditorWrapper.vue'),
},
props: {
file: {
type: Object,
default: null,
},
folder: {
type: Object,
default: null,
path: {
type: String,
required: true,
},
},
data() {
return {
focus: false,
folder: null,
file: null,
loaded: false,
ready: false,
autofocus: false,
Expand All @@ -89,15 +92,22 @@ export default {
},
},
watch: {
path() {
this.getFileInfo()
},
focus(newValue) {
if (!newValue) {
document.querySelector('#editor').scrollTo(0, 0)
}
},
},
async mounted() {
if (this.enabled) {
this.getFileInfo()
}
subscribe('Text::showRichWorkspace', () => {
this.enabled = true
this.getFileInfo()
})
subscribe('Text::hideRichWorkspace', () => {
this.enabled = false
Expand All @@ -108,20 +118,54 @@ export default {
// setTimeout(() => this.focus = false, 2000)
},
reset() {
this.file = null
this.focus = false
this.$nextTick(() => {
this.creating = false
this.getFileInfo()
})
},
getFileInfo() {
this.loaded = false
this.autofocus = false
this.ready = false
const params = { path: this.path }
if (IS_PUBLIC) {
params.shareToken = this.shareToken
}
return axios.get(WORKSPACE_URL, { params }).then((response) => {
const data = response.data.ocs.data
this.folder = data.folder || null
this.file = data.file
this.editing = true
this.loaded = true
return true
}).catch((error) => {
if (error.response.data.ocs && error.response.data.ocs.data.folder) {
this.folder = error.response.data.ocs.data.folder
} else {
this.folder = null
}
this.file = null
this.loaded = true
this.ready = true
this.creating = false
return false
})
},
createNew() {
if (this.creating) {
return
}
this.creating = true
this.autofocus = true
if (!this.file) {
window.FileList.createFile('Readme.md', { scrollTo: false, animate: false })
}
this.getFileInfo().then((workspaceFileExists) => {
this.autofocus = true
if (!workspaceFileExists) {
window.FileList.createFile('Readme.md', { scrollTo: false, animate: false }).then((status, data) => {
this.getFileInfo()
})
}
})
},
},
}
Expand Down