From 2496046d566cf1e19f4f691e6b4a6173601c0915 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 19 Oct 2022 12:26:32 -0700 Subject: [PATCH] Allow setting folder base path (close #85) --- lib/Controller/PageController.php | 6 ++++++ src/components/Settings.vue | 20 ++++++++++++++------ src/components/Timeline.vue | 2 +- src/components/frame/Folder.vue | 14 +++++++++++--- src/mixins/UserConfig.ts | 7 ++++--- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 9187818fb..d2074e03e 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -67,6 +67,12 @@ public function main() $uid = $user->getUid(); $timelinePath = \OCA\Memories\Util::getPhotosPath($this->config, $uid); $this->initialState->provideInitialState('timelinePath', $timelinePath); + $this->initialState->provideInitialState('foldersPath', $this->config->getUserValue( + $uid, + Application::APPNAME, + 'foldersPath', + '/' + )); $this->initialState->provideInitialState('showHidden', $this->config->getUserValue( $uid, Application::APPNAME, diff --git a/src/components/Settings.vue b/src/components/Settings.vue index 9aed14449..3042b7656 100644 --- a/src/components/Settings.vue +++ b/src/components/Settings.vue @@ -27,6 +27,11 @@ v-model="config_timelinePath" type="text"> + + + {{ t('memories', 'Show hidden folders') }} @@ -68,13 +73,16 @@ export default class Settings extends Mixins(UserConfig, GlobalMixin) { // Update localStorage localStorage.setItem('memories_squareThumbs', this.config_squareThumbs ? '1' : '0'); - // Update remote - await this.updateSetting('showHidden'); - const res = await this.updateSetting('timelinePath'); - if (res.status === 200) { - window.location.reload(); - } else { + // Settings list + const settings = ['showHidden', 'timelinePath', 'foldersPath']; + + // Update all + const p = await Promise.all(settings.map(async (setting) => this.updateSetting(setting))); + + if (p.some((r) => !r || r.status !== 200)) { showError(this.t('memories', 'Error updating settings')); + } else { + window.location.reload(); } } } diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 729e726ce..56093210d 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -431,7 +431,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { // Folder if (this.$route.name === 'folders') { - let path: any = this.$route.params.path || '/'; + let path: any = this.config_foldersPath + (this.$route.params.path || '/'); path = typeof path === 'string' ? path : path.join('/'); query.set('folder', path); } diff --git a/src/components/frame/Folder.vue b/src/components/frame/Folder.vue index 794fc5dcb..ade2070f3 100644 --- a/src/components/frame/Folder.vue +++ b/src/components/frame/Folder.vue @@ -27,6 +27,7 @@ import { Component, Prop, Watch, Mixins } from 'vue-property-decorator'; import { IFileInfo, IFolder } from '../../types'; import GlobalMixin from '../../mixins/GlobalMixin'; +import UserConfig from '../../mixins/UserConfig'; import * as dav from "../../services/DavRequests"; import { getPreviewUrl } from "../../services/FileUtils"; @@ -38,7 +39,7 @@ import FolderIcon from 'vue-material-design-icons/Folder.vue'; FolderIcon, }, }) -export default class Folder extends Mixins(GlobalMixin) { +export default class Folder extends Mixins(GlobalMixin, UserConfig) { @Prop() data: IFolder; // Separate property because the one on data isn't reactive @@ -96,8 +97,15 @@ export default class Folder extends Mixins(GlobalMixin) { /** Open folder */ openFolder(folder: IFolder) { - const path = folder.path.split('/').filter(x => x).slice(2) as any; - this.$router.push({ name: 'folders', params: { path }}); + const path = folder.path.split('/').filter(x => x).slice(2) as string[]; + + // Remove base path if present + const basePath = this.config_foldersPath.split('/').filter(x => x); + if (path.length >= basePath.length && path.slice(0, basePath.length).every((x, i) => x === basePath[i])) { + path.splice(0, basePath.length); + } + + this.$router.push({ name: 'folders', params: { path: path as any }}); } } diff --git a/src/mixins/UserConfig.ts b/src/mixins/UserConfig.ts index 236fe8899..570a84c39 100644 --- a/src/mixins/UserConfig.ts +++ b/src/mixins/UserConfig.ts @@ -30,10 +30,11 @@ const eventName = 'memories:user-config-changed' @Component export default class UserConfig extends Vue { - config_timelinePath = loadState('memories', 'timelinePath') || ''; + config_timelinePath: string = loadState('memories', 'timelinePath') || ''; + config_foldersPath: string = loadState('memories', 'foldersPath') || '/'; config_showHidden = loadState('memories', 'showHidden') === "true"; - config_tagsEnabled = loadState('memories', 'systemtags'); - config_recognizeEnabled = loadState('memories', 'recognize'); + config_tagsEnabled = Boolean(loadState('memories', 'systemtags')); + config_recognizeEnabled = Boolean(loadState('memories', 'recognize')); config_squareThumbs = localStorage.getItem('memories_squareThumbs') === '1'; config_showFaceRect = localStorage.getItem('memories_showFaceRect') === '1';