270 lines
9.8 KiB
JavaScript
270 lines
9.8 KiB
JavaScript
/* Xeslint-disable */
|
|
|
|
function addNavItem(title, icon, route, navItems) {
|
|
window.$gz.store.commit("addNavItem", {
|
|
title,
|
|
icon,
|
|
route,
|
|
navItems
|
|
});
|
|
}
|
|
|
|
/////////////////////////////////////
|
|
// Initialize the app
|
|
// on change of authentication status
|
|
export default function initialize() {
|
|
var promise = new Promise(function(resolve) {
|
|
if (window.$gz.store.state.authenticated) {
|
|
//Fetch the core localized text keys that will always be required by user
|
|
window.$gz.locale
|
|
.fetch(window.$gz.locale.coreKeys)
|
|
.then(function putFetchedNavItemsInStore() {
|
|
//put nav items into store
|
|
//Everyone has a home
|
|
|
|
/*
|
|
- "HOME" (Current user specific stuff only)
|
|
- "OVERVIEW" (old "dashboard" not sure of the LT name but it's the old dashboard) of service if a tech or has access to tech related shit like current dashboard
|
|
- A customer had thoughts on the dashboard:
|
|
- case 1974: shootnsharp@thesoileaus.com "In my opinion, the dashboard would be much more functional and valuable if I could determine how many work orders show on the screen and possibly even what statuses (or be able to sort by status, priority, etc.) The At a Glance stats of Service Rate Quantity is helpful but would be even more relevant if it showed what was approaching due date, overdue, waiting on parts, pending parts requests, items on loan stats, preventative maintenance work orders approaching and overdue. Having the capability to customize the Dashboard is key because each Service business has its own metrics that are most important to its business."
|
|
- SCHEDULE (User's own schedule only if applicable, all users can have a schedule so it goes here)
|
|
- MEMOS (for user)
|
|
- SETTINGS
|
|
- User locale settings
|
|
- Language
|
|
- Time zone
|
|
- date time numeric formats (NOT CURRENCY, THATS GLOBAL AND FIXED)
|
|
- Any other user specific settings that the User can control (and sb able to control more than in v7 if it doesn't affect anyone else)
|
|
- Change login?
|
|
- notification subscriptions
|
|
- Notifciation deliveries
|
|
*/
|
|
|
|
//create array of sub items under the home menu item
|
|
var sub = [];
|
|
|
|
//DASHBOARD
|
|
sub.push({
|
|
title: window.$gz.locale.get("DashboardDashboard"),
|
|
icon: "tachometer-alt",
|
|
route: "/dashboard"
|
|
});
|
|
//SCHEDULE (personal)
|
|
sub.push({
|
|
title: window.$gz.locale.get("Schedule"),
|
|
icon: "calendar-alt",
|
|
route: "/schedule/me"
|
|
});
|
|
|
|
//MEMOS
|
|
sub.push({
|
|
title: window.$gz.locale.get("Schedule"),
|
|
icon: "inbox",
|
|
route: "/memo"
|
|
});
|
|
|
|
//3rd level items under preferences
|
|
var subSub = [];
|
|
|
|
//LOCALE
|
|
subSub.push({
|
|
title: window.$gz.locale.get("Locale"),
|
|
icon: "language",
|
|
route: "/locale"
|
|
});
|
|
|
|
//LOGIN
|
|
subSub.push({
|
|
title: window.$gz.locale.get("SetLoginPassword"),
|
|
icon: "key",
|
|
route: "/changepw"
|
|
});
|
|
|
|
//Preferences (personal)
|
|
sub.push({
|
|
title: window.$gz.locale.get("UserPreferences"),
|
|
icon: "user-cog",
|
|
route: undefined,
|
|
navItems: subSub
|
|
});
|
|
|
|
addNavItem(window.$gz.locale.get("Home"), "home", "/", sub);
|
|
|
|
//NOTE: If a user has read full record or better then they should have access to that area
|
|
|
|
if (
|
|
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(window.$gz.locale.get("Service"), "toolbox", "/service");
|
|
}
|
|
|
|
if (
|
|
window.$gz.role.hasRole(
|
|
window.$gz.role.AUTHORIZATION_ROLES.DispatchLimited
|
|
) ||
|
|
window.$gz.role.hasRole(
|
|
window.$gz.role.AUTHORIZATION_ROLES.DispatchFull
|
|
)
|
|
) {
|
|
addNavItem(
|
|
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 (
|
|
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("Administration"),
|
|
"user-tie",
|
|
"/admin"
|
|
);
|
|
}
|
|
|
|
if (
|
|
window.$gz.role.hasRole(
|
|
window.$gz.role.AUTHORIZATION_ROLES.OpsAdminFull
|
|
) ||
|
|
window.$gz.role.hasRole(
|
|
window.$gz.role.AUTHORIZATION_ROLES.OpsAdminLimited
|
|
)
|
|
) {
|
|
addNavItem(window.$gz.locale.get("Operations"), "cogs", "ops");
|
|
}
|
|
|
|
//MOVED TO MENU OUT OF NAV
|
|
//Everyone can see about and logout
|
|
// addNavItem(window.$gz.locale.get("HelpAboutAyaNova"), "info-circle", "/about");
|
|
// addNavItem(window.$gz.locale.get("Logout"), "sign-out-alt", "/login");
|
|
})
|
|
.then(() => {
|
|
//CACHE LOCALE SETTINGS
|
|
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 = window.$gz.api.apiErrorToHumanString(res.error);
|
|
window.$gz.store.commit(
|
|
"logItem",
|
|
"Initialize::() fetch useroptions -> 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();
|
|
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: localize message and also actually have a fix for it here
|
|
//so this should be a confirm prompt but for now will just show it
|
|
|
|
//for now just show the message
|
|
window.$gz.eventBus.$emit(
|
|
"notify-info",
|
|
"Time zone offset for your account is set to " +
|
|
res.data.timeZoneOffset +
|
|
" which doesn't match the local timezone offset of " +
|
|
localOffset,
|
|
window.$gz.store.state.helpUrl + "intro/#searching"
|
|
);
|
|
}
|
|
|
|
// window.$gz.eventBus.$emit("notify-success", "Success");
|
|
// window.$gz.eventBus.$emit(
|
|
// "notify-warning",
|
|
// "This is a very long warning, it has a lot of text and goes on and on and on. Hard to understand why anyone would do it this way but whatever right?@!"
|
|
// );
|
|
// window.$gz.eventBus.$emit(
|
|
// "notify-error",
|
|
// "This is a medium error"
|
|
// );
|
|
|
|
//Store offset in locale data
|
|
//TODO: also need the other locale settings such as number and date formats etc to be added at server
|
|
window.$gz.store.commit("setLocale", {
|
|
decimalSeparator: ".",
|
|
currencySymbol: "$",
|
|
shortDate: "YYYY-MM-DD",
|
|
shortTime: "hh:mm:ss A",
|
|
shortDateAndTime: "YYYY-MM-DD hh:mm:ss A",
|
|
timeZoneOffset: res.data.timeZoneOffset
|
|
});
|
|
|
|
resolve();
|
|
}
|
|
})
|
|
.catch(function handleFetchUserOptionsError(error) {
|
|
window.$gz.store.commit(
|
|
"logItem",
|
|
"Initialize::() fetch useroptions -> error" + error
|
|
);
|
|
throw error;
|
|
});
|
|
})
|
|
.catch(function handleIntializeError(error) {
|
|
window.$gz.store.commit(
|
|
"logItem",
|
|
"Initialize::() ltfetch -> error" + error
|
|
);
|
|
throw error;
|
|
});
|
|
}
|
|
});
|
|
return promise;
|
|
}
|