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();
$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,

View File

@ -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') }}
@ -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();
}
}
}

View File

@ -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);
}

View File

@ -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 }});
}
}
</script>

View File

@ -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';