diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js index 56bb422b1aab1e27c1afdc2d7b51cf9ca067d9eb..9b5f3c2151cf0c0fe7e9debf1e6535ae14bdb939 100644 --- a/packages/file-handling/src/file-sink.js +++ b/packages/file-handling/src/file-sink.js @@ -305,6 +305,7 @@ export class FileSink extends ScopedElementsMixin(DbpFileHandlingLitElement) { nextcloud-file-url="${this.nextcloudFileURL}" ?show-nextcloud-additional-menu="${this.showNextcloudAdditionalMenu}" store-nextcloud-session="true" + ?show-nextcloud-additional-menu="${this.showNextcloudAdditionalMenu}" @dbp-nextcloud-file-picker-file-uploaded="${(event) => { this.uploadToNextcloud(event.detail); }}" diff --git a/packages/file-handling/src/i18n/de/translation.json b/packages/file-handling/src/i18n/de/translation.json index 863c4ef461dbf2f311c113880bef64def4752452..defe21edd06d51ac3014f44cf5f333f9fd3392fc 100644 --- a/packages/file-handling/src/i18n/de/translation.json +++ b/packages/file-handling/src/i18n/de/translation.json @@ -77,7 +77,11 @@ "favorites-link-text": "Meine Favoriten", "remember-me": "Mit {{name}} verbunden bleiben", "log-out": "Verbindung trennen", - "open-submenu": "Untermenü öffnen" + "open-submenu": "Untermenü öffnen", + "error-save-to-favorites": "Speichern in Favoriten nicht möglich! Bitte wählen Sie einen Ordner innerhalb der Favoriten aus.", + "error-save-to-recent": "Speichern in den neuesten Dateien nicht möglich! Bitte wählen Sie einen Ordner innerhalb der neuesten Dateien aus.", + "recent-files-link-text": "Neueste Dateien", + "favorites-link-text": "Meine Favoriten" }, "clipboard": { "add-files": "Dateien der Zwischenablage hinzufügen", diff --git a/packages/file-handling/src/i18n/en/translation.json b/packages/file-handling/src/i18n/en/translation.json index 0bc4701803a1a0fa8ad26e223502546ae06701b0..e0d0be3f3c2881cff599ed319b3c1ce880474625 100644 --- a/packages/file-handling/src/i18n/en/translation.json +++ b/packages/file-handling/src/i18n/en/translation.json @@ -78,7 +78,11 @@ "favorites-link-text": "My Favorites", "remember-me": "Stay connected with {{name}}", "log-out": "Disconnect", - "open-submenu": "Open submenu" + "open-submenu": "Open submenu", + "error-save-to-favorites": "Saving to Favorites not possible! Please select a folder within the Favorites.", + "error-save-to-recent": "Saving to Recent Files not possible! Please select a folder within the Recent Files.", + "recent-files-link-text": "Recent Files", + "favorites-link-text": "My Favorites" }, "clipboard": { "add-files": "Add files to clipboard", diff --git a/packages/file-handling/src/nextcloud-file-picker.js b/packages/file-handling/src/nextcloud-file-picker.js index 672c6182ba418454ad248ad292ea91a142a646b9..aadf95ed4e13d2dfff96ddf8e38fd68392b8f2a8 100644 --- a/packages/file-handling/src/nextcloud-file-picker.js +++ b/packages/file-handling/src/nextcloud-file-picker.js @@ -58,14 +58,14 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { this.abortUpload = false; this.authInfo = ''; this.selectBtnDisabled = true; - this.showAdditionalMenu = false; - this.isInFavorites = false; - this.isInRecent = false; - this.userName = ''; this.storeSession = false; this.showSubmenu = false; this.bounCloseSubmenuHandler = this.closeSubmenu.bind(this); this.initateOpensubmenu = false; + this.showAdditionalMenu = false; + this.isInFavorites = false; + this.isInRecent = false; + this.userName = ''; } static get scopedElements() { @@ -106,7 +106,9 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { showAdditionalMenu: { type: Boolean, attribute: 'show-nextcloud-additional-menu' }, userName: { type: Boolean, attribute: false }, storeSession: {type: Boolean, attribute: 'store-nextcloud-session'}, - showSubmenu: {type: Boolean, attribute: false} + showSubmenu: {type: Boolean, attribute: false}, + showAdditionalMenu: { type: Boolean, attribute: 'show-nextcloud-additional-menu' }, + userName: { type: Boolean, attribute: false }, }; } @@ -566,6 +568,74 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { return result; } + /** + * + * @param {*} path + * @returns array including file path and base name + */ + parseFileAndBaseName(path) { + if (path[0] !== "/") { //TODO verify + path = "/" + path; + } + while (/^.+\/$/.test(path)) { + path = path.substr(0, path.length - 1); + } + path = decodeURIComponent(path); + + let array1 = this.webDavUrl.split('/'); + let array2 = path.split('/'); + for (let i = 0; i < array2.length; i++) { + let item2 = array2[i]; + array1.forEach(item1 => { + if (item1 === item2) { + array2.shift(); + i--; + } + }); + } + array2.shift(); + + let basename = array2[array2.length - 1]; + let filename = '/' + array2.join('/'); + + return [ filename, basename ]; + } + + /** + * + * @param {*} response + * @returns list of file objects containing corresponding information + */ + mapResponseToObject(response) { + let results = []; + + response.forEach(item => { + const [ filePath, baseName ] = this.parseFileAndBaseName(item.href); + + const prop = item.propstat.prop; + let etag = typeof prop.getetag === 'string' ? prop.getetag.replace(/"/g, '') : null; + let sizeVal = prop.getcontentlength ? prop.getcontentlength : '0'; + let fileType = prop.resourcetype && typeof prop.resourcetype === 'object' && typeof prop.resourcetype.collection !== 'undefined' ? 'directory' : 'file'; + + let mimeType; + if (fileType === 'file') { + mimeType = prop.getcontenttype && typeof prop.getcontenttype === 'string' ? prop.getcontenttype.split(';')[0] : ''; + } + + let propsObject = { getetag: etag, getlastmodified: prop.getlastmodified, getcontentlength: sizeVal, + permissions: prop.permissions, resourcetype: fileType, getcontenttype: prop.getcontenttype }; + + let statObject = { basename: baseName, etag: etag, filename: filePath, lastmod: prop.getlastmodified, + mime: mimeType, props: propsObject, size: parseInt(sizeVal, 10), type: fileType }; + + results.push(statObject); + }); + + return results; + } + + + /** * * @param {*} path @@ -2291,6 +2361,9 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { <dbp-icon name="checkmark-circle" class="nextcloud-add-folder"></dbp-icon> </button> </div> + + <!-- TODO begin --> + <!-- <div class="menu-buttons"> <div class="add-folder ${classMap({hidden: !this.directoriesOnly})}"> <div class="inline-block"> @@ -2304,10 +2377,52 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { this.addFolder(); }}"> <dbp-icon name="checkmark-circle" class="nextcloud-add-folder"></dbp-icon> + </button> </div> --> <!-- TODO end --> +<!-- + <div class="additional-menu ${classMap({hidden: !this.showAdditionalMenu})}"> + + <a class="extended-menu-link" @click="${() => { this.toggleMoreMenu(); }}" title="${i18n.t('nextcloud-file-picker.more-menu')}"> + <dbp-icon name="more-filled" class="more-menu"></dbp-icon> + </a> + <ul class='extended-menu hidden'> + <li class="${classMap({active: this.isInFavorites})}" id="favorites-item"> + <a class="" @click="${this.loadFavorites}"> + ${i18n.t('nextcloud-file-picker.favorites-link-text')} + </a> + </li> + <li class="${classMap({active: this.isInRecent})}" id="recent-item"> + <a class="" @click="${this.loadRecent}"> + ${i18n.t('nextcloud-file-picker.recent-files-link-text')} + </a> + </li> + <li class="${classMap({hidden: !this.directoriesOnly})}"> + <a class="${classMap({inactive: this.isInRecent || this.isInFavorites})}" @click="${() => { this.openAddFolderDialogue(); }}"> + ${i18n.t('nextcloud-file-picker.add-folder')} + </a> + </li> + + <div class="inline-block"> + <div id="new-folder-wrapper" class="hidden"> + <input type="text" + placeholder="${i18n.t('nextcloud-file-picker.new-folder-placeholder')}" + name="new-folder" class="input" id="new-folder"/> + <button class="button add-folder-button" + title="${i18n.t('nextcloud-file-picker.add-folder')}" + @click="${() => { + this.addFolder(); + }}"> + <dbp-icon name="checkmark-circle" class="nextcloud-add-folder"></dbp-icon> + </button> + </div> +--> + <!-- TODO end --> +<!-- + </div> +--> <!-- <button class="button ${classMap({hidden: this.showAdditionalMenu})}" title="${i18n.t('nextcloud-file-picker.add-folder-open')}" @click="${() => { @@ -2315,6 +2430,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { }}"> <dbp-icon name="plus" class="nextcloud-add-folder" id="add-folder-button"></dbp-icon> </button> --> +<!-- <li class="close" @click="${this.hideMoreMenu}"><dbp-icon name="close" style="color: red"></dbp-icon></li> </ul> @@ -2336,7 +2452,8 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { </div> </div> </div> - </div> + </div> +--> <div class="filter-options-wrapper ${classMap({hidden: !this.isInRecent})}"> <label id="user_files_only_wrapper" class="button-container"> <!-- ${i18n.t('nextcloud-file-picker.replace-mode-all')} --> Show only my files <!--TODO-->