From d198bea6136f82a9805ccb300da51c14cbc83d6d Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 1 Feb 2021 17:52:20 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 8 +------- ayanova/src/api/gzutil.js | 18 ++++++++++++++++++ ayanova/src/components/data-table.vue | 19 ++++++++++++++++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index ef556ce4..81c46e5d 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -149,13 +149,7 @@ todo: filter, can be programmatic or user, user saves, can choose from list TODO: LIST VIEW REPLACMENT OUTSTANDING TO DO Client fixup <---= CURRENTLY HERE WHERE IT"S AT: - listcolumnview form works but has issues: - un translated title - Items don't stay in their location when set to not include and saved - not sure if this is a problem or just necessary but it's jarring as is different than before, maybe better though as all visible are at the top?? - figure it out! - icon is filter need to pick new icon for data-list-column-view - "view" related stuff? Something that looks like columns? + Fixup client so existing client works with new filter and sort system *before* porting UI diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index 4b4f1d29..2468c1ef 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -639,6 +639,24 @@ export default { return ret; }, /////////////////////////////////////////////// + // Simple array equality comparison + // (will NOT work on arrays of objects) + isEqualArraysOfPrimitives: function(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length !== b.length) return false; + + // If you don't care about the order of the elements inside + // the array, you should sort both arrays here. + // Please note that calling sort on an array will modify that array. + // you might want to clone your array first. + + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + return true; + }, + /////////////////////////////////////////////// // Use geolocation api to attempt to get current location // try high accuracy first and downgrade if unavailable //https://www.openstreetmap.org/?mlat=48.3911&mlon=-124.7353#map=12/48.3910/-124.7353 diff --git a/ayanova/src/components/data-table.vue b/ayanova/src/components/data-table.vue index 43876fff..b2785da1 100644 --- a/ayanova/src/components/data-table.vue +++ b/ayanova/src/components/data-table.vue @@ -436,16 +436,33 @@ export default { //{ "page": 1, "itemsPerPage": 10, "sortBy": [], "sortDesc": [], "groupBy": [], "groupDesc": [], "mustSort": false, "multiSort": false } //this code works around some weird bug that causes visible items to be selected in grid (only, not in actual selected array, just a visual thing) // when breakpoint is switched between wide and narrow either way. No idea why it happens but this fixes that issue and also ensures that there are no + //spurious fetches happening just because the view has changed + //See what has changed and record it for processing + let sortHasChanged = !( + window.$gz.util.isEqualArraysOfPrimitives( + this.dataTablePagingOptions.sortBy, + this.lastDataTablePagingOptions.sortBy + ) && + window.$gz.util.isEqualArraysOfPrimitives( + this.dataTablePagingOptions.sortDesc, + this.lastDataTablePagingOptions.sortDesc + ) + ); + if ( this.lastDataTablePagingOptions.page == this.dataTablePagingOptions.page && this.lastDataTablePagingOptions.itemsPerPage == - this.dataTablePagingOptions.itemsPerPage + this.dataTablePagingOptions.itemsPerPage && + !sortHasChanged ) { //no effective change, return + console.log("NO CHANGE"); return; } + console.log("Has changed"); + //has changed something important so refetch and put a pin in last paging settings for next time this.getDataFromApi(); this.lastDataTablePagingOptions = this.dataTablePagingOptions;