diff --git a/packages/file-handling/src/dbp-nextcloud-file-picker.js b/packages/file-handling/src/dbp-nextcloud-file-picker.js index 73fdf9ba960296044858dda7518c97aef2e43736..1b8e1e9d9b562c02007698f1564f75abaec69696 100644 --- a/packages/file-handling/src/dbp-nextcloud-file-picker.js +++ b/packages/file-handling/src/dbp-nextcloud-file-picker.js @@ -72,7 +72,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { isPickerActive: { type: Boolean, attribute: false }, statusText: { type: String, attribute: false }, folderIsSelected: { type: String, attribute: false }, - directoryPath: { type: String, attribute: false }, + directoryPath: { type: String, attribute: 'directory-path' }, allowedMimeTypes: { type: String, attribute: 'allowed-mime-types' }, directoriesOnly: { type: Boolean, attribute: 'directories-only' }, maxSelectedItems: { type: Number, attribute: 'max-selected-items' }, @@ -84,6 +84,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { activeDirectoryACL: { type: String, attribute: false }, selectAllButton: { type: Boolean, attribute: false }, abortUploadButton: { type: Boolean, attribute: false }, + }; } @@ -474,6 +475,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { this.dispatchEvent(event); } + /** * Upload Files to a directory * @@ -1246,7 +1248,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { border-bottom: 1px solid black; } - .breadcrumb:last-child{ + .breadcrumb:last-child, .breadcrumb:first-child{ border-bottom: none; } diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js index 3af358ae63ab5a6511ca20dfb3bad61048496b48..b1b8d00e02dcb7664c9911307c178cae194720ff 100644 --- a/packages/file-handling/src/file-sink.js +++ b/packages/file-handling/src/file-sink.js @@ -24,6 +24,8 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { this.nextcloudAuthUrl = ''; this.nextcloudWebDavUrl = ''; this.nextcloudName ='Nextcloud'; + this.nextcloudDefaultDir = ''; + this.nextcloudDir = ''; this.text = ''; this.buttonLabel = ''; this.filename = "files.zip"; @@ -31,6 +33,8 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { this.activeDestination = 'local'; this.isDialogOpen = false; this.enabledDestinations = 'local'; + this.defaultSink = 'a'; + this.firstOpen = true; } static get scopedElements() { @@ -57,10 +61,22 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { text: { type: String }, buttonLabel: { type: String, attribute: 'button-label' }, isDialogOpen: { type: Boolean, attribute: false }, - activeDestination: { type: Boolean, attribute: false }, + activeDestination: { type: String, attribute: 'active-destination' }, + defaultSink: { type: String, attribute: 'default-sink' }, + firstOpen: { type: Boolean, attribute: false }, + nextcloudDefaultDir: { type: String, attribute: 'nextcloud-default' }, + nextcloudDir: { type: String, attribute: false }, }; } + connectedCallback() { + super.connectedCallback(); + + this.updateComplete.then(() => { + + }); + } + async downloadCompressedFiles() { // see: https://stuk.github.io/jszip/ let JSZip = (await import('jszip/dist/jszip.js')).default; @@ -129,6 +145,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { } finishedFileUpload(event) { + this.sendDestination(); MicroModal.close(this._('#modal-picker')); if (event.detail > 0) { send({ @@ -140,6 +157,19 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { } } + sendDestination() { + let data = {}; + if (this.activeDestination == 'nextcloud') { + data = {"source": this.activeDestination, "nextcloud": this._("#nextcloud-file-picker").directoryPath}; + + } else { + data = {"source": this.activeDestination}; + } + const event = new CustomEvent("dbp-file-sink-switched", { "detail": data, bubbles: true, composed: true }); + this.dispatchEvent(event); + } + + preventDefaults (e) { e.preventDefault(); e.stopPropagation(); @@ -157,9 +187,18 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { disableScroll: true, onClose: modal => { this.isDialogOpen = false; }, }); + + + //check if default destination is set + if (this.defaultSink !== '' && this.firstOpen) { + this.activeDestination = this.defaultSink; + this.nextcloudDir = this.nextcloudDefaultDir; + this.firstOpen = false; + } } closeDialog(e) { + this.sendDestination(); MicroModal.close(this._('#modal-picker')); } @@ -239,6 +278,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) { auth-url="${this.nextcloudAuthUrl}" web-dav-url="${this.nextcloudWebDavUrl}" nextcloud-name="${this.nextcloudName}" + directory-path="${this.nextcloudDir}" @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 bee797dd90f61a0b25f5f28faceac1ea82edfc7f..8a5f1e0684ec2f0f4629dcdaf472bd23e2ba930a 100644 --- a/packages/file-handling/src/file-source.js +++ b/packages/file-handling/src/file-source.js @@ -39,6 +39,8 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { this.nextcloudAuthUrl = ''; this.nextcloudName ='Nextcloud'; this.nextcloudWebDavUrl = ''; + this.nextcloudDefaultDir = ''; + this.nextcloudDir = ''; this.dropArea = null; this.allowedMimeTypes = '*/*'; this.enabledSources = 'local'; @@ -49,6 +51,8 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { this._queueKey = 0; this.activeSource = 'local'; this.isDialogOpen = false; + this.defaultSource = ''; + this.firstOpen = true; } static get scopedElements() { @@ -75,8 +79,12 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { buttonLabel: { type: String, attribute: 'button-label' }, disabled: { type: Boolean }, decompressZip: { type: Boolean, attribute: 'decompress-zip' }, - activeSource: { type: Boolean, attribute: false }, + activeSource: { type: String, attribute: 'active-source' }, 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 }, }; } @@ -99,11 +107,10 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { this.removeAttribute("dialog-open"); // this.closeDialog(); } - break; + } }); - super.update(changedProperties); } @@ -205,12 +212,25 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { * @param file */ sendFileEvent(file) { + this.sendSource(); MicroModal.close(this._('#modal-picker')); const data = {"file": file}; const event = new CustomEvent("dbp-file-source-file-selected", { "detail": data, bubbles: true, composed: true }); this.dispatchEvent(event); } + sendSource() { + let data = {}; + if (this.activeSource == 'nextcloud') { + data = {"source": this.activeSource, "nextcloud": this._("#nextcloud-file-picker").directoryPath}; + + } else { + data = {"source": this.activeSource}; + } + const event = new CustomEvent("dbp-file-source-switched", { "detail": data, bubbles: true, composed: true }); + this.dispatchEvent(event); + } + checkFileType(file) { // check if file is allowed const [fileMainType, fileSubType] = file.type.split('/'); @@ -335,9 +355,18 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { this._('#nextcloud-file-picker').selectAllButton = true;} }); } + + + //check if default source is set + if (this.defaultSink !== '' && this.firstOpen) { + this.activeDestination = this.defaultSink; + this.nextcloudDir = this.nextcloudDefaultDir; + this.firstOpen = false; + } } closeDialog() { + this.sendSource(); this._('#nextcloud-file-picker').selectAllButton = true; MicroModal.close(this._('#modal-picker')); }