forked from kumahq/kuma-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
395 lines (377 loc) · 11.3 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
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(/* webpackChunkName: "not-found" */ '@/views/NotFound')
},
// Home - a landing place that resets things
{
path: '/',
name: 'home',
redirect: {
name: 'global-overview',
params: {
mesh: 'all'
}
}
},
// 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(/* webpackChunkName: "onboarding-get-started" */ '@/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(/* webpackChunkName: "onboarding-complete" */ '@/views/Onboarding/Complete')
}
]
},
{
// Entity Wizard
path: '/wizard',
name: 'wizard',
component: () => import(/* webpackChunkName: "shell-default" */ '@/views/Shell'),
children: [
{
path: 'mesh',
name: 'create-mesh',
meta: {
title: 'Create a new Mesh',
excludeAsBreadcrumb: true,
wizardProcess: true
},
component: () => import(/* webpackChunkName: "wizard-mesh" */ '@/views/Wizard/views/Mesh')
},
{
path: 'kubernetes-dataplane',
name: 'kubernetes-dataplane',
meta: {
title: 'Create a new Kubernetes Dataplane',
excludeAsBreadcrumb: true,
wizardProcess: true
},
component: () => import(/* webpackChunkName: "wizard-dataplane-kubernetes" */ '@/views/Wizard/views/DataplaneKubernetes')
},
{
path: 'universal-dataplane',
name: 'universal-dataplane',
meta: {
title: 'Create a new Universal Dataplane',
excludeAsBreadcrumb: true,
wizardProcess: true
},
component: () => import(/* webpackChunkName: "wizard-dataplane-universal" */ '@/views/Wizard/views/DataplaneUniversal')
}
]
},
// App
// diagnostics
{
path: '/diagnostics',
name: 'diagnostics',
component: () => import(/* webpackChunkName: "diagnostics" */ '@/views/Diagnostics'),
meta: {
title: 'Diagnostics',
breadcrumb: 'Diagnostics',
hideSubnav: true
}
},
// Zones
{
path: '/zones',
name: 'zones',
meta: {
title: 'Zones'
},
component: () => import(/* webpackChunkName: "zones" */ '@/views/Entities/Zones')
},
// all Meshes
{
path: '/meshes',
name: 'all-meshes',
meta: {
title: 'Meshes',
breadcrumb: 'Meshes',
parent: 'global-overview'
},
params: { mesh: ':mesh' },
component: () => import(/* webpackChunkName: "shell-default" */ '@/views/Shell'),
children: [
{
path: ':mesh',
name: 'mesh-child',
meta: {
title: 'Mesh Overview',
parent: 'all-meshes'
},
params: { mesh: ':mesh' },
component: () => import(/* webpackChunkName: "meshes" */ '@/views/Entities/Meshes')
}
]
},
{
path: '/:mesh',
name: 'mesh',
meta: {
title: 'Meshes',
breadcrumb: 'Meshes',
parent: 'all-meshes'
},
params: { mesh: ':mesh' },
component: () => import(/* webpackChunkName: "shell-default" */ '@/views/Shell'),
children: [
// overview
{
path: 'overview',
name: 'global-overview',
alias: '/',
meta: {
title: 'Global Overview'
},
component: () => import(/* webpackChunkName: "global-overview" */ '@/views/Overview')
},
// Zones
// {
// path: 'zones',
// name: 'zones',
// meta: {
// title: 'Zones'
// },
// component: () => import(/* webpackChunkName: "zones" */ '@/views/Entities/Zones')
// },
// all dataplanes
{
path: 'dataplanes',
name: 'dataplanes',
meta: {
title: 'Dataplanes'
},
component: () => import(/* webpackChunkName: "dataplanes" */ '@/views/Entities/Dataplanes')
},
// ingress dataplanes
{
path: 'ingress-dataplanes',
name: 'ingress-dataplanes',
component: () => import(/* webpackChunkName: "dataplanes-ingress" */ '@/views/Entities/IngressDataplanes'),
meta: {
title: 'Ingress Dataplanes',
breadcrumb: 'Ingress Dataplanes'
}
},
// gateway dataplanes
{
path: 'gateway-dataplanes',
name: 'gateway-dataplanes',
component: () => import(/* webpackChunkName: "dataplanes-gateway" */ '@/views/Entities/GatewayDataplanes'),
meta: {
title: 'Gateway Dataplanes',
breadcrumb: 'Gateway Dataplanes'
}
},
// traffic permissions
{
path: 'traffic-permissions',
name: 'traffic-permissions',
meta: {
title: 'Traffic Permissions'
},
component: () => import(/* webpackChunkName: "traffic-permissions" */ '@/views/Policies/TrafficPermissions')
},
// traffic routes
{
path: 'traffic-routes',
name: 'traffic-routes',
meta: {
title: 'Traffic Routes'
},
component: () => import(/* webpackChunkName: "traffic-routes" */ '@/views/Policies/TrafficRoutes')
},
// traffic logs
{
path: 'traffic-logs',
name: 'traffic-logs',
meta: {
title: 'Traffic Logs'
},
component: () => import(/* webpackChunkName: "traffic-logs" */ '@/views/Policies/TrafficLogs')
},
// traffic traces
{
path: 'traffic-traces',
name: 'traffic-traces',
meta: {
title: 'Traffic Traces'
},
component: () => import(/* webpackChunkName: "traffic-traces" */ '@/views/Policies/TrafficTraces')
},
// fault injections
{
path: 'fault-injections',
name: 'fault-injections',
meta: {
title: 'Fault Injections'
},
component: () => import(/* webpackChunkName: "fault-injections" */ '@/views/Policies/FaultInjections')
},
// circuit breakers
{
path: 'circuit-breakers',
name: 'circuit-breakers',
meta: {
title: 'Circuit Breakers'
},
component: () => import(/* webpackChunkName: "circuit-breakers" */ '@/views/Policies/CircuitBreakers')
},
// health checks
{
path: 'health-checks',
name: 'health-checks',
meta: {
title: 'Health Checks'
},
component: () => import(/* webpackChunkName: "health-checks" */ '@/views/Policies/HealthChecks')
},
// proxy templates
{
path: 'proxy-templates',
name: 'proxy-templates',
meta: {
title: 'Proxy Templates'
},
component: () => import(/* webpackChunkName: "proxy-templates" */ '@/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()
})
/**
* If the user is sent to the homepage root url ("/")
* redirect them to the Global Overview and set the mesh to "all".
* This ensures they get to the desired starting page once finished
* with the onboarding process.
*
* When the user is sent to the Global Overview from the root, this will also
* changed the selected mesh in their localStorage if it's set to something
* other than "all".
*/
router.beforeEach((to, from, next) => {
const isRoot = to.fullPath === '/'
const storedMesh = localStorage.getItem('selectedMesh') || null
const targetMesh = 'all'
if (isRoot) {
/** sync the mesh in localStorage with the route change */
if (storedMesh && storedMesh !== targetMesh) {
localStorage.setItem('selectedMesh', targetMesh)
}
/** send the user to the Global Overview from "/" */
next({
name: 'global-overview',
params: { mesh: targetMesh }
})
} else {
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()
}
})
/**
* 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
}