This commit is contained in:
2019-07-24 15:15:52 +00:00
parent 565a092251
commit a14e64644d
22 changed files with 132 additions and 93 deletions

View File

@@ -1,12 +1,7 @@
/* xeslint-disable */
import store from "../store";
import roles from "./authorizationroles";
import locale from "./locale";
import api from "./gzapi";
import gzevent from "./eventbus";
function addNavItem(title, icon, route) {
store.commit("addNavItem", {
window.$gz.store.commit("addNavItem", {
title,
icon,
route
@@ -18,83 +13,127 @@ function addNavItem(title, icon, route) {
// on change of authentication status
export default function initialize() {
var promise = new Promise(function(resolve) {
if (store.state.authenticated) {
if (window.$gz.store.state.authenticated) {
//Fetch the core localized text keys that will always be required by user
locale
.fetch(locale.coreKeys)
window.$gz.locale
.fetch(window.$gz.locale.coreKeys)
.then(function putFetchedNavItemsInStore() {
//put nav items into store
//Everyone has a home
addNavItem(locale.get("Home"), "home", "/");
addNavItem(window.$gz.locale.get("Home"), "home", "/");
//NOTE: If a user has read full record or better then they should have access to that area
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.TechLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.TechFull) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.SubContractorLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.SubContractorFull)
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.TechLimited
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.TechFull
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.SubContractorLimited
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.SubContractorFull
)
) {
addNavItem(locale.get("Service"), "toolbox", "/service");
addNavItem(window.$gz.locale.get("Service"), "toolbox", "/service");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchFull)
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.DispatchLimited
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.DispatchFull
)
) {
addNavItem(locale.get("Dispatch"), "shipping-fast", "/dispatch");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryFull) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminFull)
) {
addNavItem(locale.get("Inventory"), "dolly", "/inventory");
}
if (roles.hasRole(roles.AUTHORIZATION_ROLES.AccountingFull)) {
addNavItem(
locale.get("Accounting"),
window.$gz.locale.get("Dispatch"),
"shipping-fast",
"/dispatch"
);
}
if (
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.InventoryLimited
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.InventoryFull
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.BizAdminLimited
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.BizAdminFull
)
) {
addNavItem(
window.$gz.locale.get("Inventory"),
"dolly",
"/inventory"
);
}
if (
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.AccountingFull
)
) {
addNavItem(
window.$gz.locale.get("Accounting"),
"file-invoice-dollar",
"/accounting"
);
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminFull)
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.BizAdminLimited
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.BizAdminFull
)
) {
addNavItem(locale.get("Administration"), "user-tie", "/admin");
addNavItem(
window.$gz.locale.get("Administration"),
"user-tie",
"/admin"
);
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminFull) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminLimited)
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.OpsAdminFull
) ||
window.$gz.role.hasRole(
window.$gz.role.AUTHORIZATION_ROLES.OpsAdminLimited
)
) {
addNavItem(locale.get("Operations"), "cogs", "ops");
addNavItem(window.$gz.locale.get("Operations"), "cogs", "ops");
}
//MOVED TO MENU OUT OF NAV
//Everyone can see about and logout
// addNavItem(locale.get("HelpAboutAyaNova"), "info-circle", "/about");
// addNavItem(locale.get("Logout"), "sign-out-alt", "/login");
// addNavItem(window.$gz.locale.get("HelpAboutAyaNova"), "info-circle", "/about");
// addNavItem(window.$gz.locale.get("Logout"), "sign-out-alt", "/login");
})
.then(() => {
//CACHE LOCALE SETTINGS
api
.get("UserOptions/" + store.state.userId)
window.$gz.api
.get("UserOptions/" + window.$gz.store.state.userId)
.then(res => {
if (res.error != undefined) {
//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 and popup a notification to user
var msg = api.apiErrorToHumanString(res.error);
store.commit(
var msg = window.$gz.api.apiErrorToHumanString(res.error);
window.$gz.store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + msg
);
gzevent.$emit("notify-error", msg);
window.$gz.eventBus.$emit("notify-error", msg);
} else {
//TODO: also need the other locale settings such as number and date formats etc
var localOffset = new Date().getTimezoneOffset();
@@ -107,7 +146,7 @@ export default function initialize() {
//so this should be a confirm prompt but for now will just show it
//for now just show the message
gzevent.$emit(
window.$gz.eventBus.$emit(
"notify-info",
"Time zone offset for this account is set to " +
res.data.timeZoneOffset +
@@ -119,7 +158,7 @@ export default function initialize() {
//Store offset in locale data
//TODO: also need the other locale settings such as number and date formats etc to be added at server
store.commit("setLocale", {
window.$gz.store.commit("setLocale", {
decimalSeparator: ".",
currencySymbol: "$",
shortDate: "YYYY-MM-DD",
@@ -132,7 +171,7 @@ export default function initialize() {
}
})
.catch(function handleFetchUserOptionsError(error) {
store.commit(
window.$gz.store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + error
);
@@ -140,7 +179,10 @@ export default function initialize() {
});
})
.catch(function handleIntializeError(error) {
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
window.$gz.store.commit(
"logItem",
"Initialize::() ltfetch -> error" + error
);
throw error;
});
}