This commit is contained in:
2019-05-02 19:46:34 +00:00
parent 60d1fb82fe
commit 640c6ef095
20 changed files with 400 additions and 271 deletions

View File

@@ -1,14 +1,14 @@
/* Xeslint-disable */
import store from "../store";
import locale from "./locale";
import gzevent from "./eventbus";
var devModeShowErrors = false;
////////////////////////////////////////////////////////
//
// Localize, Log and optionally display errors
// return localized message in case caller needs it
function dealWithError(msg, form) {
function dealWithError(msg, vm) {
msg = locale.translateString(msg);
//In some cases the error may not be localizable, if this is not a debug run then it should show without the ?? that localizing puts in keys not found
//so it's not as wierd looking to the user
@@ -17,20 +17,24 @@ function dealWithError(msg, form) {
}
store.commit("logItem", msg);
if (devModeShowErrors) {
alert("~" + msg);
gzevent.$emit(
"notify-error",
"DEV ERROR errorHandler::devShowUnknownError - unexpected error: \r\n" +
msg
);
}
//If a form instance was provided (vue instance)
//then put the error into it
if (form) {
if (form.$gzdevmode()) {
if (vm) {
if (vm.$gzdevmode()) {
//make sure formState.appError is defined on data
if (!form.$_.has(form, "formState.appError")) {
if (!vm.$_.has(vm, "formState.appError")) {
throw "DEV ERROR errorHandler::dealWithError -> formState.appError seems to be missing from form's vue data object";
}
}
form.formState.appError = msg;
form.$gzform.setErrorBoxErrors(form);
vm.formState.appError = msg;
vm.$gzform.setErrorBoxErrors(vm);
}
}
export default {
@@ -79,13 +83,13 @@ export default {
/////////////////////////////////////////////////
// Localize, log and return error
//
handleFormError(err, form) {
handleFormError(err, vm) {
//called inside forms when things go wrong
//returns the localized message in case the form wants to display it as well
if (err instanceof Error && err.message) {
dealWithError(err.message, form);
dealWithError(err.message, vm);
} else {
dealWithError(err.toString(), form);
dealWithError(err.toString(), vm);
}
}
};

View File

@@ -33,7 +33,7 @@ function devShowUnknownError(error) {
console.log(error);
gzevent.$emit(
"popup-message",
"notify-warning",
"DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console "
);
}
@@ -55,7 +55,7 @@ function handleError(action, error, route, reject) {
//
if (error.message && error.message.includes("NotAuthorized")) {
store.commit("logItem", "Not authorized, redirecting to HOME");
gzevent.$emit("popup-message", gzlocale.get("ErrorUserNotAuthorized"));
gzevent.$emit("notify-warning", gzlocale.get("ErrorUserNotAuthorized"));
router.push("/");
return reject("[ErrorUserNotAuthorized]");
}
@@ -63,6 +63,7 @@ function handleError(action, error, route, reject) {
//Handle 401 not authenticated
if (error.message && error.message.includes("NotAuthenticated")) {
store.commit("logItem", "User is not authenticated, redirecting to LOGIN");
gzevent.$emit("notify-error", gzlocale.get("ErrorUserNotAuthenticated"));
auth.logout();
router.push("/login");
return reject("[ErrorUserNotAuthenticated]");

View File

@@ -130,7 +130,8 @@ export default {
vm.$router.push({ name: item.data });
break;
default:
alert(
vm.$gzevent.$emit(
"notify-warning",
"gzmenu:handleAppClick - unrecognized command [" +
menuItem.key +
"]"
@@ -185,8 +186,52 @@ export default {
self.handleAppClick(vm, menuitem);
});
vm.$gzevent.$on("popup-message", function handlePopupMessage(msg) {
alert(msg);
//Notifications: pops up and slowly disappears
///////////
//ERROR
vm.$gzevent.$on("notify-error", function handleNotifyWarn(msg) {
vm.$dialog.notify.info(msg, {
position: "top-right",
icon: "fa-exclamation-triangle",
timeout: 8000
});
});
///////////
//WARNING
vm.$gzevent.$on("notify-warning", function handleNotifyWarn(msg) {
vm.$dialog.notify.warning(msg, {
position: "top-right",
icon: "fa-exclamation",
timeout: 7000
});
});
///////////
//INFO
vm.$gzevent.$on("notify-info", function handleNotifyWarn(msg) {
vm.$dialog.notify.info(msg, {
position: "top-right",
icon: "fa-info-circle",
timeout: 6000
});
});
///////////
//SUCCESS
vm.$gzevent.$on("notify-success", function handleNotifyWarn(msg) {
vm.$dialog.notify.success(msg, {
position: "top-right",
icon: "fa-check-circle ",
timeout: 5000
});
});
vm.$gzevent.$on("alert-user-toast", function handlePopupMessage(msg) {
this.$dialog.message.info(msg, {
position: "top-left"
});
});
}
//new functions above here

View File

@@ -3,6 +3,7 @@ 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", {
@@ -83,8 +84,13 @@ export default function initialize() {
.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));
//convert error to human readable string for display and popup a notification to user
var msg = api.apiErrorToHumanString(res.error);
store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + msg
);
gzevent.$emit("notify-error", msg);
} else {
//TODO: also need the other locale settings such as number and date formats etc
@@ -94,14 +100,18 @@ export default function initialize() {
}
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 +
// "."
// );
//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
gzevent.$emit(
"notify-info",
"Time zone offset for this account is set to " +
res.data.timeZoneOffset +
" which doesn't match the local timezone offset of " +
localOffset +
". You might want to adjust that under user settings"
);
}
//Store offset in locale data