forked from kumahq/kuma-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
281 lines (266 loc) · 7.09 KB
/
router.js
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
export default (store) => {
const routes = [
{
path: '/404',
name: 'not-found',
alias: '*',
meta: {
title: 'Page not found',
excludeAsBreadcrumb: true
},
component: () => import('@/views/NotFound')
},
{
path: '/',
redirect: { name: 'global-overview' }
},
// Onboarding
{
path: '/get-started',
redirect: { name: 'setup-welcome' },
component: () => import('@/views/ShellEmpty'),
children: [
{
path: 'welcome',
name: 'setup-welcome',
meta: {
title: 'Welcome to Kuma!',
excludeAsBreadcrumb: true,
hideSidebar: true,
hideStatus: true,
simpleHeader: true,
simpleContent: true,
onboardingProcess: true
},
component: () => import('@/views/Onboarding/GetStarted')
},
{
path: 'complete',
name: 'setup-complete',
meta: {
title: 'Congratulations!',
excludeAsBreadcrumb: true,
hideSidebar: true,
hideStatus: true,
simpleHeader: true,
simpleContent: true,
onboardingProcess: true
},
component: () => import('@/views/Onboarding/Complete')
}
]
},
{
// Entity Wizard
path: '/wizard',
name: 'wizard',
component: () => import('@/views/Shell'),
children: [
{
path: 'mesh',
name: 'create-mesh',
meta: {
title: 'Create a new Mesh',
excludeAsBreadcrumb: true
},
component: () => import('@/views/Wizard/views/Mesh')
}
]
},
// App
// meshes
{
path: '/overview',
alias: '/',
name: 'global-overview',
component: () => import('@/views/Overview'),
meta: {
title: 'Global Overview',
breadcrumb: 'Overview'
}
},
// all Meshes
{
path: '/meshes',
name: 'all-meshes',
meta: {
title: 'Meshes',
breadcrumb: 'Meshes',
parent: 'global-overview'
},
params: { mesh: ':mesh' },
component: () => import('@/views/Shell'),
children: [
{
path: ':mesh',
name: 'mesh-child',
meta: {
title: 'Mesh Overview',
parent: 'all-meshes'
},
params: { mesh: ':mesh' },
component: () => import('@/views/Entities/Meshes')
}
]
},
{
path: '/:mesh',
name: 'mesh',
meta: {
title: 'Meshes',
breadcrumb: 'Meshes',
parent: 'mesh-overview'
},
params: { mesh: ':mesh' },
component: () => import('@/views/Shell'),
children: [
// dataplanes
{
path: 'dataplanes',
name: 'dataplanes',
meta: {
title: 'Dataplanes',
parent: 'dataplanes'
},
component: () => import('@/views/Entities/Dataplanes')
},
// traffic permissions
{
path: 'traffic-permissions',
name: 'traffic-permissions',
meta: {
title: 'Traffic Permissions'
},
component: () => import('@/views/Policies/TrafficPermissions')
},
// traffic routes
{
path: 'traffic-routes',
name: 'traffic-routes',
meta: {
title: 'Traffic Routes'
},
component: () => import('@/views/Policies/TrafficRoutes')
},
// traffic logs
{
path: 'traffic-logs',
name: 'traffic-logs',
meta: {
title: 'Traffic Logs'
},
component: () => import('@/views/Policies/TrafficLogs')
},
// traffic traces
{
path: 'traffic-traces',
name: 'traffic-traces',
meta: {
title: 'Traffic Traces'
},
component: () => import('@/views/Policies/TrafficTraces')
},
// fault injections
{
path: 'fault-injections',
name: 'fault-injections',
meta: {
title: 'Fault Injections'
},
component: () => import('@/views/Policies/FaultInjections')
},
// health checks
{
path: 'health-checks',
name: 'health-checks',
meta: {
title: 'Health Checks'
},
component: () => import('@/views/Policies/HealthChecks')
},
// proxy templates
{
path: 'proxy-templates',
name: 'proxy-templates',
meta: {
title: 'Proxy Templates'
},
component: () => import('@/views/Policies/ProxyTemplates')
}
]
}
]
const router = new VueRouter({
/**
* Defaulting to hash mode since this runs within Kuma itself
* and it's easier to avoid having to do advanced server config
* simply for hash-free URLs.
*/
// mode: 'history',
base: process.env.BASE_URL,
routes: routes
})
// Set $router.previous on each route
router.beforeResolve((to, from, next) => {
router.previous = from
next()
})
/**
* This will make sure that the Meshes page displays all meshes
* if the user happens to go to the bare `/meshes` url with no
* query on the end of it.
*/
router.beforeEach((to, from, next) => {
if (to.name === 'all-meshes') {
next({
name: 'mesh-child',
params: { mesh: 'all' }
})
} else {
next()
}
})
/**
* A route guard for handling the onboarding process. If the user hasn't gone
* through the setup/onboarding process yet, this sends them through it. Once
* completed, a localStorage value is set to true so that they're not sent
* through it again.
*/
router.beforeEach((to, from, next) => {
const hasOnboarded = JSON.parse(localStorage.getItem('kumaOnboardingComplete') || null)
const currentRoute = to.meta.onboardingProcess
if ((!hasOnboarded || hasOnboarded === false) && !currentRoute) {
next({ name: 'setup-welcome' })
} else {
next()
}
})
/**
* Navigate up URL hierarchy
*
* @param {Number} levels - number of url directories to jump up e.g. if
* "/consumers/123/update" is currentRoute, then levels = 2 would return
* "/consumers"
* @param {Boolean} redirect - if true, this will perform a redirect
* @returns {String} returns the path of the path calculation
*/
router.navigateUp = function (levels = 1, redirect = true) {
var upperPath = this.currentRoute.path.split('/')
if (upperPath.length >= levels) {
upperPath.splice(upperPath.length - levels)
const path = upperPath.join('/')
redirect && this.push({ path })
return path
}
}
router.onReady(() => {
store.commit('SET_GLOBAL_LOADING', { globalLoading: true })
setTimeout(() => {
store.commit('SET_GLOBAL_LOADING', { globalLoading: false })
}, 1000)
})
return router
}