diff --git a/src/panel/graph_panel/controllers/analytic_controller.ts b/src/panel/graph_panel/controllers/analytic_controller.ts index e11ee5f..4da6805 100644 --- a/src/panel/graph_panel/controllers/analytic_controller.ts +++ b/src/panel/graph_panel/controllers/analytic_controller.ts @@ -220,8 +220,8 @@ export class AnalyticController { this.analyticUnits.forEach(a => this._runStatusWaiter(a)); } - fetchAnalyticUnitsDetections(from: number | null, to: number | null) { - if(from === null || to === null) { + fetchAnalyticUnitsDetections(from?: number, to?: number) { + if(from === undefined || to === undefined) { return; } this.analyticUnits.forEach(analyticUnit => { @@ -309,7 +309,9 @@ export class AnalyticController { async redetectAll() { this.analyticUnits.forEach(unit => { + // TODO: remove duplication with runDetect unit.segments.clear(); + unit.detectionSpans = []; unit.status = null; }); const ids = this.analyticUnits.map(analyticUnit => analyticUnit.id); @@ -318,12 +320,13 @@ export class AnalyticController { _.each(this.analyticUnits, analyticUnit => this._runStatusWaiter(analyticUnit)); } - async runDetect(analyticUnitId: AnalyticUnitId) { + async runDetect(analyticUnitId: AnalyticUnitId, from?: number, to?: number) { const analyticUnit = this._analyticUnitsSet.byId(analyticUnitId); analyticUnit.segments.clear(); + analyticUnit.detectionSpans = []; analyticUnit.status = null; await this.saveAnalyticUnit(analyticUnit); - await this._analyticService.runDetect(analyticUnitId); + await this._analyticService.runDetect(analyticUnitId, from, to); this._runStatusWaiter(analyticUnit); } diff --git a/src/panel/graph_panel/graph_ctrl.ts b/src/panel/graph_panel/graph_ctrl.ts index fd20df1..246fdde 100644 --- a/src/panel/graph_panel/graph_ctrl.ts +++ b/src/panel/graph_panel/graph_ctrl.ts @@ -59,8 +59,8 @@ class GraphCtrl extends MetricsPanelCtrl { private _panelId: string; private _dataTimerange: { - from: number, - to: number + from?: number, + to?: number }; panelDefaults = { @@ -273,10 +273,8 @@ class GraphCtrl extends MetricsPanelCtrl { await this.analyticsController.removeAnalyticUnit(analyticUnit.id, true); } if(analyticUnit.status === 'READY') { - if(this.range === undefined) { - this.updateTimeRange(); - } - await this.analyticsController.fetchSegments(analyticUnit, +this.range.from, +this.range.to); + const { from, to } = this.rangeTimestamp; + await this.analyticsController.fetchSegments(analyticUnit, from, to); } this.render(this.seriesList); this.$scope.$digest(); @@ -372,8 +370,7 @@ class GraphCtrl extends MetricsPanelCtrl { this.dataList = dataList; this.loading = true; - const from = +this.range.from; - const to = +this.range.to; + const { from, to } = this.rangeTimestamp; if(this.analyticsController !== undefined) { const hsrSeries = await this.analyticsController.getHSRSeries(from, to); @@ -432,10 +429,9 @@ class GraphCtrl extends MetricsPanelCtrl { const from = _.find(series.datapoints, datapoint => datapoint[0] !== null); const to = _.findLast(series.datapoints, datapoint => datapoint[0] !== null); + this._dataTimerange = {}; if(from !== undefined && to !== undefined) { this._dataTimerange = { from: from[1], to: to[1] }; - } else { - this._dataTimerange = { from: null, to: null } } if (series.unit) { @@ -580,8 +576,13 @@ class GraphCtrl extends MetricsPanelCtrl { this.analyticsController.redetectAll(); } - async runDetect(analyticUnitId: AnalyticUnitId) { - this.analyticsController.runDetect(analyticUnitId); + async runDetectInCurrentRange(analyticUnitId: AnalyticUnitId) { + const { from, to } = this.rangeTimestamp; + + this.analyticsController.runDetect( + analyticUnitId, + from, to + ); } async saveNew() { @@ -734,6 +735,17 @@ class GraphCtrl extends MetricsPanelCtrl { this.$scope.$digest(); } + get rangeTimestamp(): { from: number, to: number } { + if(this.range === undefined) { + this.updateTimeRange(); + } + + return { + from: +this.range.from, + to: +this.range.to + }; + } + get hasticDatasources() { return this._hasticDatasources; } diff --git a/src/panel/graph_panel/partials/tab_analytics.html b/src/panel/graph_panel/partials/tab_analytics.html index 72c37bc..b7e9da1 100644 --- a/src/panel/graph_panel/partials/tab_analytics.html +++ b/src/panel/graph_panel/partials/tab_analytics.html @@ -113,7 +113,7 @@