2023-10-16 18:08:23 +00:00
|
|
|
import Router, { Route, RouteConfig } from 'vue-router';
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
2023-04-19 23:14:30 +00:00
|
|
|
import { generateUrl } from '@nextcloud/router';
|
2023-10-16 18:08:23 +00:00
|
|
|
|
2023-10-29 21:10:56 +00:00
|
|
|
import Timeline from '@components/Timeline.vue';
|
|
|
|
import Explore from '@components/Explore.vue';
|
|
|
|
import SplitTimeline from '@components/SplitTimeline.vue';
|
|
|
|
import ClusterView from '@components/ClusterView.vue';
|
|
|
|
import NativeXSetup from '@native/Setup.vue';
|
2022-08-16 01:12:14 +00:00
|
|
|
|
2023-10-29 21:10:56 +00:00
|
|
|
import { translate as t } from '@services/l10n';
|
|
|
|
import { constants as c } from '@services/utils';
|
2023-10-16 18:08:23 +00:00
|
|
|
|
|
|
|
// Routes are defined here
|
|
|
|
export type RouteId =
|
|
|
|
| 'Base'
|
|
|
|
| 'Folders'
|
|
|
|
| 'Favorites'
|
|
|
|
| 'Videos'
|
|
|
|
| 'Albums'
|
|
|
|
| 'Archive'
|
|
|
|
| 'ThisDay'
|
|
|
|
| 'Recognize'
|
|
|
|
| 'FaceRecognition'
|
|
|
|
| 'Places'
|
|
|
|
| 'Tags'
|
|
|
|
| 'FolderShare'
|
|
|
|
| 'AlbumShare'
|
|
|
|
| 'Map'
|
|
|
|
| 'Explore'
|
|
|
|
| 'NxSetup';
|
|
|
|
|
2023-10-16 19:42:18 +00:00
|
|
|
export const routes: { [key in RouteId]: RouteConfig } = {
|
2023-10-16 18:08:23 +00:00
|
|
|
Base: {
|
|
|
|
path: '/',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'timeline',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Timeline') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Folders: {
|
|
|
|
path: '/folders/:path*',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'folders',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Folders') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Favorites: {
|
|
|
|
path: '/favorites',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'favorites',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Favorites') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Videos: {
|
|
|
|
path: '/videos',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'videos',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Videos') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Albums: {
|
|
|
|
path: '/albums/:user?/:name?',
|
|
|
|
component: ClusterView,
|
|
|
|
name: 'albums',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Albums') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Archive: {
|
|
|
|
path: '/archive',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'archive',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Archive') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
ThisDay: {
|
|
|
|
path: '/thisday',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'thisday',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'On this day') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Recognize: {
|
|
|
|
path: '/recognize/:user?/:name?',
|
|
|
|
component: ClusterView,
|
|
|
|
name: 'recognize',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'People') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
FaceRecognition: {
|
|
|
|
path: '/facerecognition/:user?/:name?',
|
|
|
|
component: ClusterView,
|
|
|
|
name: 'facerecognition',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'People') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Places: {
|
|
|
|
path: '/places/:name*',
|
|
|
|
component: ClusterView,
|
|
|
|
name: 'places',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Places') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Tags: {
|
|
|
|
path: '/tags/:name*',
|
|
|
|
component: ClusterView,
|
|
|
|
name: 'tags',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Tags') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
FolderShare: {
|
2023-10-19 19:12:26 +00:00
|
|
|
path: '/s/:token/:path*',
|
2023-10-16 18:08:23 +00:00
|
|
|
component: Timeline,
|
|
|
|
name: 'folder-share',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Shared Folder') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
AlbumShare: {
|
|
|
|
path: '/a/:token',
|
|
|
|
component: Timeline,
|
|
|
|
name: 'album-share',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Shared Album') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Map: {
|
|
|
|
path: '/map',
|
|
|
|
component: SplitTimeline,
|
|
|
|
name: 'map',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Map') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
Explore: {
|
|
|
|
path: '/explore',
|
|
|
|
component: Explore,
|
|
|
|
name: 'explore',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Explore') }),
|
|
|
|
},
|
|
|
|
|
|
|
|
NxSetup: {
|
|
|
|
path: '/nxsetup',
|
|
|
|
component: NativeXSetup,
|
|
|
|
name: 'nxsetup',
|
|
|
|
props: (route: Route) => ({ rootTitle: t('memories', 'Setup') }),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-10-28 19:08:34 +00:00
|
|
|
Vue.use(Router);
|
2022-08-16 01:12:14 +00:00
|
|
|
|
2022-10-28 19:08:34 +00:00
|
|
|
export default new Router({
|
2023-04-19 23:14:30 +00:00
|
|
|
mode: 'history',
|
2022-10-28 19:08:34 +00:00
|
|
|
// if index.php is in the url AND we got this far, then it's working:
|
|
|
|
// let's keep using index.php in the url
|
2023-04-19 23:14:30 +00:00
|
|
|
base: generateUrl('/apps/memories'),
|
|
|
|
linkActiveClass: 'active',
|
2023-10-16 18:08:23 +00:00
|
|
|
routes: Object.values(routes),
|
2022-10-28 19:08:34 +00:00
|
|
|
});
|
2023-10-16 18:08:23 +00:00
|
|
|
|
|
|
|
// Define global route checkers
|
|
|
|
// Injected through globals.d.ts
|
|
|
|
export type GlobalRouteCheckers = {
|
|
|
|
[key in `routeIs${RouteId}`]: boolean;
|
|
|
|
} & {
|
|
|
|
// Extra, special route checkers
|
|
|
|
routeIsPublic: boolean;
|
|
|
|
routeIsPeople: boolean;
|
|
|
|
routeIsRecognizeUnassigned: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implement getters for route checkers
|
|
|
|
function defineRouteChecker(key: keyof GlobalRouteCheckers, condition: (route?: Route) => boolean) {
|
|
|
|
Object.defineProperty(Vue.prototype, key, {
|
|
|
|
get() {
|
|
|
|
return condition(this.$route);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:42:18 +00:00
|
|
|
// Build basic route checkers
|
2023-10-16 18:08:23 +00:00
|
|
|
for (const [key, value] of Object.entries(routes)) {
|
|
|
|
defineRouteChecker(`routeIs${<keyof typeof routes>key}`, (route) => route?.name === value.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra route checkers
|
|
|
|
defineRouteChecker('routeIsPublic', (route) => route?.name?.endsWith('-share') ?? false);
|
2023-10-16 19:42:18 +00:00
|
|
|
defineRouteChecker('routeIsPeople', (route) =>
|
|
|
|
[routes.Recognize.name, routes.FaceRecognition.name].includes(route?.name ?? ''),
|
|
|
|
);
|
2023-10-16 18:08:23 +00:00
|
|
|
defineRouteChecker(
|
|
|
|
'routeIsRecognizeUnassigned',
|
2023-10-16 19:42:18 +00:00
|
|
|
(route) => route?.name === routes.Recognize.name && route!.params.name === c.FACE_NULL,
|
2023-10-16 18:08:23 +00:00
|
|
|
);
|