This commit is contained in:
2020-01-29 21:59:01 +00:00
parent 9bcc14247e
commit ec6cf3b09c
2 changed files with 51 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ export default {
// //
//step 1: build an array of keys that we don't have already //step 1: build an array of keys that we don't have already
//Note: this will ensure only unique keys go into the store so it's safe to call this with dupes as can happen //Note: this will ensure only unique keys go into the store so it's safe to call this with dupes as can happen
//for example datatables have dynamic column names so they need to fetch on demand
var needIt = []; var needIt = [];
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
if (!window.$gz._.has(window.$gz.store.state.localeText, keys[i])) { if (!window.$gz._.has(window.$gz.store.state.localeText, keys[i])) {

View File

@@ -13,6 +13,7 @@
:options.sync="options" :options.sync="options"
:server-items-length="totalRecords" :server-items-length="totalRecords"
:loading="loading" :loading="loading"
:disable-sort="true"
class="elevation-1" class="elevation-1"
></v-data-table> ></v-data-table>
</div> </div>
@@ -111,9 +112,11 @@ export default {
listOptions["DataFilterID"] = that.dataFilterId; listOptions["DataFilterID"] = that.dataFilterId;
} }
//Mini? //Mini?
if (that.$vuetify.breakpoint.xs) { //OK, seems as though the datatable has a built in ability to handle small viewports by displaying each record vertically instead so maybe I only need
listOptions["Mini"] = true; //mini for picklists
} // if (that.$vuetify.breakpoint.xs) {
// listOptions["Mini"] = true;
// }
that.loading = true; that.loading = true;
var listUrl = var listUrl =
@@ -121,10 +124,18 @@ export default {
window.$gz.api.get(listUrl).then(res => { window.$gz.api.get(listUrl).then(res => {
that.loading = false; that.loading = false;
that.totalItems = res.paging.count; that.totalItems = res.paging.count;
//build that.headers here console.log("About to call fetchlocalizedheadernames");
that.headers = buildHeaders(res.columns); (async function() {
//Post process data here and then set that.records //Make sure the locale keys are fetched
that.records = buildRecords(res.data); await fetchLocalizedHeaderNames(res.columns);
console.log(
"Back from fetch localized header names, now can bjuild headers"
);
//build that.headers here
that.headers = buildHeaders(res.columns);
//Post process data here and then set that.records
that.records = buildRecords(res.data);
})();
}); });
} }
} }
@@ -132,6 +143,7 @@ export default {
//Called by getDataFromApi on retrieval of list with columnData //Called by getDataFromApi on retrieval of list with columnData
function buildHeaders(columnData) { function buildHeaders(columnData) {
//debugger;
//iterate columns, build headers and return //iterate columns, build headers and return
if (!columnData) { if (!columnData) {
return []; return [];
@@ -143,10 +155,41 @@ function buildHeaders(columnData) {
var h = {}; var h = {};
h["text"] = window.$gz.locale.get(cm.cm); h["text"] = window.$gz.locale.get(cm.cm);
h["value"] = i; h["value"] = i;
// console.log("Adding column:");
// console.log(h);
ret.push(h); ret.push(h);
} }
// console.log("Returning header array:");
// console.log(ret);
return ret; return ret;
} }
//////////////////////////////////////////////////////////
//
// Ensures column names are present in locale table
//
async function fetchLocalizedHeaderNames(columnData) {
if (!columnData) {
return;
}
var headerKeys = [];
for (var i = 1; i < columnData.length; i++) {
var cm = columnData[i];
headerKeys.push(cm.cm);
}
//Now fetch all the keys and await the response before returning
await window.$gz.locale
.fetch(headerKeys)
.then(() => {
console.log("fetchLocalizedHeaderNames completed, returning now");
return;
})
.catch(err => {
that.formState.ready = true; //show the form anyway so we know what's what
window.$gz.errorHandler.handleFormError(err);
});
}
/* /*
{ {
text: string text: string