diff --git a/src/panel/graph_panel/controllers/analytic_controller.ts b/src/panel/graph_panel/controllers/analytic_controller.ts index 992fa8b..be97de1 100644 --- a/src/panel/graph_panel/controllers/analytic_controller.ts +++ b/src/panel/graph_panel/controllers/analytic_controller.ts @@ -115,9 +115,6 @@ export class AnalyticController { this._analyticUnitsSet.addItem(this._newAnalyticUnit); this._creatingNewAnalyticType = false; this._savingNewAnalyticUnit = false; - if(this._newAnalyticUnit.detectorType !== 'threshold') { - this._runStatusWaiter(this._newAnalyticUnit); - } } get creatingNew() { return this._creatingNewAnalyticType; } @@ -134,7 +131,7 @@ export class AnalyticController { return this._analyticUnitsSet.byId(this._selectedAnalyticUnitId); } - async toggleUnitTypeLabelingMode(id: AnalyticUnitId, metric: MetricExpanded, datasource: DatasourceRequest) { + async toggleAnalyticUnitLabelingMode(id: AnalyticUnitId, metric: MetricExpanded, datasource: DatasourceRequest) { this._currentMetric = metric; this._currentDatasource = datasource; @@ -148,7 +145,6 @@ export class AnalyticController { this._selectedAnalyticUnitId = id; this.labelingUnit.selected = true; this.toggleLabelingMode(LabelingMode.LABELING); - this.toggleVisibility(id, true); } async disableLabeling() { @@ -277,12 +273,15 @@ export class AnalyticController { return newIds; } - redetectAll() { - this.analyticUnits.forEach(a => { - a.segments.clear(); - this._runStatusWaiter(a); - this._analyticService.runDetect(a.id); + async redetectAll() { + this.analyticUnits.forEach(unit => { + unit.segments.clear(); + unit.status = null; }); + const ids = this.analyticUnits.map(analyticUnit => analyticUnit.id); + await this._analyticService.runDetect(ids); + + _.each(this.analyticUnits, analyticUnit => this._runStatusWaiter(analyticUnit)); } // TODO: move to renderer diff --git a/src/panel/graph_panel/graph_ctrl.ts b/src/panel/graph_panel/graph_ctrl.ts index 985b9f5..65eed42 100644 --- a/src/panel/graph_panel/graph_ctrl.ts +++ b/src/panel/graph_panel/graph_ctrl.ts @@ -161,7 +161,6 @@ class GraphCtrl extends MetricsPanelCtrl { // because of https://github.com/hastic/hastic-grafana-app/issues/162 this.events.on('init-edit-mode', this.onInitEditMode.bind(this)); - const grafanaUrlRegex = /^(.+)\/d/; const parsedUrl = window.location.href.match(grafanaUrlRegex); if(parsedUrl !== null) { @@ -171,6 +170,7 @@ class GraphCtrl extends MetricsPanelCtrl { } this._panelId = `${this.dashboard.uid}/${this.panel.id}`; + this._datasources = {}; } rebindKeys() { @@ -201,6 +201,9 @@ class GraphCtrl extends MetricsPanelCtrl { const hasticDatasourceId = this.panel.hasticDatasource; if(hasticDatasourceId !== undefined && hasticDatasourceId !== null) { const hasticDatasource = _.find(this._hasticDatasources, { id: hasticDatasourceId }); + if(hasticDatasource === undefined) { + return undefined; + } let url = hasticDatasource.url; if(hasticDatasource.access === 'proxy') { url = `api/datasources/proxy/${hasticDatasource.id}`; @@ -247,8 +250,6 @@ class GraphCtrl extends MetricsPanelCtrl { } async link(scope, elem, attrs, ctrl) { - this._datasources = {}; - this.$graphElem = $(elem[0]).find('#graphPanel'); this.$legendElem = $(elem[0]).find('#graphLegend'); @@ -314,7 +315,7 @@ class GraphCtrl extends MetricsPanelCtrl { this.processor = new DataProcessor(this.panel); await this._fetchHasticDatasources(); - let hasticDatasource = this.hasticDatasource; + const hasticDatasource = this.getHasticDatasource(); if(hasticDatasource === undefined) { delete this.analyticService; } else { @@ -638,7 +639,7 @@ class GraphCtrl extends MetricsPanelCtrl { this.refresh(); const datasource = await this._getDatasourceRequest(); const metric = new MetricExpanded(this.panel.datasource, this.panel.targets); - await this.analyticsController.toggleUnitTypeLabelingMode(id, metric, datasource); + await this.analyticsController.toggleAnalyticUnitLabelingMode(id, metric, datasource); this.$scope.$digest(); this.render(); } @@ -681,7 +682,7 @@ class GraphCtrl extends MetricsPanelCtrl { grafanaUrl: window.location.host, datasourceName: datasource === undefined ? 'unknown' : datasource.name, datasourceType: datasource === undefined ? 'unknown' : datasource.type, - hasticDatasourceName: datasource === undefined ? 'unknown' : hasticDatasource.name, + hasticDatasourceName: hasticDatasource === undefined || datasource === undefined ? 'unknown' : hasticDatasource.name, hasticDatasourceUrl: hasticDatasource === undefined ? 'unknown' : hasticDatasource.url }; } diff --git a/src/panel/graph_panel/models/analytic_unit.ts b/src/panel/graph_panel/models/analytic_unit.ts index 1dfb366..5c2e219 100644 --- a/src/panel/graph_panel/models/analytic_unit.ts +++ b/src/panel/graph_panel/models/analytic_unit.ts @@ -120,7 +120,8 @@ export class AnalyticUnit { value !== 'READY' && value !== 'LEARNING' && value !== 'PENDING' && - value !== 'FAILED' + value !== 'FAILED' && + value !== null ) { throw new Error('Unsupported status value: ' + value); } diff --git a/src/panel/graph_panel/partials/tab_analytics.html b/src/panel/graph_panel/partials/tab_analytics.html index 3cfcc2c..2cbee49 100644 --- a/src/panel/graph_panel/partials/tab_analytics.html +++ b/src/panel/graph_panel/partials/tab_analytics.html @@ -159,6 +159,7 @@