Mercurial > gemma
view client/src/router.js @ 1207:70116d392387
close bottleneck list: made searchbar collapse only if it was collapsed before
opening the bottleneck list will expand the searchbar, closing the bottleneck list
was always collapsing the searchbar too. Now it stays open if it was open beforeopening the bottleneck list
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 19 Nov 2018 13:02:48 +0100 |
parents | 1d4801145a2d |
children | 162a790120c2 |
line wrap: on
line source
/* * This is Free Software under GNU Affero General Public License v >= 3.0 * without warranty, see README.md and license for details. * * SPDX-License-Identifier: AGPL-3.0-or-later * License-Filename: LICENSES/AGPL-3.0.txt * * Copyright (C) 2018 by via donau * – Österreichische Wasserstraßen-Gesellschaft mbH * Software engineering by Intevation GmbH * * Author(s): * Thomas Junk <thomas.junk@intevation.de> */ import Vue from "vue"; import Router from "vue-router"; import store from "./store"; import { sessionStillActive, toMillisFromString } from "./application/lib/session"; /* facilitate codesplitting */ const Login = () => import("./login/Login.vue"); const Main = () => import("./application/Main.vue"); const Usermanagement = () => import("./usermanagement/Usermanagement.vue"); const Logs = () => import("./logs/logs.vue"); const Importqueue = () => import("./importqueue/Importqueue.vue"); const Systemconfiguration = () => import("./systemconfiguration/systemconfiguration.vue"); Vue.use(Router); const router = new Router({ routes: [ { path: "/login", name: "login", component: Login }, { path: "/usermanagement", name: "usermanagement", component: Usermanagement, meta: { requiresAuth: true }, beforeEnter: (to, from, next) => { const isSysadmin = store.getters["user/isSysAdmin"]; if (!isSysadmin) { next("/"); } else { next(); } } }, { path: "/logs", name: "logs", component: Logs, meta: { requiresAuth: true }, beforeEnter: (to, from, next) => { const isSysadmin = store.getters["user/isSysAdmin"]; if (!isSysadmin) { next("/"); } else { next(); } } }, { path: "/systemconfiguration", name: "systemconfiguration", component: Systemconfiguration, meta: { requiresAuth: true }, beforeEnter: (to, from, next) => { const isSysadmin = store.getters["user/isSysAdmin"]; if (!isSysadmin) { next("/"); } else { next(); } } }, { path: "/importqueue", name: "importqueue", component: Importqueue, meta: { requiresAuth: true }, beforeEnter: (to, from, next) => { const isWaterwayAdmin = store.getters["user/isSysAdmin"]; if (!isWaterwayAdmin) { next("/"); } else { next(); } } }, { path: "/", name: "mainview", component: Main, meta: { requiresAuth: true }, beforeEnter: (to, from, next) => { const expiresFromPastSession = toMillisFromString( localStorage.getItem("expires") ); if (sessionStillActive(expiresFromPastSession)) { store.commit("user/setUser", localStorage.getItem("user")); store.commit("user/setExpires", expiresFromPastSession); store.commit("user/setRoles", localStorage.getItem("roles")); store.commit("user/setIsAuthenticate", true); } else { store.commit("user/clearAuth"); } next(); } }, { path: "*", component: Login } ] }); router.beforeEach((to, from, next) => { const requiresAuth = to.matched.some(record => record.meta.requiresAuth); const loggedIn = store.state.user.isAuthenticated; const expiresFromPastSession = toMillisFromString( localStorage.getItem("expires") ); const authRequired = requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession)); if (authRequired) { next("/login"); } else if (!authRequired) { next(); } else { next(); } }); export default router;