This commit is contained in:
2019-01-04 21:48:43 +00:00
parent c86dd91d33
commit 35b9674af1
6 changed files with 4 additions and 4 deletions

View File

@@ -0,0 +1,127 @@
/* xeslint-disable */
import store from "../store";
import roles from "./roles";
import lt from "./locale";
import api from "./apiutil";
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) {
//GET LOCALIZED TEXT FOR SHELL
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::() ltfetch -> error" + error);
throw error;
});
//CACHE LOCALE SETTINGS
//check the timezone offset is still valid, offer to change it if not
//api.get("UserOptions/" + store.state.userId).then(res => {
api
.get("UserOptions/" + store.state.userId)
.then(res => {
if (res.error) {
//In a form this would trigger a bunch of validation or error display code but for here and now:
//convert error to human readable string for display
alert(api.apiErrorToHumanString(res.error));
} else {
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 +
"."
);
}
}
})
.catch(function(error) {
store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + error
);
throw error;
});
}
}