diff --git a/packages/file-handling/README.md b/packages/file-handling/README.md index 0638929cb2376680def6f42b464e7c54ae5c131c..8ff1f61faed58167cf8352203ae46ec00245eff6 100644 --- a/packages/file-handling/README.md +++ b/packages/file-handling/README.md @@ -22,6 +22,10 @@ files from a [Nextcloud](https://nextcloud.com/) instance. - example `<vpu-file-source allowed-mime-types='image/*'></vpu-file-source>` ... images (of all sub types) only - example `<vpu-file-source allowed-mime-types='image/png,text/plain'></vpu-file-source>` ... PNGs or TXTs only - example `<vpu-file-source allowed-mime-types='*/*'></vpu-file-source>` ... all file types (default) +- `enabled-sources` (optional): sets which sources are enabled + - you can use `local` and `nextcloud` + - default is `local` + - example `<vpu-file-source enabled-sources='local,nextcloud'></vpu-file-source>` - `disabled` (optional): disable input control - example `<vpu-file-source disabled></vpu-file-source>` - `decompress-zip` (optional): decompress zip file and send the contained files (including files in folders) diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js index c6cf55423b4437b8beac7676f585cc1f758eae49..028047a586e9586954b12d36d7f2f7ee584b6488 100644 --- a/packages/file-handling/src/file-source.js +++ b/packages/file-handling/src/file-source.js @@ -38,6 +38,7 @@ export class FileSource extends ScopedElementsMixin(VPULitElement) { this.nextcloudWebDavUrl = ''; this.dropArea = null; this.allowedMimeTypes = '*/*'; + this.enabledSources = 'local'; this.text = ''; this.buttonLabel = ''; this.disabled = false; @@ -62,6 +63,7 @@ export class FileSource extends ScopedElementsMixin(VPULitElement) { return { lang: { type: String }, allowedMimeTypes: { type: String, attribute: 'allowed-mime-types' }, + enabledSources: { type: String, attribute: 'enabled-sources' }, nextcloudAuthUrl: { type: String, attribute: 'nextcloud-auth-url' }, nextcloudWebDavUrl: { type: String, attribute: 'nextcloud-web-dav-url' }, text: { type: String }, @@ -80,6 +82,11 @@ export class FileSource extends ScopedElementsMixin(VPULitElement) { case "lang": i18n.changeLanguage(this.lang); break; + case "enabledSources": + if (!this.hasEnabledSource(this.activeSource)) { + this.activeSource = this.enabledSources.split(",")[0]; + } + break; case "isDialogOpen": if (this.isDialogOpen) { // this.setAttribute("dialog-open", ""); @@ -219,6 +226,12 @@ export class FileSource extends ScopedElementsMixin(VPULitElement) { return true; } + hasEnabledSource(source) { + const enabledSources = this.enabledSources.split(','); + + return enabledSources.includes(source); + } + /** * Decompress files synchronously * @@ -515,12 +528,12 @@ export class FileSource extends ScopedElementsMixin(VPULitElement) { <nav class="modal-nav"> <div title="${i18n.t('file-source.nav-local')}" @click="${() => { this.activeSource = "local"; }}" - class="${classMap({"active": this.activeSource === "local"})}"> + class="${classMap({"active": this.activeSource === "local", hidden: !this.hasEnabledSource("local")})}"> <vpu-icon class="nav-icon" name="laptop"></vpu-icon> </div> <div title="Nextcloud" @click="${() => { this.activeSource = "nextcloud"; }}" - class="${classMap({"active": this.activeSource === "nextcloud", hidden: this.nextcloudWebDavUrl === "" || this.nextcloudAuthUrl === ""})}"> + class="${classMap({"active": this.activeSource === "nextcloud", hidden: !this.hasEnabledSource("nextcloud")})}"> <vpu-icon class="nav-icon" name="cloud"></vpu-icon> </div> </nav>