From 4b1596e4c6ab76a9adf9f511aa51f7ca8bd9f17d Mon Sep 17 00:00:00 2001 From: Vanessa Pertsch Date: Wed, 11 May 2022 12:11:14 +0200 Subject: [PATCH 1/6] enable opening a single shared file Signed-off-by: Vanessa Pertsch --- src/utils/fileUtils.js | 14 +++++++++++++- src/views/Viewer.vue | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/utils/fileUtils.js b/src/utils/fileUtils.js index 74ac05730..7016eadd4 100644 --- a/src/utils/fileUtils.js +++ b/src/utils/fileUtils.js @@ -56,6 +56,18 @@ const extractFilePaths = function(path) { return [dirPath, fileName] } +/** + * A single shared file can be opend with path: '/'. + * In this case there is no parent folder to find sibling files in. + * + * @param {string} path the full path + * @return {boolean} + */ +const isSingleSharedFile = function(path) { + + return path === '/' +} + /** * Sorting comparison function * @@ -141,4 +153,4 @@ const getDavPath = function({ filename, basename }) { return getRootPath() + encodeFilePath(filename) } -export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo, getDavPath } +export { encodeFilePath, extractFilePaths, isSingleSharedFile, sortCompare, genFileInfo, getDavPath } diff --git a/src/views/Viewer.vue b/src/views/Viewer.vue index a726d8709..9fdf962d3 100644 --- a/src/views/Viewer.vue +++ b/src/views/Viewer.vue @@ -141,7 +141,7 @@ import NcModal from '@nextcloud/vue/dist/Components/NcModal.js' import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js' import isMobile from '@nextcloud/vue/dist/Mixins/isMobile' -import { extractFilePaths, sortCompare } from '../utils/fileUtils.js' +import { extractFilePaths, isSingleSharedFile, sortCompare } from '../utils/fileUtils.js' import { getRootPath } from '../utils/davUtils.js' import canDownload from '../utils/canDownload.js' import cancelableRequest from '../utils/CancelableRequest.js' @@ -508,7 +508,7 @@ export default { // store current position this.currentIndex = this.fileList.findIndex(file => file.basename === fileInfo.basename) - } else if (group) { + } else if (group && !isSingleSharedFile(path)) { const mimes = this.mimeGroups[group] ? this.mimeGroups[group] : [mime] From 8c584371387de4d6988c84afde81d6b637bf10d7 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 16 May 2022 13:44:36 +0200 Subject: [PATCH 2/6] render viewer content in element instead of modal Signed-off-by: Max --- src/services/Viewer.js | 38 +++++++++++++++++++++++++++++++------ src/utils/fileUtils.js | 14 +------------- src/views/Viewer.vue | 43 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 73 insertions(+), 22 deletions(-) diff --git a/src/services/Viewer.js b/src/services/Viewer.js index b56f79ffd..9ed09fc2f 100644 --- a/src/services/Viewer.js +++ b/src/services/Viewer.js @@ -47,6 +47,7 @@ export default class Viewer { this._state.file = '' this._state.fileInfo = null this._state.files = [] + this._state.el = null this._state.loadMore = () => ([]) this._state.onPrev = () => {} this._state.onNext = () => {} @@ -114,6 +115,16 @@ export default class Viewer { return this._state.files } + /** + * Get the element to render the current file in + * + * @memberof Viewer + * @return {string} selector of the element + */ + get el() { + return this._state.el + } + /** * Get the supported mimetypes that can be opened with the viewer * @@ -183,6 +194,19 @@ export default class Viewer { return this._state.overrideHandlerId } + /** + * Set element to open viewer in + * + * @memberof Viewer + * @param {string} el selector of the element to render the file in + */ + setRootElement(el = null) { + if (this._state.file) { + throw new Error('Please set root element before calling Viewer.open().') + } + this._state.el = el + } + /** * Open the path into the viewer * @@ -223,12 +247,14 @@ export default class Viewer { } else { this._state.fileInfo = fileInfo } - this._state.files = list - this._state.loadMore = loadMore - this._state.onPrev = onPrev - this._state.onNext = onNext - this._state.onClose = onClose - this._state.canLoop = canLoop + if (!this._state.el) { + this._state.files = list + this._state.loadMore = loadMore + this._state.onPrev = onPrev + this._state.onNext = onNext + this._state.onClose = onClose + this._state.canLoop = canLoop + } } /** diff --git a/src/utils/fileUtils.js b/src/utils/fileUtils.js index 7016eadd4..74ac05730 100644 --- a/src/utils/fileUtils.js +++ b/src/utils/fileUtils.js @@ -56,18 +56,6 @@ const extractFilePaths = function(path) { return [dirPath, fileName] } -/** - * A single shared file can be opend with path: '/'. - * In this case there is no parent folder to find sibling files in. - * - * @param {string} path the full path - * @return {boolean} - */ -const isSingleSharedFile = function(path) { - - return path === '/' -} - /** * Sorting comparison function * @@ -153,4 +141,4 @@ const getDavPath = function({ filename, basename }) { return getRootPath() + encodeFilePath(filename) } -export { encodeFilePath, extractFilePaths, isSingleSharedFile, sortCompare, genFileInfo, getDavPath } +export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo, getDavPath } diff --git a/src/views/Viewer.vue b/src/views/Viewer.vue index 9fdf962d3..df9f7a3ef 100644 --- a/src/views/Viewer.vue +++ b/src/views/Viewer.vue @@ -22,7 +22,24 @@ -->