annotate client/src/router.js @ 1362:ca33ad696594

remove the first empyty lines * remove the first empyty line in the license hearders to client files
author Fadi Abbud <fadi.abbud@intevation.de>
date Mon, 26 Nov 2018 11:42:47 +0100
parents 99c039e86624
children d0c4d17ee7ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1362
ca33ad696594 remove the first empyty lines
Fadi Abbud <fadi.abbud@intevation.de>
parents: 1296
diff changeset
1 /* This is Free Software under GNU Affero General Public License v >= 3.0
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
2 * without warranty, see README.md and license for details.
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
3 *
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
4 * SPDX-License-Identifier: AGPL-3.0-or-later
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
5 * License-Filename: LICENSES/AGPL-3.0.txt
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
6 *
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
7 * Copyright (C) 2018 by via donau
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
8 * – Österreichische Wasserstraßen-Gesellschaft mbH
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
9 * Software engineering by Intevation GmbH
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
10 *
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
11 * Author(s):
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
12 * Thomas Junk <thomas.junk@intevation.de>
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 853
diff changeset
13 */
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
14 import Vue from "vue";
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
15 import Router from "vue-router";
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
16 import store from "./store";
1272
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1244
diff changeset
17 import { sessionStillActive, toMillisFromString } from "./lib/session";
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
18
483
27502291e564 docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents: 466
diff changeset
19 /* facilitate codesplitting */
1272
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1244
diff changeset
20 const Login = () => import("./components/Login.vue");
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1244
diff changeset
21 const Main = () => import("./components/map/Main.vue");
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1244
diff changeset
22 const Usermanagement = () =>
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1244
diff changeset
23 import("./components/admin/usermanagement/Usermanagement.vue");
1276
aec9ed491dad more cleanup in client/src
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
24 const Logs = () => import("./components/admin/Logs.vue");
aec9ed491dad more cleanup in client/src
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
25 const Importqueue = () => import("./components/admin/Importqueue.vue");
853
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
26 const Systemconfiguration = () =>
1276
aec9ed491dad more cleanup in client/src
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
27 import("./components/admin/Systemconfiguration.vue");
466
e3035621cc52 refac: Small improvement of loading time with code splitting
Thomas Junk <thomas.junk@intevation.de>
parents: 285
diff changeset
28
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
29 Vue.use(Router);
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
30
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
31 const router = new Router({
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
32 routes: [
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
33 {
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
34 path: "/login",
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
35 name: "login",
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
36 component: Login
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
37 },
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
38 {
581
fb5d9d5ff320 refac: UI redesign
Thomas Junk <thomas.junk@intevation.de>
parents: 483
diff changeset
39 path: "/usermanagement",
fb5d9d5ff320 refac: UI redesign
Thomas Junk <thomas.junk@intevation.de>
parents: 483
diff changeset
40 name: "usermanagement",
fb5d9d5ff320 refac: UI redesign
Thomas Junk <thomas.junk@intevation.de>
parents: 483
diff changeset
41 component: Usermanagement,
278
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
42 meta: {
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
43 requiresAuth: true
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
44 },
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
45 beforeEnter: (to, from, next) => {
285
8e22d1f16f81 refactor: better variable naming
Thomas Junk <thomas.junk@intevation.de>
parents: 284
diff changeset
46 const isSysadmin = store.getters["user/isSysAdmin"];
284
96860b2bbc0d fix: User management only for sysadmin
Thomas Junk <thomas.junk@intevation.de>
parents: 278
diff changeset
47 if (!isSysadmin) {
278
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
48 next("/");
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
49 } else {
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
50 next();
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
51 }
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
52 }
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
53 },
9c1dfadb53aa feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents: 165
diff changeset
54 {
713
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
55 path: "/logs",
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
56 name: "logs",
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
57 component: Logs,
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
58 meta: {
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
59 requiresAuth: true
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
60 },
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
61 beforeEnter: (to, from, next) => {
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
62 const isSysadmin = store.getters["user/isSysAdmin"];
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
63 if (!isSysadmin) {
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
64 next("/");
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
65 } else {
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
66 next();
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
67 }
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
68 }
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
69 },
badbc0207418 feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents: 592
diff changeset
70 {
853
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
71 path: "/systemconfiguration",
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
72 name: "systemconfiguration",
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
73 component: Systemconfiguration,
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
74 meta: {
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
75 requiresAuth: true
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
76 },
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
77 beforeEnter: (to, from, next) => {
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
78 const isSysadmin = store.getters["user/isSysAdmin"];
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
79 if (!isSysadmin) {
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
80 next("/");
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
81 } else {
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
82 next();
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
83 }
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
84 }
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
85 },
fb39ec3b95a8 systemconfig WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 713
diff changeset
86 {
1173
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
87 path: "/importqueue",
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
88 name: "importqueue",
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
89 component: Importqueue,
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
90 meta: {
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
91 requiresAuth: true
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
92 },
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
93 beforeEnter: (to, from, next) => {
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
94 const isWaterwayAdmin = store.getters["user/isSysAdmin"];
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
95 if (!isWaterwayAdmin) {
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
96 next("/");
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
97 } else {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
98 next();
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
99 }
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
100 }
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
101 },
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents: 1122
diff changeset
102 {
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
103 path: "/",
30
7ba0a77fd679 ol component added
Thomas Junk <thomas.junk@intevation.de>
parents: 13
diff changeset
104 name: "mainview",
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
105 component: Main,
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
106 meta: {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
107 requiresAuth: true
160
061209505028 feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 30
diff changeset
108 },
061209505028 feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 30
diff changeset
109 beforeEnter: (to, from, next) => {
165
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
110 const expiresFromPastSession = toMillisFromString(
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
111 localStorage.getItem("expires")
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
112 );
162
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents: 160
diff changeset
113 if (sessionStillActive(expiresFromPastSession)) {
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1019
diff changeset
114 store.commit("user/setUser", localStorage.getItem("user"));
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1019
diff changeset
115 store.commit("user/setExpires", expiresFromPastSession);
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1019
diff changeset
116 store.commit("user/setRoles", localStorage.getItem("roles"));
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1019
diff changeset
117 store.commit("user/setIsAuthenticate", true);
162
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents: 160
diff changeset
118 } else {
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1276
diff changeset
119 store.commit("reset");
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1019
diff changeset
120 store.commit("user/clearAuth");
160
061209505028 feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 30
diff changeset
121 }
061209505028 feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents: 30
diff changeset
122 next();
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
123 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
124 },
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
125 {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
126 path: "*",
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
127 component: Login
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
128 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
129 ]
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
130 });
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
131
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
132 router.beforeEach((to, from, next) => {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
133 const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1019
diff changeset
134 const loggedIn = store.state.user.isAuthenticated;
165
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
135 const expiresFromPastSession = toMillisFromString(
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
136 localStorage.getItem("expires")
4bf2173748f3 refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents: 162
diff changeset
137 );
162
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents: 160
diff changeset
138 const authRequired =
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents: 160
diff changeset
139 requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession));
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents: 160
diff changeset
140 if (authRequired) {
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
141 next("/login");
162
9908260d1e6a Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents: 160
diff changeset
142 } else if (!authRequired) {
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
143 next();
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
144 } else {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
145 next();
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
146 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
147 });
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
148
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
149 export default router;