This commit is contained in:
2019-07-24 15:09:00 +00:00
parent 604fe1dd72
commit 565a092251
10 changed files with 77 additions and 76 deletions

View File

@@ -1,10 +1,9 @@
/* xeslint-disable */
import store from "../store";
import rights from "./bizroles";
import bizrolerights from "./biz-role-rights";
export default {
ROLE_RIGHTS: rights,
ROLE_RIGHTS: bizrolerights,
AUTHORIZATION_ROLES: {
///<summary>No role set</summary>
NoRole: 0,
@@ -40,10 +39,10 @@ export default {
OpsAdminFull: 16384
},
hasRole(desiredRole) {
if (!store.state.roles || store.state.roles === 0) {
if (!window.$gz.store.state.roles || window.$gz.store.state.roles === 0) {
return false;
}
return (store.state.roles & desiredRole) != 0;
return (window.$gz.store.state.roles & desiredRole) != 0;
},
///////////////////////////////////////////////////////////////////////
// Get a default empty rights object so that it can be present when a
@@ -59,7 +58,7 @@ export default {
/////////////////////////////////
// oType is the name of the object type as defined in ayatype.js
//
getRights(vm, oType) {
getRights(oType) {
//from bizroles.cs:
//HOW THIS WORKS / WHATS EXPECTED
//Change = CREATE, RETRIEVE, UPDATE, DELETE - Full rights
@@ -80,7 +79,7 @@ export default {
var objectRoleRights = this.ROLE_RIGHTS[typeName];
//get the logged in user's role
var userRole = vm.$store.state.roles;
var userRole = window.$gz.store.state.roles;
//calculate the effective rights
//a non zero result of the bitwise calculation means true and zero means false so using !! to force it into a boolean value (contrary to some style guides that say !! is obscure but I say it saves a lot of typing)

View File

@@ -1,34 +1,29 @@
/* xeslint-disable */
import decode from "jwt-decode";
import store from "../store";
import initialize from "./initialize";
// var secondMethod = function(someStuff) {
// var promise = new Promise(function(resolve, reject) {
// setTimeout(function() {
// console.log("second method completed");
// resolve({ newData: someStuff.data + " some more data" });
// }, 2000);
// });
// return promise;
// };
export function processLogin(response) {
var promise = new Promise(function(resolve, reject) {
//is token present?
if (!response || !response.data || !response.data.token) {
store.commit("logItem", "auth::processLogin -> response empty");
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response empty"
);
return reject();
}
const token = decode(response.data.token);
if (!token || !token.iss) {
store.commit("logItem", "auth::processLogin -> response token empty");
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response token empty"
);
return reject();
}
if (token.iss != "ayanova.com") {
store.commit(
window.$gz.store.commit(
"logItem",
"auth::processLogin -> token invalid (iss): " + token.iss
);
@@ -36,7 +31,7 @@ export function processLogin(response) {
}
//Put app relevant items into vuex store so app can use them
store.commit("login", {
window.$gz.store.commit("login", {
apiToken: response.data.token,
authenticated: true,
userId: Number(token.id),
@@ -46,7 +41,7 @@ export function processLogin(response) {
//Initialize the application
initialize().then(() => {
store.commit(
window.$gz.store.commit(
"logItem",
"auth::processLogin -> User " + token.id + " logged in"
);
@@ -57,16 +52,22 @@ export function processLogin(response) {
}
export function processLogout() {
if (store.state.authenticated) {
store.commit("logItem", "auth::processLogout -> User logged out");
if (window.$gz.store.state.authenticated) {
window.$gz.store.commit(
"logItem",
"auth::processLogout -> User logged out"
);
}
store.commit("logout");
window.$gz.store.commit("logout");
sessionStorage.clear(); //clear all temporary session storage data
}
export function isLoggedIn() {
//const token = getToken();
return !!store.state.apiToken && !isTokenExpired(store.state.apiToken);
return (
!!window.$gz.store.state.apiToken &&
!isTokenExpired(window.$gz.store.state.apiToken)
);
}
function getTokenExpirationDate(encodedToken) {

View File

@@ -1,7 +1,5 @@
/* Xeslint-disable */
import store from "../store";
import locale from "./locale";
import gzevent from "./eventbus";
var devModeShowErrors = false;
////////////////////////////////////////////////////////
@@ -9,20 +7,20 @@ var devModeShowErrors = false;
// Localize, Log and optionally display errors
// return localized message in case caller needs it
function dealWithError(msg, vm) {
msg = locale.translateString(msg);
msg = window.$gz.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
if (!devModeShowErrors && msg.includes("??")) {
msg = msg.replace("??", "");
}
store.commit("logItem", msg);
window.$gz.store.commit("logItem", msg);
if (devModeShowErrors) {
var errMsg =
"DEV ERROR errorHandler::devShowUnknownError - unexpected error: \r\n" +
msg;
//eslint-disable-next-line
console.log(errMsg);
gzevent.$emit("notify-error", errMsg);
window.$gz.eventbus.$emit("notify-error", errMsg);
}
//If a form instance was provided (vue instance)

View File

@@ -1,7 +1,4 @@
/*e slint-disable */
import store from "../store";
import gzapi from "./gzapi";
import _ from "../libs/lodash.min.js";
///Add data key names which make the custom fields control work more easily
///Since the names can be inferred from the data that comes from the server it saves bandwidth to do it here at the client
@@ -21,14 +18,16 @@ function addDataKeyNames(obj) {
export default {
get(formKey) {
return new Promise(function getFormTemplate(resolve) {
if (!_.has(store.state.formCustomTemplate, formKey)) {
if (
!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)
) {
//fetch and populate the store
gzapi.get("formcustom/" + formKey).then(res => {
window.$gz.api.get("formcustom/" + formKey).then(res => {
if (res.error) {
throw res.error;
}
store.commit("addFormCustomTemplateItem", {
window.$gz.store.commit("addFormCustomTemplateItem", {
formKey: formKey,
value: addDataKeyNames(JSON.parse(res.data.template))
});

View File

@@ -1,11 +1,6 @@
/* Xeslint-disable */
import _ from "../libs/lodash.min.js";
import store from "../store";
import router from "../router";
import auth from "./auth";
import errorHandler from "./errorhandler";
import gzevent from "./eventbus";
import gzlocale from "./locale";
function stringifyPrimitive(v) {
switch (typeof v) {
@@ -27,13 +22,13 @@ function stringifyPrimitive(v) {
// Show unexpected errors during development
//
function devShowUnknownError(error) {
if (errorHandler.devMode) {
if (window.$gz.errorHandler.devMode) {
// eslint-disable-next-line
console.log("gzapi::devShowUnknownError, error is:");
// eslint-disable-next-line
console.log(error);
gzevent.$emit(
window.$gz.eventBus.$emit(
"notify-warning",
"DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console "
);
@@ -47,7 +42,7 @@ function devShowUnknownError(error) {
function handleError(action, error, route, reject) {
var errorMessage =
"API error: " + action + " route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage);
window.$gz.store.commit("logItem", errorMessage);
//Handle 403 not authorized
//popup not authorized, log, then go to HOME
@@ -55,16 +50,25 @@ function handleError(action, error, route, reject) {
//reaction to directly entered or opened link, not application logic driving it, so home is safest choice
//
if (error.message && error.message.includes("NotAuthorized")) {
store.commit("logItem", "Not authorized, redirecting to HOME");
gzevent.$emit("notify-warning", gzlocale.get("ErrorUserNotAuthorized"));
window.$gz.store.commit("logItem", "Not authorized, redirecting to HOME");
window.$gz.eventBus.$emit(
"notify-warning",
window.$gz.locale.get("ErrorUserNotAuthorized")
);
router.push("/");
return reject("[ErrorUserNotAuthorized]");
}
//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"));
window.$gz.store.commit(
"logItem",
"User is not authenticated, redirecting to LOGIN"
);
window.$gz.eventBus.$emit(
"notify-error",
window.$gz.locale.get("ErrorUserNotAuthenticated")
);
auth.logout();
router.push("/login");
return reject("[ErrorUserNotAuthenticated]");
@@ -78,7 +82,7 @@ function handleError(action, error, route, reject) {
error.message.includes("NetworkError") ||
error.message.includes("Network request failed")
) {
store.commit("logItem", "Network error");
window.$gz.store.commit("logItem", "Network error");
//note: using locale key in square brackets
return reject("[ErrorServerUnresponsive]");
//throw "Error: unable to contact server";
@@ -105,7 +109,7 @@ export default {
return Promise.resolve(response);
} else {
//log unhandled api error
store.commit(
window.$gz.store.commit(
"logItem",
"API error: status=" +
response.status +
@@ -134,14 +138,14 @@ export default {
//Accept: "application/json, text/plain, */*",
Accept: "application/json",
"Content-Type": "application/json-patch+json",
Authorization: "Bearer " + store.state.apiToken
Authorization: "Bearer " + window.$gz.store.state.apiToken
};
},
postAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + store.state.apiToken
Authorization: "Bearer " + window.$gz.store.state.apiToken
};
},
postUnAuthorizedHeaders() {
@@ -191,7 +195,7 @@ export default {
};
},
APIUrl(apiPath) {
if ("" == store.state.apiUrl) {
if ("" == window.$gz.store.state.apiUrl) {
//construct the api url and store it
//development location?
if (
@@ -199,29 +203,30 @@ export default {
window.location.hostname == "192.168.1.56") &&
window.location.port == "8080"
) {
store.commit("setAPIURL", "http://localhost:7575/api/v8.0/");
store.commit("setHelpURL", "http://localhost:7575/docs/");
store.commit(
window.$gz.store.commit("setAPIURL", "http://localhost:7575/api/v8.0/");
window.$gz.store.commit("setHelpURL", "http://localhost:7575/docs/");
window.$gz.store.commit(
"logItem",
"gzapi::APIUrl -> setting to dev. mode: " + store.state.apiUrl
"gzapi::APIUrl -> setting to dev. mode: " +
window.$gz.store.state.apiUrl
);
} else {
//production location <protocol>//<hostname>:<port>/
store.commit(
window.$gz.store.commit(
"setHelpURL",
window.location.protocol + "//" + window.location.host + "/docs/"
);
store.commit(
window.$gz.store.commit(
"setAPIURL",
window.location.protocol + "//" + window.location.host + "/api/v8.0/"
);
store.commit(
window.$gz.store.commit(
"logItem",
"gzapi::APIUrl -> setting to: " + store.state.apiUrl
"gzapi::APIUrl -> setting to: " + window.$gz.store.state.apiUrl
);
}
}
return store.state.apiUrl + apiPath;
return window.$gz.store.state.apiUrl + apiPath;
},
/////////////////////////////
// REPLACE END OF URL
@@ -297,7 +302,7 @@ export default {
//Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token
fetchOptions = that.fetchPostOptions(data);
//ensure the route doesn't end in /0 which will happen if it's a new record since the edit forms just send the url here with the ID regardless
if (_.endsWith(route, "/0")) {
if (window.$gz._.endsWith(route, "/0")) {
route = route.slice(0, -2);
}
}

View File

@@ -10,8 +10,6 @@
// All locale keys for validation *MUST* be fetched prior to this being used as it assumes all keys are fetched first
// Add any new keys used to the block in locale.js=>commonKeysEditForm
import Vue from "vue";
import errorHandler from "./errorhandler";
import store from "../store";
var triggeringChange = false;
@@ -65,7 +63,7 @@ function getControlValue(ctrl) {
// Get field name from control
//
function getControlLabel(ctrl) {
if (errorHandler.developmentModeShowErrorsImmediately) {
if (window.$gz.errorHandler.developmentModeShowErrorsImmediately) {
if (!ctrl.label) {
throw "gzform:getControlLabel - the control has no label " + ctrl;
}
@@ -322,7 +320,7 @@ export default {
//
serverErrors(vm, ref) {
//CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC
if (window.$gz.errorHandler.devMode()) {
if (window.$gz.window.$gz.errorHandler.devMode()) {
//make sure formState.serverErrors is defined on data
if (!window.$gz._.has(vm, "formState.serverError")) {
throw "DEV ERROR gzform::formState.serverErrors -> formState.serverError seems to be missing from form's vue data object";
@@ -517,7 +515,7 @@ export default {
getFormSettings(formKey) {
return {
temp: JSON.parse(sessionStorage.getItem(formKey)),
saved: store.state.formSettings[formKey]
saved: window.$gz.store.state.formSettings[formKey]
};
},
////////////////////////////////////
@@ -526,14 +524,14 @@ export default {
// requires object with one or both keys {temp:{...tempformsettings...},saved:{...persistedformsettings...}}
//
setFormSettings(formKey, formSettings) {
if (errorHandler.devMode()) {
if (window.$gz.errorHandler.devMode()) {
if (!formSettings.saved && !formSettings.temp) {
throw "gzform:setFormSettings - saved AND temp keys are both missing from form data!";
}
}
if (formSettings.saved) {
store.commit("setFormSettings", {
window.$gz.store.commit("setFormSettings", {
formKey: formKey,
formSettings: formSettings.saved
});

View File

@@ -114,7 +114,7 @@ export default {
})
.then(() => {
//don't have access to local data object until here
that.rights = window.$gz.role.getRights(this, window.$gz.type.Widget);
that.rights = window.$gz.role.getRights(window.$gz.type.Widget);
var formSettings = window.$gz.form.getFormSettings(FORM_KEY);
/**
* {

View File

@@ -57,7 +57,8 @@ window.$gz = {
api: gzapi,
form: gzform,
report: gzreport,
errorHandler: errorhandler
errorHandler: errorhandler,
store: store
};
/////////////////////////////////////////////////////////////////

View File

@@ -258,7 +258,7 @@ export default {
});
},
created() {
this.rights = window.$gz.role.getRights(this, window.$gz.type.Widget);
this.rights = window.$gz.role.getRights(window.$gz.type.Widget);
window.$gz.eventbus.$on("menu-click", clickHandler);
//id 0 means create a new record don't load one