Skip to content

Commit

Permalink
Allow setting folder base path (close #85)
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Oct 19, 2022
1 parent 0a028ef commit 25d787f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 14 additions & 6 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
v-model="config_timelinePath"
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"
type="switch">
{{ t('memories', 'Show hidden folders') }}
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 11 additions & 3 deletions src/components/frame/Folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -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 }});
}
}
</script>
Expand Down
7 changes: 4 additions & 3 deletions src/mixins/UserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 25d787f

Please sign in to comment.