From fa9490c89e36cda57428ffd01411ca0bea24bda0 Mon Sep 17 00:00:00 2001 From: Tamara Steinwender <tamara.steinwender@tugraz.at> Date: Wed, 10 Feb 2021 14:18:19 +0100 Subject: [PATCH] Remove sync to a provider functionality --- .../src/dbp-nextcloud-file-picker.js | 12 ++++ packages/file-handling/src/file-sink.js | 72 ++++++++++--------- packages/file-handling/src/file-source.js | 70 +++++++++--------- 3 files changed, 86 insertions(+), 68 deletions(-) diff --git a/packages/file-handling/src/dbp-nextcloud-file-picker.js b/packages/file-handling/src/dbp-nextcloud-file-picker.js index c84aef9e..342c0009 100644 --- a/packages/file-handling/src/dbp-nextcloud-file-picker.js +++ b/packages/file-handling/src/dbp-nextcloud-file-picker.js @@ -323,6 +323,9 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { * @param path */ loadDirectory(path) { + if ( typeof this.directoryPath === 'undefined' ) { + this.directoryPath = ''; + } console.log("load nextcloud directory", path); this.selectAllButton = true; this.loading = true; @@ -865,6 +868,9 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { addFolder() { if (this._('#new-folder').value !== "") { let folderName = this._('#new-folder').value; + if ( typeof this.directoryPath === 'undefined' ) { + this.directoryPath = ''; + } let folderPath = this.directoryPath + "/" + folderName; this.webDavClient.createDirectory(folderPath).then(contents => { // this.loadDirectory(this.directoryPath); @@ -913,6 +919,9 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { * @returns {string} parent directory path */ getParentDirectoryPath() { + if ( typeof this.directoryPath === 'undefined' ) { + this.directoryPath = ''; + } let path = this.directoryPath.replace(/\/$/, ""); path = path.replace(path.split("/").pop(), "").replace(/\/$/, ""); @@ -925,6 +934,9 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { * @returns {string} clickable breadcrumb path */ getBreadcrumb() { + if ( typeof this.directoryPath === 'undefined' ) { + this.directoryPath = ''; + } let htmlpath = []; htmlpath[0] = html`<span class="breadcrumb"><a class="home-link" @click="${() => { this.loadDirectory(""); }}" title="${i18n.t('nextcloud-file-picker.folder-home')}"><dbp-icon name="home"></dbp-icon> </a></span>`; const directories = this.directoryPath.split('/'); diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js index 24e93de3..d0b8bdf0 100644 --- a/packages/file-handling/src/file-sink.js +++ b/packages/file-handling/src/file-sink.js @@ -24,18 +24,18 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { this.nextcloudAuthUrl = ''; this.nextcloudWebDavUrl = ''; this.nextcloudName ='Nextcloud'; - this.nextcloudDefaultDir = ''; - this.nextcloudDir = ''; + this.nextcloudPath = ''; this.nextcloudFileURL = ''; this.text = ''; this.buttonLabel = ''; this.filename = "files.zip"; this.files = []; - this.activeDestination = 'local'; + this.activeTarget = 'local'; this.isDialogOpen = false; - this.enabledDestinations = 'local'; - this.defaultSink = 'a'; + this.enabledTargets = 'local'; this.firstOpen = true; + + this.initialFileHandlingState = {target: '', path: ''}; } static get scopedElements() { @@ -56,7 +56,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { lang: {type: String}, filename: {type: String}, files: {type: Array, attribute: false}, - enabledDestinations: {type: String, attribute: 'enabled-destinations'}, + enabledTargets: {type: String, attribute: 'enabled-targets'}, nextcloudAuthUrl: {type: String, attribute: 'nextcloud-auth-url'}, nextcloudWebDavUrl: {type: String, attribute: 'nextcloud-web-dav-url'}, nextcloudName: {type: String, attribute: 'nextcloud-name'}, @@ -64,12 +64,12 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { text: {type: String}, buttonLabel: {type: String, attribute: 'button-label'}, isDialogOpen: {type: Boolean, attribute: false}, - - activeDestination: {type: String, attribute: 'active-destination'}, - defaultSink: {type: String, attribute: 'default-sink'}, + activeTarget: {type: String, attribute: 'active-target'}, firstOpen: {type: Boolean, attribute: false}, - nextcloudDefaultDir: {type: String, attribute: 'nextcloud-default'}, - nextcloudDir: {type: String, attribute: false}, + nextcloudPath: {type: String, attribute: false}, + + initialFileHandlingState: {type: Object, attribute: 'initial-file-handling-state'}, + }; } @@ -79,6 +79,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { this.updateComplete.then(() => { + console.log("initialFileHandlingState", this.initialFileHandlingState); }); } @@ -123,9 +124,9 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { case "lang": i18n.changeLanguage(this.lang); break; - case "enabledDestinations": - if (!this.hasEnabledDestination(this.activeDestination)) { - this.activeDestination = this.enabledDestinations.split(",")[0]; + case "enabledTargets": + if (!this.hasEnabledDestination(this.activeTargets)) { + this.activeTargets = this.enabledTargets.split(",")[0]; } break; case "files": @@ -133,10 +134,10 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { this.openDialog(); } break; - case "nextcloudDefaultDir": + case "initialFileHandlingState": //check if default destination is set if (this.firstOpen) { - this.nextcloudDir = this.nextcloudDefaultDir; + this.nextcloudPath = this.initialFileHandlingState.path; } break; } @@ -146,7 +147,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { } hasEnabledDestination(source) { - return this.enabledDestinations.split(',').includes(source); + return this.enabledTargets.split(',').includes(source); } async uploadToNextcloud(directory) { @@ -170,14 +171,15 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { sendDestination() { let data = {}; - if (this.activeDestination == 'nextcloud') { - data = {"source": this.activeDestination, "nextcloud": this._("#nextcloud-file-picker").directoryPath}; + if (this.activeTarget == 'nextcloud') { + data = {"target": this.activeTarget, "path": this._("#nextcloud-file-picker").directoryPath}; } else { - data = {"source": this.activeDestination}; + data = {"target": this.activeTarget}; } - const event = new CustomEvent("dbp-file-sink-switched", { "detail": data, bubbles: true, composed: true }); - this.dispatchEvent(event); + this.sendSetPropertyEvent('initial-file-handling-state', data); + //const event = new CustomEvent("dbp-file-sink-switched", { "detail": data, bubbles: true, composed: true }); + //this.dispatchEvent(event); } @@ -187,6 +189,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { } loadWebdavDirectory() { + if (this._('#nextcloud-file-picker').webDavClient !== null) { this._('#nextcloud-file-picker').loadDirectory(this._('#nextcloud-file-picker').directoryPath); } @@ -199,14 +202,15 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { onClose: modal => { this.isDialogOpen = false; }, }); + console.log("initialFileHandlingState", this.initialFileHandlingState); //check if default destination is set - if (this.defaultSink !== '' && typeof this.defaultSink !== 'undefined' && this.firstOpen) { - this.activeDestination = this.defaultSink; - this.nextcloudDir = this.nextcloudDefaultDir; + if (this.initialFileHandlingState.target !== '' && typeof this.initialFileHandlingState.target !== 'undefined' && this.firstOpen) { + this.activeTarget = this.initialFileHandlingState.target; + this.nextcloudPath = this.initialFileHandlingState.path; if (this._('#nextcloud-file-picker').webDavClient !== null) { - this._('#nextcloud-file-picker').loadDirectory(this.nextcloudDefaultDir); - console.log("load default nextcloud sink", this.nextcloudDefaultDir); + this._('#nextcloud-file-picker').loadDirectory(this.initialFileHandlingState.path); + console.log("load default nextcloud sink", this.initialFileHandlingState.path); } this.firstOpen = false; } @@ -249,14 +253,14 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { <div class="modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-picker-title"> <nav class="modal-nav"> <div title="${i18n.t('file-sink.nav-local')}" - @click="${() => { this.activeDestination = "local"; }}" - class="${classMap({"active": this.activeDestination === "local", hidden: !this.hasEnabledDestination("local")})}"> + @click="${() => { this.activeTarget = "local"; }}" + class="${classMap({"active": this.activeTarget === "local", hidden: !this.hasEnabledDestination("local")})}"> <dbp-icon class="nav-icon" name="laptop"></dbp-icon> <p>${i18n.t('file-source.nav-local')}</p> </div> <div title="${this.nextcloudName}" - @click="${() => { this.activeDestination = "nextcloud"; this.loadWebdavDirectory();}}" - class="${classMap({"active": this.activeDestination === "nextcloud", hidden: !this.hasEnabledDestination("nextcloud") || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> + @click="${() => { this.activeTarget = "nextcloud"; this.loadWebdavDirectory();}}" + class="${classMap({"active": this.activeTarget === "nextcloud", hidden: !this.hasEnabledDestination("nextcloud") || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> <dbp-icon class="nav-icon" name="cloud"></dbp-icon> <p> ${this.nextcloudName} </p> </div> @@ -270,7 +274,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { <main class="modal-content" id="modal-picker-content"> - <div class="source-main ${classMap({"hidden": this.activeDestination !== "local"})}"> + <div class="source-main ${classMap({"hidden": this.activeTarget !== "local"})}"> <div id="zip-download-block"> <div class="block"> ${this.text || i18n.t('file-sink.local-intro', {'count': this.files.length})} @@ -282,7 +286,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { </button> </div> </div> - <div class="source-main ${classMap({"hidden": this.activeDestination !== "nextcloud" || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> + <div class="source-main ${classMap({"hidden": this.activeTarget !== "nextcloud" || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> <dbp-nextcloud-file-picker id="nextcloud-file-picker" class="${classMap({hidden: this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}" directories-only @@ -293,7 +297,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { auth-url="${this.nextcloudAuthUrl}" web-dav-url="${this.nextcloudWebDavUrl}" nextcloud-name="${this.nextcloudName}" - directory-path="${this.nextcloudDir}" + directory-path="${this.nextcloudPath}" nextcloud-file-url="${this.nextcloudFileURL}" @dbp-nextcloud-file-picker-file-uploaded="${(event) => { this.uploadToNextcloud(event.detail); diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js index 853e3a49..6fda9a3f 100644 --- a/packages/file-handling/src/file-source.js +++ b/packages/file-handling/src/file-source.js @@ -40,21 +40,21 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { this.nextcloudAuthUrl = ''; this.nextcloudName ='Nextcloud'; this.nextcloudWebDavUrl = ''; - this.nextcloudDefaultDir = ''; - this.nextcloudDir = ''; + this.nextcloudPath = ''; this.nextcloudFileURL = ''; this.dropArea = null; this.allowedMimeTypes = '*/*'; - this.enabledSources = 'local'; + this.enabledTargets = 'local'; this.text = ''; this.buttonLabel = ''; this.disabled = false; this.decompressZip = false; this._queueKey = 0; - this.activeSource = 'local'; + this.activeTarget = 'local'; this.isDialogOpen = false; - this.defaultSource = ''; this.firstOpen = true; + + this.initialFileHandlingState = {target: '', path: ''}; } static get scopedElements() { @@ -74,7 +74,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { context: { type: String, attribute: 'context'}, lang: { type: String }, allowedMimeTypes: { type: String, attribute: 'allowed-mime-types' }, - enabledSources: { type: String, attribute: 'enabled-sources' }, + enabledTargets: { type: String, attribute: 'enabled-targets' }, nextcloudAuthUrl: { type: String, attribute: 'nextcloud-auth-url' }, nextcloudWebDavUrl: { type: String, attribute: 'nextcloud-web-dav-url' }, nextcloudName: { type: String, attribute: 'nextcloud-name' }, @@ -83,13 +83,12 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { buttonLabel: { type: String, attribute: 'button-label' }, disabled: { type: Boolean }, decompressZip: { type: Boolean, attribute: 'decompress-zip' }, - activeSource: { type: String, attribute: 'active-source' }, + activeTarget: { type: String, attribute: 'active-target' }, isDialogOpen: { type: Boolean, attribute: 'dialog-open' }, - - defaultSource: { type: String, attribute: 'default-source' }, firstOpen: { type: Boolean, attribute: false }, - nextcloudDefaultDir: { type: String, attribute: 'nextcloud-default' }, - nextcloudDir: { type: String, attribute: false }, + nextcloudPath: { type: String, attribute: false }, + + initialFileHandlingState: {type: Object, attribute: 'initial-file-handling-state'}, }; } @@ -99,9 +98,9 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { case "lang": i18n.changeLanguage(this.lang); break; - case "enabledSources": - if (!this.hasEnabledSource(this.activeSource)) { - this.activeSource = this.enabledSources.split(",")[0]; + case "enabledTargets": + if (!this.hasEnabledSource(this.activeTarget)) { + this.activeTarget = this.enabledTargets.split(",")[0]; } break; case "isDialogOpen": @@ -113,10 +112,10 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { // this.closeDialog(); } break; - case "nextcloudDefaultDir": + case "initialFileHandlingState": //check if default destination is set if (this.firstOpen) { - this.nextcloudDir = this.nextcloudDefaultDir; + this.nextcloudPath = this.initialFileHandlingState.path; } break; @@ -141,6 +140,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { }); this.dropArea.addEventListener('drop', this.handleDrop.bind(this), false); this._('#fileElem').addEventListener('change', this.handleChange.bind(this)); + }); } @@ -233,14 +233,16 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { sendSource() { let data = {}; - if (this.activeSource == 'nextcloud') { - data = {"source": this.activeSource, "nextcloud": this._("#nextcloud-file-picker").directoryPath}; + if (this.activeTarget == 'nextcloud') { + data = {"target": this.activeTarget, "path": this._("#nextcloud-file-picker").directoryPath}; } else { - data = {"source": this.activeSource}; + data = {"target": this.activeTarget}; } - const event = new CustomEvent("dbp-file-source-switched", { "detail": data, bubbles: true, composed: true }); - this.dispatchEvent(event); + + this.sendSetPropertyEvent('initial-file-handling-state', data); + //const event = new CustomEvent("initial-file-handling-state", { "detail": data, bubbles: true, composed: true }); + //this.dispatchEvent(event); } checkFileType(file) { @@ -263,7 +265,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { } hasEnabledSource(source) { - return this.enabledSources.split(',').includes(source); + return this.enabledTargets.split(',').includes(source); } /** @@ -364,7 +366,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { } openDialog() { - if (this.enabledSources.includes('nextcloud')) { + if (this.enabledTargets.includes('nextcloud')) { this.loadWebdavDirectory(); } @@ -381,12 +383,12 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { //check if default source is set - if (this.defaultSource !== '' && typeof this.defaultSource !== 'undefined' && this.firstOpen) { - this.activeDestination = this.defaultSource; - this.nextcloudDir = this.nextcloudDefaultDir; + if (this.initialFileHandlingState.target !== '' && typeof this.initialFileHandlingState.target !== 'undefined' && this.firstOpen) { + this.activeDestination = this.initialFileHandlingState.target; + this.nextcloudPath = this.initialFileHandlingState.path; if (this._('#nextcloud-file-picker').webDavClient !== null) { - this._('#nextcloud-file-picker').loadDirectory(this.nextcloudDefaultDir); - console.log("load default nextcloud source", this.defaultSource); + this._('#nextcloud-file-picker').loadDirectory(this.initialFileHandlingState.path); + console.log("load default nextcloud source", this.initialFileHandlingState.target); } this.firstOpen = false; } @@ -466,14 +468,14 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { <div class="modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-picker-title"> <nav class="modal-nav"> <div title="${i18n.t('file-source.nav-local')}" - @click="${() => { this.activeSource = "local"; }}" - class="${classMap({"active": this.activeSource === "local", hidden: !this.hasEnabledSource("local")})}"> + @click="${() => { this.activeTarget = "local"; }}" + class="${classMap({"active": this.activeTarget === "local", hidden: !this.hasEnabledSource("local")})}"> <dbp-icon class="nav-icon" name="laptop"></dbp-icon> <p>${i18n.t('file-source.nav-local')}</p> </div> <div title="Nextcloud" - @click="${() => { this.activeSource = "nextcloud"; this.loadWebdavDirectory();}}" - class="${classMap({"active": this.activeSource === "nextcloud", hidden: !this.hasEnabledSource("nextcloud") || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> + @click="${() => { this.activeTarget = "nextcloud"; this.loadWebdavDirectory();}}" + class="${classMap({"active": this.activeTarget === "nextcloud", hidden: !this.hasEnabledSource("nextcloud") || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> <dbp-icon class="nav-icon" name="cloud"></dbp-icon> <p> ${this.nextcloudName} </p> </div> @@ -488,7 +490,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { </div> <main class="modal-content" id="modal-picker-content"> - <div class="source-main ${classMap({"hidden": this.activeSource !== "local"})}"> + <div class="source-main ${classMap({"hidden": this.activeTarget !== "local"})}"> <div id="dropArea"> <div class="block"> <p>${this.text || i18n.t('intro')}</p> @@ -504,7 +506,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { </label> </div> </div> - <div class="source-main ${classMap({"hidden": this.activeSource !== "nextcloud" || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> + <div class="source-main ${classMap({"hidden": this.activeTarget !== "nextcloud" || this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> <dbp-nextcloud-file-picker id="nextcloud-file-picker" class="${classMap({hidden: this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}" ?disabled="${this.disabled}" -- GitLab