This commit is contained in:
@@ -1,63 +1,33 @@
|
||||
/* ZZeslint-disable */
|
||||
//TODO: Need enum translator
|
||||
//AuthorizationRoles.128
|
||||
//window.$gz.local.enumLocalized(enumType, enumValue)
|
||||
//(in locale) check if have that type already featched, if not fetches the whole list and caches it locally
|
||||
//also a method to return the list of enumerated types in ID order with localized names
|
||||
//window.$gz.local.enumList(enumType) - returns a list usable on edit forms
|
||||
/* enums: {
|
||||
AuthorizationRoles0:"No role",
|
||||
AuthorizationRoles1:"Business admin limited"
|
||||
etc
|
||||
|
||||
to get all authorization roles iterate list looking for start of key that is AuthorizationRoles
|
||||
To get individual one same but only need to fetch actual value i.e. AuthorizationRoles1
|
||||
if not one item starts with AuthorizationRoles then list needs to be fetched, maybe can use the enumpicklist route for that
|
||||
This way entirely bypasses locale stuff
|
||||
//big object so maybe it's own thing, not part of locale at all or locale fronts for it??
|
||||
*/
|
||||
export default {
|
||||
//enums.AuthorizationRoles[0]
|
||||
getEnumDisplay(enumKey, enumValue) {
|
||||
// debugger;
|
||||
get(enumKey, enumValue) {
|
||||
enumKey = enumKey.toLowerCase();
|
||||
if (!window.$gz._.has(window.$gz.store.state.localeText, key)) {
|
||||
return "??" + key;
|
||||
}
|
||||
return window.$gz.store.state.localeText[key];
|
||||
return window.$gz.store.state.enums[enumKey][enumValue];
|
||||
},
|
||||
///////////////////////////////////
|
||||
//
|
||||
// Returns an array of enum value and display objects
|
||||
// for enum key specified
|
||||
// e.g. [{0:"no role"},{1:"Limited role"}]
|
||||
// Fetches enum list from server
|
||||
// and puts in store. if necessary
|
||||
//
|
||||
getEnumList(enumKey) {
|
||||
//debugger;
|
||||
async fetchEnumList(enumKey) {
|
||||
//check if list
|
||||
//if not then fetch it and store it
|
||||
enumKey = enumKey.toLowerCase();
|
||||
|
||||
if (!window.$gz._.has(window.$gz.store.state.enums, enumKey)) {
|
||||
var that = this;
|
||||
(async function() {
|
||||
await that.fetch(enumKey).then(dat => {
|
||||
//massage the data as necessary
|
||||
debugger;
|
||||
|
||||
var e = { enumKey: enumKey, items: {} };
|
||||
for (var i = 0; i < dat.length; i++) {
|
||||
var o = dat[i];
|
||||
e.items[o.id] = o.name;
|
||||
}
|
||||
|
||||
//stuff the data into the store
|
||||
window.$gz.store.commit("setEnum", e);
|
||||
return window.$gz.store.state.enums[enumKey];
|
||||
});
|
||||
})();
|
||||
} else {
|
||||
return window.$gz.store.state.enums[enumKey];
|
||||
await that.fetch(enumKey).then(dat => {
|
||||
//massage the data as necessary
|
||||
var e = { enumKey: enumKey, items: {} };
|
||||
for (var i = 0; i < dat.length; i++) {
|
||||
var o = dat[i];
|
||||
e.items[o.id] = o.name;
|
||||
}
|
||||
//stuff the data into the store
|
||||
window.$gz.store.commit("setEnum", e);
|
||||
});
|
||||
}
|
||||
},
|
||||
fetch(enumKey) {
|
||||
|
||||
@@ -399,6 +399,7 @@ export default {
|
||||
that.serverColumns = res.columns;
|
||||
//Make sure the locale keys are fetched
|
||||
await fetchLocalizedHeaderNames(res.columns); //Note can use await here because it's wrapped inside an async function call, it will wait then resume next stuff below
|
||||
await fetchEnums(res.columns);
|
||||
//build that.headers here
|
||||
that.headers = buildHeaders(res.columns);
|
||||
//Post process data here and then set that.records
|
||||
@@ -536,8 +537,12 @@ function buildRecords(listData, columndefinitions, filters) {
|
||||
This way entirely bypasses locale stuff
|
||||
//big object so maybe it's own thing, not part of locale at all or locale fronts for it??
|
||||
*/
|
||||
window.$gz.enums.getEnumList(columndefinitions[iColumn].et);
|
||||
display = columndefinitions[iColumn].et + "." + display;
|
||||
// window.$gz.enums.getEnumList(columndefinitions[iColumn].et);
|
||||
//display = columndefinitions[iColumn].et + "." + display;
|
||||
display = window.$gz.enums.get(
|
||||
columndefinitions[iColumn].et,
|
||||
display
|
||||
);
|
||||
break;
|
||||
default:
|
||||
//do nothing, allow it to stay as is
|
||||
@@ -593,6 +598,23 @@ async function fetchLocalizedHeaderNames(columnData) {
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Ensures column enums are present in enums list in store
|
||||
//
|
||||
async function fetchEnums(columnData) {
|
||||
if (!columnData) {
|
||||
return;
|
||||
}
|
||||
var headerKeys = [];
|
||||
for (var i = 1; i < columnData.length; i++) {
|
||||
var cm = columnData[i];
|
||||
if (cm.et) {
|
||||
await window.$gz.enums.fetchEnumList(cm.et);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CURRENTLY THINKING NOT TO CACHE THIS AS
|
||||
//users might only ever view the list and
|
||||
//often it might not contain the whole range of options
|
||||
|
||||
Reference in New Issue
Block a user