From abd144721b5836ccb007beda93f8d04d04bbaec8 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 6 Mar 2019 15:10:51 +0100 Subject: [PATCH] [Major] Refresh fixes and loading overlay --- bower.json | 2 +- strolch-wc-reports-facet.html | 17 +++-- strolch-wc-reports-table.html | 23 +++++- strolch-wc-reports.html | 136 ++++++++++++++++++++++++++++++---- 4 files changed, 154 insertions(+), 24 deletions(-) diff --git a/bower.json b/bower.json index a03bd61..bee8942 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "strolch-wc-reports", "description": "Strolch WebComponent Reports", - "version": "0.1.6", + "version": "0.2.0", "authors": [ "Robert von Burg" ], diff --git a/strolch-wc-reports-facet.html b/strolch-wc-reports-facet.html index a796f53..d7d5b74 100644 --- a/strolch-wc-reports-facet.html +++ b/strolch-wc-reports-facet.html @@ -145,7 +145,7 @@ handle-as="json" method="GET" on-response="onPostFieldResponse" - on-error="onAjaxError"> + on-error="onAjaxErrorCustom"> @@ -164,8 +164,8 @@
+ debounced-input="{{searchTerm}}" + disabled="[[arrayFilled(filters)]]"> @@ -328,10 +362,12 @@ value: true }, facets: { - type: Array + type: Array, + value: [] }, reports: { - type: Array + type: Array, + value: [] }, filtersReady: { type: Boolean, @@ -363,9 +399,11 @@ }, propagateShowDialog: { type: Boolean, - value: function () { - return false - } + value: false + }, + nrOfAjaxCallsRunning: { + type: Number, + value: 0 } }, @@ -391,6 +429,41 @@ this.$.dlg.open(); }, + onAjaxErrorCustom: function (e) { + this.hideLoadingOverlay(); + this.onAjaxError(e); + }, + + onAjaxRunning: function (e) { + if (e.detail.running) { + this.showLoadingOverlay(); + } else { + this.hideLoadingOverlay(); + } + }, + + showLoadingOverlay: function () { + this.nrOfAjaxCallsRunning++; + console.log("Showing loading overlay in 150ms..."); + var that = this; + clearTimeout(this.showOverlayTimeout); + this.showOverlayTimeout = setTimeout(function () { + console.log("Showing loading overlay..."); + that.hideOverlay = false; + that.$.content.classList.add("blur"); + }, 150); + }, + hideLoadingOverlay: function () { + this.nrOfAjaxCallsRunning--; + + if (this.nrOfAjaxCallsRunning == 0) { + console.log("Hiding loading overlay..."); + clearTimeout(this.showOverlayTimeout); + this.hideOverlay = true; + this.$.content.classList.remove("blur"); + } + }, + onToggleShowFacets: function (event) { this.showFacets = !this.showFacets; }, @@ -410,6 +483,8 @@ // directly set this as the available types this.set("reports", data); + + this.hideLoadingOverlay(); }, onGetFacetResponse: function (event) { // get the response @@ -424,6 +499,9 @@ // directly set this as the available facets this.set("facets", response.data); + if (response.data.length == 0) { + this.showFacets = false; + } // show the view var that = this; @@ -432,18 +510,30 @@ restampTemplate.if = true; that.filtersReady = true; }); + + this.hideLoadingOverlay(); }, onPostCsvResponse: function (event) { var response = event.detail.response; console.log('Received CSV Result: 8'); var fileName = this.reportId + this.toDateTime(new Date()) + '.csv'; Strolch.handleAjaxFileDownload(response, fileName, 'text/csv'); + + this.hideLoadingOverlay(); }, onReportSelected: function (event) { + + // clear the previous view + var restampTemplate = this.$.restampTemplate; + restampTemplate.if = false; + this.set("allFilters", []); + this.set("facets", []); + // set the new report id this.filtersReady = false; this.set("reportId", this.reports[this.selectedReportIndex].id); this.$.ajaxGetFacets.generateRequest(); + this.showLoadingOverlay(); }, onSelectionChanged: function (event) { this.updateAllFilters(); @@ -453,13 +543,28 @@ 'Content-Type': 'application/json', 'Accept': 'text/csv' }; + + var from = this.fromDate == null || Strolch.isEmptyString(this.fromDate) ? null : new Date(this.fromDate).toISOString(); + var to = this.toDate == null || Strolch.isEmptyString(this.toDate) ? null : new Date(this.toDate).toISOString(); + this.$.ajaxPostCsv.body = { - filter: this.allFilters + filter: this.allFilters, + dateRange: { + from: from, + to: to + } }; this.$.ajaxPostCsv.generateRequest(); + this.showLoadingOverlay(); }, onRefreshTapped: function (event) { - this.$$("#table").refreshReports(); + var table = this.$$("#table"); + if (table == null) { + this.$.ajaxGetFacets.generateRequest(); + this.showLoadingOverlay(); + } else { + table.refreshReports(); + } }, onPrintTapped: function (elem) { @@ -469,6 +574,7 @@ reload: function () { this.$.ajaxGetReports.generateRequest(); + this.showLoadingOverlay(); }, /* Private */