Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « router « src - github.com/nextcloud/photos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8c6457bf5de94963f5c9f9b92a073b47d4a366b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
 * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @author John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @license AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import { generateUrl } from '@nextcloud/router'
import Router from 'vue-router'
import Vue from 'vue'

import isMapsInstalled from '../services/IsMapsInstalled.js'
import areTagsInstalled from '../services/AreTagsInstalled.js'
import { imageMimes, videoMimes } from '../services/AllowedMimes.js'

import isRecognizeInstalled from '../services/IsRecognizeInstalled.js'

const Folders = () => import('../views/Folders')
const Albums = () => import('../views/Albums')
const AlbumContent = () => import('../views/AlbumContent')
const Tags = () => import('../views/Tags')
const TagContent = () => import('../views/TagContent')
const Timeline = () => import('../views/Timeline')
const Faces = () => import('../views/Faces')
const FaceContent = () => import('../views/FaceContent')

Vue.use(Router)

let mapsPath = generateUrl('/apps/maps')
if (!isMapsInstalled) {
	mapsPath = generateUrl('/settings/apps/integration/maps')
}

/**
 * Parse the path of a route : join the elements of the array and return a single string with slashes
 * + always lead current path with a slash
 *
 * @param {string | Array} path path arguments to parse
 * @return {string}
 */
const parsePathParams = (path) => {
	return `/${Array.isArray(path) ? path.join('/') : path || ''}`
}

const router = new Router({
	mode: 'history',
	// 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
	base: generateUrl('/apps/photos'),
	linkActiveClass: 'active',
	routes: [
		{
			path: '/',
			component: Timeline,
			name: 'all_media',
		},
		{
			path: '/photos',
			component: Timeline,
			name: 'photos',
			props: route => ({
				mimesType: imageMimes,
			}),
		},
		{
			path: '/videos',
			component: Timeline,
			name: 'videos',
			props: route => ({
				mimesType: videoMimes,
			}),
		},
		{
			path: '/albums',
			component: Albums,
			name: 'albums',
		},
		{
			path: '/albums/:albumName*',
			component: AlbumContent,
			name: 'albums',
			props: route => ({
				albumName: route.params.albumName,
			}),
		},
		{
			path: '/folders/:path*',
			component: Folders,
			name: 'folders',
			props: route => ({
				path: parsePathParams(route.params.path),
				// if path is empty
				isRoot: !route.params.path,
				rootTitle: t('photos', 'Folders'),
			}),
		},
		{
			path: '/shared/:path*',
			component: Folders,
			name: 'shared',
			props: route => ({
				path: parsePathParams(route.params.path),
				// if path is empty
				isRoot: !route.params.path,
				rootTitle: t('photos', 'Shared with you'),
				showShared: true,
			}),
		},
		{
			path: '/favorites',
			component: Timeline,
			name: 'favorites',
			props: route => ({
				onlyFavorites: true,
			}),
		},
		{
			path: '/tags/',
			component: Tags,
			name: 'tags',
			redirect: !areTagsInstalled ? { name: 'timeline' } : null,
			props: route => ({
				path: '',
				isRoot: !route.params.path,
				rootTitle: t('photos', 'Tagged photos'),
			}),
		},
		{
			path: '/tags/:path',
			component: TagContent,
			name: 'tagcontent',
			redirect: !areTagsInstalled ? { name: 'timeline' } : null,
			props: route => ({
				path: `${route.params.path ? route.params.path : ''}`,
			}),
		},
		{
			path: '/maps',
			name: 'maps',
			// router-link doesn't support external url, let's force the redirect
			beforeEnter() {
				window.open(mapsPath, '_blank')
			},
		},
		{
			path: '/thisday',
			name: 'thisday',
			component: Timeline,
			props: route => ({
				rootTitle: t('photos', 'On this day'),
				onThisDay: true,
			}),
		},
		{
			path: '/faces',
			name: 'faces',
			component: Faces,
			...((!isRecognizeInstalled) && {
				beforeEnter() {
					const recognizeInstallLink = generateUrl('/settings/apps/installed/recognize')
					window.open(recognizeInstallLink, '_blank')
				},
			}),
		},
		{
			path: '/faces/:faceName',
			name: 'facecontent',
			component: FaceContent,
			props: route => ({
				rootTitle: route.params.faceName,
				faceName: route.params.faceName,
			}),
		},
	],
})

export default router