From abacdabd14fdac072f0ad60e40037f749c4bda97 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 10 Feb 2020 23:00:27 +0000 Subject: [PATCH] --- ayanova/src/api/enums.js | 60 ++++++------------------ ayanova/src/components/gz-data-table.vue | 26 +++++++++- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/ayanova/src/api/enums.js b/ayanova/src/api/enums.js index 51b55134..e07d1043 100644 --- a/ayanova/src/api/enums.js +++ b/ayanova/src/api/enums.js @@ -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) { diff --git a/ayanova/src/components/gz-data-table.vue b/ayanova/src/components/gz-data-table.vue index f29f5e42..f2f78b2a 100644 --- a/ayanova/src/components/gz-data-table.vue +++ b/ayanova/src/components/gz-data-table.vue @@ -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