Skip to content
Merged
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
84 changes: 83 additions & 1 deletion src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,92 @@ import { logger } from './helpers/logger.js'
import { openMimetypes } from './helpers/mime.js'
import { documentReady } from './helpers/index.js'
import store from './store/index.js'
import { emit, subscribe } from '@nextcloud/event-bus'
import RichWorkspace from './views/RichWorkspace.vue'

__webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-line
__webpack_public_path__ = OC.linkTo('text', 'js/') // eslint-disable-line

const newRichWorkspaceFileMenuPlugin = {
attach(menu) {
const fileList = menu.fileList
const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension')
// only attach to main file list, public view is not supported yet
if (fileList.id !== 'files' && fileList.id !== 'files.public') {
return
}

// register the new menu entry
menu.addMenuEntry({
id: 'rich-workspace-init',
displayName: t('text', 'Add description'),
templateName: descriptionFile,
iconClass: 'icon-rename',
fileType: 'file',
useInput: false,
actionHandler() {
return window.FileList
.createFile(descriptionFile, { scrollTo: false, animate: false })
.then(() => emit('Text::showRichWorkspace', { autofocus: true }))
},
shouldShow() {
return !fileList.findFile(descriptionFile)
},
})
},
}

const filesWorkspacePlugin = {
el: null,

attach(fileList) {
if (fileList.id !== 'files' && fileList.id !== 'files.public') {
return
}
this.el = document.createElement('div')
fileList.registerHeader({
id: 'workspace',
el: this.el,
render: this.render.bind(this),
priority: 10,
})
},

render(fileList) {
if (fileList.id !== 'files' && fileList.id !== 'files.public') {
return
}

OC.Plugins.register('OCA.Files.NewFileMenu', newRichWorkspaceFileMenuPlugin)
import('vue').then((module) => {
const Vue = module.default
this.el.id = 'files-workspace-wrapper'
Vue.prototype.t = window.t
Vue.prototype.n = window.n
Vue.prototype.OCA = window.OCA
const View = Vue.extend(RichWorkspace)
const vm = new View({
propsData: {
path: fileList.getCurrentDirectory(),
hasRichWorkspace: true,
},
store,
}).$mount(this.el)
subscribe('files:navigation:changed', () => {
// Expose if the default file list is active to the component
// to only render the workspace if the file list is actually visible
vm.active = OCA.Files.App.getCurrentFileList() === fileList
})
fileList.$el.on('urlChanged', data => {
vm.path = data.dir.toString()
})
fileList.$el.on('changeDirectory', data => {
vm.path = data.dir.toString()
})
})
},
}

const loadEditor = ({ sharingToken, mimetype, fileId, $el }) => {
const container = document.createElement('div')
container.id = 'texteditor'
Expand Down Expand Up @@ -58,7 +140,7 @@ documentReady(() => {

// list of files - dir sharing
if (filesTable) {
// OC.Plugins.register('OCA.Files.FileList', FilesWorkspacePlugin)
OC.Plugins.register('OCA.Files.FileList', filesWorkspacePlugin)
registerFileActionFallback()
registerFileCreate()
return
Expand Down