This commit is contained in:
2021-02-03 18:45:58 +00:00
parent 6e9d2fe280
commit 23f8e76878
2 changed files with 86 additions and 75 deletions

View File

@@ -9,6 +9,7 @@
<v-card-title>{{ tableColumnData.text }}</v-card-title>
<!-- <v-card-subtitle class="mt-1">sub title text</v-card-subtitle> -->
<v-card-text>
activefilter:{{ activeFilter }} editItem:{{ editItem }}
<!-- FILTER CONTROL -->
<template v-if="editItem.isFilterable">
<div class="pt-6">
@@ -467,7 +468,7 @@ export default {
async open(tableColumnData) {
this.tableColumnData = tableColumnData;
await getActiveFilter(vm);
await fetchActiveFilter(this);
initEditItem(this);
this.isVisible = true;
return new Promise((resolve, reject) => {
@@ -526,9 +527,7 @@ async function populateFieldDefinitions(vm) {
//
async function fetchActiveFilter(vm) {
///api/v8/data-list-filter/{id}
let res = await window.$gz.api.get(
`/api/v8/data-list-filter/${vm.activeFilterId}`
);
let res = await window.$gz.api.get(`data-list-filter/${vm.activeFilterId}`);
if (res.error) {
//throw new Error(res.error);
throw new Error(window.$gz.errorHandler.errorToString(res, vm));

View File

@@ -3,7 +3,7 @@
<gz-error :errorBoxMessage="formState.errorBoxMessage"></gz-error>
<gz-data-table-filter
:dataListKey="dataListKey"
:activeFilterId="filterId"
:activeFilterId="activeFilterId"
ref="dataTableFilter"
>
</gz-data-table-filter>
@@ -12,7 +12,7 @@
{{ headers }} -->
<v-card-title>
<v-select
v-model="filterId"
v-model="activeFilterId"
:items="selectLists.savedFilters"
item-text="name"
item-value="id"
@@ -384,7 +384,7 @@ export default {
loading: true,
dataTablePagingOptions: {},
lastDataTablePagingOptions: {},
filterId: 0,
activeFilterId: 0, //<--0 signifies to select default as it's uninitialized
listView: undefined,
selectLists: {
savedFilters: []
@@ -614,13 +614,13 @@ export default {
params: {
dataListKey: this.dataListKey,
formKey: this.formKey,
filterId: this.filterId
activeFilterId: this.activeFilterId
}
});
},
resetListView: function() {
let vm = this;
vm.filterId = 0;
vm.activeFilterId = 0;
vm.listView = undefined;
vm.dataTablePagingOptions.page = 1;
saveFormSettings(vm);
@@ -628,6 +628,7 @@ export default {
},
savedFilterSelected: async function() {
return;
let vm = this;
//If listview had changed it can only have changed *away* from the unsaved filter item if it's present so just remove the unsaved filter item if it exists
@@ -651,11 +652,11 @@ export default {
}
}
if (vm.filterId == 0) {
if (vm.activeFilterId == 0) {
//default view, no saved, no cached
vm.listView = undefined;
saveFormSettings(vm);
} else if (vm.filterId > 0) {
} else if (vm.activeFilterId > 0) {
await fetchListView(vm);
saveFormSettings(vm);
}
@@ -788,7 +789,7 @@ export default {
vm.getDataFromApi();
},
beforeUpdate() {
if (this.clientCriteria != null && this.filterId != 0) {
if (this.clientCriteria != null && this.activeFilterId != 0) {
this.resetListView();
}
}
@@ -1071,44 +1072,52 @@ async function initForm(vm) {
////////////////////
//
async function populateSelectionLists(vm) {
//http://localhost:7575/api/v8/data-list-view/viewlist?ListKey=TestWidgetDataList
//http://localhost:7575/api/v8/data-list-filter/list?ListKey=TestWidgetDataList
let res = await window.$gz.api.get(
"data-list-filter/list?ListKey=" + vm.dataListKey
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
//window.$gz.errorHandler.handleFormError(res.error, vm);
} else {
vm.selectLists.savedFilters = res.data;
window.$gz.form.addNoSelectionItem(vm.selectLists.savedFilters);
if (vm.activeFilterId == 0) {
let dflt = res.data.find(z => z.default == true);
if (!dflt) {
throw new Error(
`data-table::populateSelectionLists - No default filter returned for listKey '${vm.dataListKey}'`
);
} else {
vm.activeFilterId = dflt.id;
}
}
}
}
//////////////////////////////////////////////////////////
//
// Fetch and cache list view
//
async function fetchListView(vm) {
if (!vm.filterId) {
return;
}
let res = await window.$gz.api.get("data-list-view/" + vm.filterId);
if (res.error) {
if (res.error.code && res.error.code == "2010") {
//list not found, probably deleted by another user
//or on another browser and this one still had it as the last used list view
vm.filterId = 0; //indicate no list view
return;
} else {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
}
// window.$gz.errorHandler.handleFormError(res.error, vm);
} else {
vm.listView = res.data.listView;
}
}
// //////////////////////////////////////////////////////////
// //
// // Fetch and cache list view
// //
// async function fetchListView(vm) {
// if (!vm.activeFilterId) {
// return;
// }
// let res = await window.$gz.api.get("data-list-view/" + vm.activeFilterId);
// if (res.error) {
// if (res.error.code && res.error.code == "2010") {
// //list not found, probably deleted by another user
// //or on another browser and this one still had it as the last used list view
// vm.activeFilterId = 0; //indicate no list view
// return;
// } else {
// vm.formState.serverError = res.error;
// window.$gz.form.setErrorBoxErrors(vm);
// }
// // window.$gz.errorHandler.handleFormError(res.error, vm);
// } else {
// vm.listView = res.data.listView;
// }
// }
////////////////////
//
@@ -1116,18 +1125,18 @@ function saveFormSettings(vm) {
let unsavedlv = vm.listView;
let cachedlv = vm.listView;
if (vm.filterId == 0) {
if (vm.activeFilterId == 0) {
//we aren't using any listview
unsavedlv = undefined;
cachedlv = undefined;
}
if (vm.filterId == -1) {
if (vm.activeFilterId == -1) {
//we have an unsaved one in use so there is no need for a cached one
cachedlv = undefined;
}
if (vm.filterId > 0) {
if (vm.activeFilterId > 0) {
//we are using a saved lv so save cached one and clear anything in unsaved one
unsavedlv = undefined;
}
@@ -1136,7 +1145,10 @@ function saveFormSettings(vm) {
temp: { page: vm.dataTablePagingOptions.page, cachedListView: cachedlv },
saved: {
itemsPerPage: vm.dataTablePagingOptions.itemsPerPage,
dataTable: { filterId: vm.filterId, unsavedListView: unsavedlv }
dataTable: {
activeFilterId: vm.activeFilterId,
unsavedListView: unsavedlv
}
}
});
}
@@ -1151,31 +1163,31 @@ function loadFormSettings(vm) {
if (formSettings.saved.itemsPerPage) {
vm.dataTablePagingOptions.itemsPerPage = formSettings.saved.itemsPerPage;
}
if (formSettings.saved.dataTable.filterId != null) {
vm.filterId = formSettings.saved.dataTable.filterId;
if (formSettings.saved.dataTable.activeFilterId != null) {
vm.activeFilterId = formSettings.saved.dataTable.activeFilterId;
}
if (vm.filterId == 0) {
//default view, not unsaved and not saved
vm.listView = undefined;
}
if (vm.filterId == -1) {
//-1 is code for unsaved list view
//check if there is a local copy of a listview vm was edited but not saved
if (formSettings.saved.dataTable.unsavedListView != null) {
//add UNSAVED FILTER if -1
// if (vm.activeFilterId == 0) {
// //default view, not unsaved and not saved
// vm.listView = undefined;
// }
// if (vm.activeFilterId == -1) {
// //-1 is code for unsaved list view
// //check if there is a local copy of a listview vm was edited but not saved
// if (formSettings.saved.dataTable.unsavedListView != null) {
// //add UNSAVED FILTER if -1
vm.selectLists.savedFilters.unshift({
name: vm.$ay.t("FilterUnsaved"),
id: -1
});
// vm.selectLists.savedFilters.unshift({
// name: vm.$ay.t("FilterUnsaved"),
// id: -1
// });
vm.listView = formSettings.saved.dataTable.unsavedListView;
} else {
//filterId is for unsaved but we have no unsaved so fix that up
vm.listView = undefined;
vm.filterId = 0;
}
}
// vm.listView = formSettings.saved.dataTable.unsavedListView;
// } else {
// //activeFilterId is for unsaved but we have no unsaved so fix that up
// vm.listView = undefined;
// vm.activeFilterId = 0;
// }
// }
}
//process TEMP form settings
@@ -1184,16 +1196,16 @@ function loadFormSettings(vm) {
vm.dataTablePagingOptions.page = formSettings.temp.page;
}
//check for cached local copy of saved list view in use
if (vm.filterId > 0) {
//0=no list view, -1=unsaved list view so any number greater than zero means there sb a cached local copy of a saved list view
if (formSettings.temp && formSettings.temp.cachedListView != null) {
vm.listView = formSettings.temp.cachedListView;
} else {
//fetch it and cache it
return fetchListView(vm, vm.filterId);
}
}
// //check for cached local copy of saved list view in use
// if (vm.activeFilterId > 0) {
// //0=no list view, -1=unsaved list view so any number greater than zero means there sb a cached local copy of a saved list view
// if (formSettings.temp && formSettings.temp.cachedListView != null) {
// vm.listView = formSettings.temp.cachedListView;
// } else {
// //fetch it and cache it
// return fetchListView(vm, vm.activeFilterId);
// }
// }
}
/*//EXAMPLE FROM INTEGRATION TEST OF BETWEEN TWO DATES