From f1077760a7835d57a474b2070fb7413ebde51e6b Mon Sep 17 00:00:00 2001 From: elizavetaRa Date: Thu, 11 Nov 2021 09:27:13 +0100 Subject: [PATCH] create files for available mimetypes #5890 --- .../src/components/AppBar/AppBar.vue | 78 +++++++++++++++++-- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/AppBar.vue b/packages/web-app-files/src/components/AppBar/AppBar.vue index 0bdf2d8fc49..c999b60c6b9 100644 --- a/packages/web-app-files/src/components/AppBar/AppBar.vue +++ b/packages/web-app-files/src/components/AppBar/AppBar.vue @@ -75,7 +75,7 @@ @click="showCreateResourceModal" > - New folder… + New folder @@ -94,6 +94,23 @@ + @@ -156,6 +173,7 @@ export default { fileFolderCreationLoading: false }), computed: { + ...mapGetters('External', ['mimeTypes']), ...mapGetters(['getToken', 'configuration', 'newFileHandlers', 'quota', 'user']), ...mapGetters('Files', [ 'files', @@ -167,6 +185,9 @@ export default { ...mapState(['route']), ...mapState('Files', ['areHiddenFilesShown']), + mimetypesAllowedForCreation() { + return this.mimeTypes.filter((mimetype) => mimetype.allow_creation) || [] + }, newButtonTooltip() { if (!this.canUpload) { return this.$gettext('You have no permission to upload!') @@ -338,8 +359,12 @@ export default { '_blank' ) }, - - showCreateResourceModal(isFolder = true, ext = 'txt', openAction = null) { + showCreateResourceModal( + isFolder = true, + ext = 'txt', + openAction = null, + generateNewFile = false + ) { const defaultName = isFolder ? this.$gettext('New folder') : this.$gettext('New file') + '.' + ext @@ -366,7 +391,11 @@ export default { ? this.checkNewFolderName(defaultName) : this.checkNewFileName(defaultName), onCancel: this.hideModal, - onConfirm: isFolder ? this.addNewFolder : this.addNewFile, + onConfirm: isFolder + ? this.addNewFolder + : generateNewFile + ? this.generateNewFile + : this.addNewFile, onInput: checkInputValue } @@ -510,7 +539,46 @@ export default { this.fileFolderCreationLoading = false }, - + async generateNewFile(fileName) { + try { + const path = pathUtil.join(this.currentPath, fileName) + const url = '/app/new?filename=' + path + console.log(encodeURI(url), path) + const headers = new Headers() + headers.append('Authorization', 'Bearer ' + this.getToken) + headers.append('X-Requested-With', 'XMLHttpRequest') + const response = await fetch(encodeURI(url), { + method: 'POST', + headers + }) + await response.json() + let resource + if (this.isPersonalRoute) { + await this.$client.files.putFileContents(path, '') + resource = await this.$client.files.fileInfo(path, DavProperties.Default) + } + resource = buildResource(resource) + this.UPSERT_RESOURCE(resource) + this.$_fileActions_triggerDefaultAction(resource) + this.hideModal() + if (this.isPersonalRoute) { + this.loadIndicators({ + client: this.$client, + currentFolder: this.currentFolder.path + }) + } + setTimeout(() => { + this.setFileSelection([resource]) + this.scrollToResource(resource) + }) + } catch (error) { + this.showMessage({ + title: this.$gettext('Creating file failed…'), + desc: error, + status: 'danger' + }) + } + }, checkNewFileName(fileName) { if (fileName === '') { return this.$gettext('File name cannot be empty')