Allow setting folder base path (close #85)

old-stable24
Varun Patil 2022-10-19 12:26:32 -07:00
parent c79b2d84b3
commit 2496046d56
5 changed files with 36 additions and 13 deletions

View File

@ -67,6 +67,12 @@ class PageController extends Controller
$uid = $user->getUid(); $uid = $user->getUid();
$timelinePath = \OCA\Memories\Util::getPhotosPath($this->config, $uid); $timelinePath = \OCA\Memories\Util::getPhotosPath($this->config, $uid);
$this->initialState->provideInitialState('timelinePath', $timelinePath); $this->initialState->provideInitialState('timelinePath', $timelinePath);
$this->initialState->provideInitialState('foldersPath', $this->config->getUserValue(
$uid,
Application::APPNAME,
'foldersPath',
'/'
));
$this->initialState->provideInitialState('showHidden', $this->config->getUserValue( $this->initialState->provideInitialState('showHidden', $this->config->getUserValue(
$uid, $uid,
Application::APPNAME, Application::APPNAME,

View File

@ -27,6 +27,11 @@
v-model="config_timelinePath" v-model="config_timelinePath"
type="text"> type="text">
<label for="folders-path">{{ t('memories', 'Folders Path') }}</label>
<input id="folders-path"
v-model="config_foldersPath"
type="text">
<NcCheckboxRadioSwitch :checked.sync="config_showHidden" <NcCheckboxRadioSwitch :checked.sync="config_showHidden"
type="switch"> type="switch">
{{ t('memories', 'Show hidden folders') }} {{ t('memories', 'Show hidden folders') }}
@ -68,13 +73,16 @@ export default class Settings extends Mixins(UserConfig, GlobalMixin) {
// Update localStorage // Update localStorage
localStorage.setItem('memories_squareThumbs', this.config_squareThumbs ? '1' : '0'); localStorage.setItem('memories_squareThumbs', this.config_squareThumbs ? '1' : '0');
// Update remote // Settings list
await this.updateSetting('showHidden'); const settings = ['showHidden', 'timelinePath', 'foldersPath'];
const res = await this.updateSetting('timelinePath');
if (res.status === 200) { // Update all
window.location.reload(); const p = await Promise.all(settings.map(async (setting) => this.updateSetting(setting)));
} else {
if (p.some((r) => !r || r.status !== 200)) {
showError(this.t('memories', 'Error updating settings')); showError(this.t('memories', 'Error updating settings'));
} else {
window.location.reload();
} }
} }
} }

View File

@ -431,7 +431,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
// Folder // Folder
if (this.$route.name === 'folders') { 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('/'); path = typeof path === 'string' ? path : path.join('/');
query.set('folder', path); query.set('folder', path);
} }

View File

@ -27,6 +27,7 @@
import { Component, Prop, Watch, Mixins } from 'vue-property-decorator'; import { Component, Prop, Watch, Mixins } from 'vue-property-decorator';
import { IFileInfo, IFolder } from '../../types'; import { IFileInfo, IFolder } from '../../types';
import GlobalMixin from '../../mixins/GlobalMixin'; import GlobalMixin from '../../mixins/GlobalMixin';
import UserConfig from '../../mixins/UserConfig';
import * as dav from "../../services/DavRequests"; import * as dav from "../../services/DavRequests";
import { getPreviewUrl } from "../../services/FileUtils"; import { getPreviewUrl } from "../../services/FileUtils";
@ -38,7 +39,7 @@ import FolderIcon from 'vue-material-design-icons/Folder.vue';
FolderIcon, FolderIcon,
}, },
}) })
export default class Folder extends Mixins(GlobalMixin) { export default class Folder extends Mixins(GlobalMixin, UserConfig) {
@Prop() data: IFolder; @Prop() data: IFolder;
// Separate property because the one on data isn't reactive // Separate property because the one on data isn't reactive
@ -96,8 +97,15 @@ export default class Folder extends Mixins(GlobalMixin) {
/** Open folder */ /** Open folder */
openFolder(folder: IFolder) { openFolder(folder: IFolder) {
const path = folder.path.split('/').filter(x => x).slice(2) as any; const path = folder.path.split('/').filter(x => x).slice(2) as string[];
this.$router.push({ name: 'folders', params: { path }});
// 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 }});
} }
} }
</script> </script>

View File

@ -30,10 +30,11 @@ const eventName = 'memories:user-config-changed'
@Component @Component
export default class UserConfig extends Vue { 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_showHidden = loadState('memories', 'showHidden') === "true";
config_tagsEnabled = loadState('memories', 'systemtags'); config_tagsEnabled = Boolean(loadState('memories', 'systemtags'));
config_recognizeEnabled = loadState('memories', 'recognize'); config_recognizeEnabled = Boolean(loadState('memories', 'recognize'));
config_squareThumbs = localStorage.getItem('memories_squareThumbs') === '1'; config_squareThumbs = localStorage.getItem('memories_squareThumbs') === '1';
config_showFaceRect = localStorage.getItem('memories_showFaceRect') === '1'; config_showFaceRect = localStorage.getItem('memories_showFaceRect') === '1';