From 86f359f98ef24f20c8c06bc6410957060f108536 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 8 Nov 2018 22:23:05 +0000 Subject: [PATCH] --- app/ayanova/src/utils/authUtil.js | 9 +- app/ayanova/src/utils/initialize.js | 122 ++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 app/ayanova/src/utils/initialize.js diff --git a/app/ayanova/src/utils/authUtil.js b/app/ayanova/src/utils/authUtil.js index 8c33bf1a..87a988c5 100644 --- a/app/ayanova/src/utils/authUtil.js +++ b/app/ayanova/src/utils/authUtil.js @@ -2,6 +2,8 @@ import decode from "jwt-decode"; import config from "./config"; import logger from "./logit"; import store from "../store"; +import initialize from "./initialize"; + //import axios from 'axios'; //import auth0 from 'auth0-js'; //import Router from 'vue-router'; @@ -36,14 +38,13 @@ export function processLogin(response) { roles: token["ayanova/roles"] }); + //Initialize the application + initialize(); + logger.log("User " + token.id + " logged in"); return Promise.resolve(true); } -// var router = new Router({ -// mode: 'history', -// }); - export function processLogout() { logger.log("Logout"); store.commit("notAuthenticated"); diff --git a/app/ayanova/src/utils/initialize.js b/app/ayanova/src/utils/initialize.js new file mode 100644 index 00000000..57be7e51 --- /dev/null +++ b/app/ayanova/src/utils/initialize.js @@ -0,0 +1,122 @@ +import store from "../store"; +import roles from "./roles"; + +function addNavItem(title, icon, route) { + store.state.navItems.push({ + title, + icon, + route + }); +} + +///////////////////////////////////// +// Initialize the app +// on change of authentication status +export default function initialize() { + //clear the nav items either way + store.state.navItems = []; + if (store.state.authenticated) { + //put nav items into store + + //Everyone has a home + addNavItem("Home", "home", "/"); + + if ( + roles.hasRole(roles.AuthorizationRoles.TechLimited) || + roles.hasRole(roles.AuthorizationRoles.TechFull) || + roles.hasRole(roles.AuthorizationRoles.SubContractorLimited) || + roles.hasRole(roles.AuthorizationRoles.SubContractorFull) + ) { + addNavItem("Service", "toolbox", "/service"); + } + + if ( + roles.hasRole(roles.AuthorizationRoles.OpsAdminFull) || + roles.hasRole(roles.AuthorizationRoles.OpsAdminLimited) + ) { + addNavItem("Operations", "cogs", "ops"); + } + + //Everyone can see about and logout + addNavItem("About", "info-circle", "/about"); + addNavItem("Log out", "sign-out-alt", "/login"); + } +} +/* + + + fa-home + + + Home + + + + + fa-toolbox + + + Service + + + + + fa-shipping-fast + + + Dispatch + + + + + fa-dolly + + + Inventory + + + + + fa-file-invoice-dollar + + + Accounting + + + + + fa-user-tie + + + Administration + + + + + fa-cogs + + + Operations + + + + + fa-info-circle + + + About + + + + + fa-sign-out-alt + + + Log off + + +*/