This commit is contained in:
2019-04-29 23:00:55 +00:00
parent aa3751be35
commit 6ffbbc11de
3 changed files with 176 additions and 145 deletions

View File

@@ -16,117 +16,124 @@ function addNavItem(title, icon, route) {
// Initialize the app
// on change of authentication status
export default function initialize() {
/* eslint-disable-next-line */
console.log("STEP 3 - INITIALIZE TOP");
if (store.state.authenticated) {
var promise = new Promise(function(resolve) {
/* eslint-disable-next-line */
console.log("STEP 4 - INITIALIZE FETCHING LOCALE KEYS");
//Fetch the core localized text keys that will always be required by user
locale
.fetch(locale.coreKeys)
.then(function putFetchedNavItemsInStore() {
/* eslint-disable-next-line */
console.log("STEP 5 - DONE FETCHING LOCALE KEYS CREATING NAV ITEMS");
//put nav items into store
//Everyone has a home
addNavItem(locale.get("Home"), "home", "/");
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)
) {
addNavItem(locale.get("Service"), "toolbox", "/service");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchFull)
) {
addNavItem(locale.get("Dispatch"), "shipping-fast", "/dispatch");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryFull)
) {
addNavItem(locale.get("Inventory"), "dolly", "/inventory");
}
if (roles.hasRole(roles.AUTHORIZATION_ROLES.AccountingFull)) {
addNavItem(
locale.get("Accounting"),
"file-invoice-dollar",
"/accounting"
);
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminFull)
) {
addNavItem(locale.get("Administration"), "user-tie", "/admin");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminFull) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminLimited)
) {
addNavItem(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");
})
.catch(function handleIntializeError(error) {
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
throw error;
});
/* eslint-disable-next-line */
console.log("STEP 6 - INIT DONE WITH NAV, NOW FETCHING USEROPTIONS SETTINGS");
//CACHE LOCALE SETTINGS
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 {
//TODO: also need the other locale settings such as number and date formats etc
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 +
// "."
// );
}
//Store offset in locale data
locale.timeZoneOffset = res.data.timeZoneOffset;
console.log("STEP 3 - INITIALIZE TOP");
if (store.state.authenticated) {
/* eslint-disable-next-line */
console.log("STEP 4 - INITIALIZE FETCHING LOCALE KEYS");
//Fetch the core localized text keys that will always be required by user
locale
.fetch(locale.coreKeys)
.then(function putFetchedNavItemsInStore() {
/* eslint-disable-next-line */
console.log("STEP 7 - DONE FETCHING LOCALE SETTINGS");
}
})
.catch(function handleFetchUserOptionsError(error) {
store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + error
);
throw error;
});
}
console.log("STEP 5 - DONE FETCHING LOCALE KEYS CREATING NAV ITEMS");
//put nav items into store
//Everyone has a home
addNavItem(locale.get("Home"), "home", "/");
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)
) {
addNavItem(locale.get("Service"), "toolbox", "/service");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchFull)
) {
addNavItem(locale.get("Dispatch"), "shipping-fast", "/dispatch");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryFull)
) {
addNavItem(locale.get("Inventory"), "dolly", "/inventory");
}
if (roles.hasRole(roles.AUTHORIZATION_ROLES.AccountingFull)) {
addNavItem(
locale.get("Accounting"),
"file-invoice-dollar",
"/accounting"
);
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminLimited) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminFull)
) {
addNavItem(locale.get("Administration"), "user-tie", "/admin");
}
if (
roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminFull) ||
roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminLimited)
) {
addNavItem(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");
})
.then(() => {
/* eslint-disable-next-line */
console.log(
"STEP 6 - INIT DONE WITH NAV, NOW FETCHING USEROPTIONS SETTINGS"
);
//CACHE LOCALE SETTINGS
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 {
//TODO: also need the other locale settings such as number and date formats etc
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 +
// "."
// );
}
//Store offset in locale data
locale.timeZoneOffset = res.data.timeZoneOffset;
/* eslint-disable-next-line */
console.log("STEP 7 - DONE FETCHING LOCALE SETTINGS");
resolve();
}
})
.catch(function handleFetchUserOptionsError(error) {
store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + error
);
throw error;
});
})
.catch(function handleIntializeError(error) {
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
throw error;
});
}
});
return promise;
}