115 lines
3.4 KiB
JavaScript
115 lines
3.4 KiB
JavaScript
/* eslint-disable */
|
|
import store from "../store";
|
|
import roles from "./roles";
|
|
import lt from "../api/locale";
|
|
import api from "../api/getAPIItem";
|
|
|
|
function addNavItem(title, icon, route) {
|
|
store.commit("addNavItem", {
|
|
title,
|
|
icon,
|
|
route
|
|
});
|
|
}
|
|
|
|
/////////////////////////////////////
|
|
// Initialize the app
|
|
// on change of authentication status
|
|
export default function initialize() {
|
|
if (store.state.authenticated) {
|
|
//Fetch the users options for local caching
|
|
|
|
//check the timezone offset is still valid, offer to change it if not
|
|
|
|
api.get("UserOptions/" + store.state.userId).then(res => {
|
|
//debugger;
|
|
var localOffset = new Date().getTimezoneOffset();
|
|
if (localOffset != 0) {
|
|
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
|
|
}
|
|
|
|
if (res.data.timeZoneOffset != localOffset) {
|
|
//todo: timezone doesn't match, offer to fix it
|
|
alert(
|
|
"Time zone offset for this account is set to " +
|
|
res.data.timeZoneOffset +
|
|
" which doesn't match the local timezone offset of " +
|
|
localOffset +
|
|
"."
|
|
);
|
|
}
|
|
});
|
|
|
|
//fetch the required localized text keys into the cache
|
|
lt.fetch([
|
|
"Home",
|
|
"Service",
|
|
"Dispatch",
|
|
"Inventory",
|
|
"Accounting",
|
|
"Administration",
|
|
"Operations",
|
|
"HelpAboutAyaNova",
|
|
"Logout"
|
|
])
|
|
.then(function() {
|
|
//put nav items into store
|
|
//Everyone has a home
|
|
addNavItem(lt.get("Home"), "home", "/");
|
|
|
|
if (
|
|
roles.hasRole(roles.AuthorizationRoles.TechLimited) ||
|
|
roles.hasRole(roles.AuthorizationRoles.TechFull) ||
|
|
roles.hasRole(roles.AuthorizationRoles.SubContractorLimited) ||
|
|
roles.hasRole(roles.AuthorizationRoles.SubContractorFull)
|
|
) {
|
|
addNavItem(lt.get("Service"), "toolbox", "/service");
|
|
}
|
|
|
|
if (
|
|
roles.hasRole(roles.AuthorizationRoles.DispatchLimited) ||
|
|
roles.hasRole(roles.AuthorizationRoles.DispatchFull)
|
|
) {
|
|
addNavItem(lt.get("Dispatch"), "shipping-fast", "/dispatch");
|
|
}
|
|
|
|
if (
|
|
roles.hasRole(roles.AuthorizationRoles.InventoryLimited) ||
|
|
roles.hasRole(roles.AuthorizationRoles.InventoryFull)
|
|
) {
|
|
addNavItem(lt.get("Inventory"), "dolly", "/inventory");
|
|
}
|
|
|
|
if (roles.hasRole(roles.AuthorizationRoles.AccountingFull)) {
|
|
addNavItem(
|
|
lt.get("Accounting"),
|
|
"file-invoice-dollar",
|
|
"/accounting"
|
|
);
|
|
}
|
|
|
|
if (
|
|
roles.hasRole(roles.AuthorizationRoles.BizAdminLimited) ||
|
|
roles.hasRole(roles.AuthorizationRoles.BizAdminFull)
|
|
) {
|
|
addNavItem(lt.get("Administration"), "user-tie", "/admin");
|
|
}
|
|
|
|
if (
|
|
roles.hasRole(roles.AuthorizationRoles.OpsAdminFull) ||
|
|
roles.hasRole(roles.AuthorizationRoles.OpsAdminLimited)
|
|
) {
|
|
addNavItem(lt.get("Operations"), "cogs", "ops");
|
|
}
|
|
|
|
//Everyone can see about and logout
|
|
addNavItem(lt.get("HelpAboutAyaNova"), "info-circle", "/about");
|
|
addNavItem(lt.get("Logout"), "sign-out-alt", "/login");
|
|
})
|
|
.catch(function(error) {
|
|
store.commit("logItem", "Initialize::() -> error" + error);
|
|
throw error;
|
|
});
|
|
}
|
|
}
|