From 8f1f07dee4fed513ef1f91456bd521efc48bdfe3 Mon Sep 17 00:00:00 2001 From: DiegoAMS Date: Tue, 6 Oct 2020 11:31:00 +0200 Subject: [PATCH] Add progress bar on click microflow --- src/ChartJS/widgets/BarChart/BarChart.xml | 15 +++++++ src/ChartJS/widgets/Core.js | 43 +++++++++++++++++-- .../widgets/DoughnutChart/DoughnutChart.xml | 15 +++++++ .../HorizontalBarChart/HorizontalBarChart.xml | 15 +++++++ src/ChartJS/widgets/LineChart/LineChart.xml | 15 +++++++ src/ChartJS/widgets/PieChart/PieChart.xml | 15 +++++++ src/ChartJS/widgets/PolarChart/PolarChart.xml | 15 +++++++ src/ChartJS/widgets/RadarChart/RadarChart.xml | 15 +++++++ .../StackedBarChart/StackedBarChart.xml | 15 +++++++ 9 files changed, 159 insertions(+), 4 deletions(-) diff --git a/src/ChartJS/widgets/BarChart/BarChart.xml b/src/ChartJS/widgets/BarChart/BarChart.xml index 544f4ec..f8d57ca 100644 --- a/src/ChartJS/widgets/BarChart/BarChart.xml +++ b/src/ChartJS/widgets/BarChart/BarChart.xml @@ -236,6 +236,21 @@ Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/Core.js b/src/ChartJS/widgets/Core.js index f40c715..dfabb32 100644 --- a/src/ChartJS/widgets/Core.js +++ b/src/ChartJS/widgets/Core.js @@ -37,6 +37,8 @@ export default defineWidget('Core', template, { // Set in the modeler responsiveRatio: 0, + progressBarType: "none", + microflowProgressString: "Loading", // Internal variables _chartJS: null, @@ -70,7 +72,6 @@ export default defineWidget('Core', template, { startup() { this.log('startup'); - // Activate chartJS (and clone it, making sure globals are not overwritten for other instances). this._chartJS = clone(ChartJS); @@ -330,6 +331,40 @@ export default defineWidget('Core', template, { this._ctx = this.canvasNode.getContext('2d'); }, + _executeWithProgress(microflow, guid, cb, errCb) { + // Wrap original function to add progress bar to all calls. + let callback = cb, errorCallback = errCb; + if ("blocking" === this.progressBarType || "regular" === this.progressBarType) { + this._progressId = mx.ui.showProgress(this.microflowProgressString || "", "blocking" === this.progressBarType); + callback = this._wrapCallback(cb); + errorCallback = this._wrapCallback(errCb); + } + this._execute(microflow, guid, callback, errorCallback); + }, + + _wrapCallback(cb) { + let callback = null; + if ("function" === typeof cb) { + callback = () => { + cb && cb(); + this._hideProgress(); + }; + } else { + callback = () => { + this._hideProgress(); + }; + } + return callback; + }, + + _hideProgress() { + if (null !== this._progressId) { + this.log("Hide progress"); + mx.ui.hideProgress(this._progressId); + this._progressId = null; + } + }, + _processData() { this.log('_processData needs to be replaced'); }, @@ -356,16 +391,16 @@ export default defineWidget('Core', template, { datasetObject = this._activeDatasets[ pointIndex ].obj; } - this._execute(this.onclickDataSetMf, datasetObject && datasetObject.getGuid()); + this._executeWithProgress(this.onclickDataSetMf, datasetObject && datasetObject.getGuid()); } if (this.onclickDataPointMf && dataPointObject) { - this._execute(this.onclickDataPointMf, dataPointObject && dataPointObject.getGuid()); + this._executeWithProgress(this.onclickDataPointMf, dataPointObject && dataPointObject.getGuid()); } } if (this.onclickmf) { - this._execute(this.onclickmf, this._mxObj && this._mxObj.getGuid()); + this._executeWithProgress(this.onclickmf, this._mxObj && this._mxObj.getGuid()); } }, diff --git a/src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml b/src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml index 9703423..7bdf77c 100644 --- a/src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml +++ b/src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml @@ -205,6 +205,21 @@ Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/HorizontalBarChart/HorizontalBarChart.xml b/src/ChartJS/widgets/HorizontalBarChart/HorizontalBarChart.xml index 1cc150a..5a2a854 100644 --- a/src/ChartJS/widgets/HorizontalBarChart/HorizontalBarChart.xml +++ b/src/ChartJS/widgets/HorizontalBarChart/HorizontalBarChart.xml @@ -236,6 +236,21 @@ Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/LineChart/LineChart.xml b/src/ChartJS/widgets/LineChart/LineChart.xml index e7c285b..4272084 100644 --- a/src/ChartJS/widgets/LineChart/LineChart.xml +++ b/src/ChartJS/widgets/LineChart/LineChart.xml @@ -255,6 +255,21 @@ Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/PieChart/PieChart.xml b/src/ChartJS/widgets/PieChart/PieChart.xml index 0d07131..8c8378a 100644 --- a/src/ChartJS/widgets/PieChart/PieChart.xml +++ b/src/ChartJS/widgets/PieChart/PieChart.xml @@ -207,6 +207,21 @@ Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/PolarChart/PolarChart.xml b/src/ChartJS/widgets/PolarChart/PolarChart.xml index 8548e38..bef4fb9 100644 --- a/src/ChartJS/widgets/PolarChart/PolarChart.xml +++ b/src/ChartJS/widgets/PolarChart/PolarChart.xml @@ -197,6 +197,21 @@ + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/RadarChart/RadarChart.xml b/src/ChartJS/widgets/RadarChart/RadarChart.xml index f6625ed..1f28ae3 100644 --- a/src/ChartJS/widgets/RadarChart/RadarChart.xml +++ b/src/ChartJS/widgets/RadarChart/RadarChart.xml @@ -233,6 +233,21 @@ Note: This is experimental. In case of non-persistent objects this should not be Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior diff --git a/src/ChartJS/widgets/StackedBarChart/StackedBarChart.xml b/src/ChartJS/widgets/StackedBarChart/StackedBarChart.xml index 20db134..c695eb9 100644 --- a/src/ChartJS/widgets/StackedBarChart/StackedBarChart.xml +++ b/src/ChartJS/widgets/StackedBarChart/StackedBarChart.xml @@ -236,6 +236,21 @@ Microflow to invoke when chart canvas is clicked + + Progress bar + Behavior + Type of progress bar to show when executing a microflow + + None + Blocking + Regular + + + + Progress message + Behavior + Progress bar text to display when executing a microflow + On Click Dataset Microflow Behavior