From 4efc585f6795111a53f973cacdf9a72936f40839 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 6 Nov 2019 17:51:30 +0300 Subject: [PATCH] Images in webhooks don't have detections #387 (#393) --- .../controllers/analytic_controller.ts | 5 +++- src/panel/graph_panel/graph_ctrl.ts | 19 ++++++++---- .../graph_panel/services/analytic_service.ts | 29 ++++++++++++------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/panel/graph_panel/controllers/analytic_controller.ts b/src/panel/graph_panel/controllers/analytic_controller.ts index f19a762..0195edd 100644 --- a/src/panel/graph_panel/controllers/analytic_controller.ts +++ b/src/panel/graph_panel/controllers/analytic_controller.ts @@ -67,7 +67,10 @@ export class AnalyticController { this._labelingDataAddedSegments = new SegmentArray(); this._labelingDataRemovedSegments = new SegmentArray(); this._analyticUnitsSet = new AnalyticUnitsSet([]); - this.fetchAnalyticUnits(); + } + + async init() { + await this.fetchAnalyticUnits(); } get helpSectionText() { return helpSectionText; } diff --git a/src/panel/graph_panel/graph_ctrl.ts b/src/panel/graph_panel/graph_ctrl.ts index a46c1dd..d445152 100644 --- a/src/panel/graph_panel/graph_ctrl.ts +++ b/src/panel/graph_panel/graph_ctrl.ts @@ -250,8 +250,6 @@ class GraphCtrl extends MetricsPanelCtrl { this.$graphElem = $(elem[0]).find('#graphPanel'); this.$legendElem = $(elem[0]).find('#graphLegend'); - this.onHasticDatasourceChange(); - this.events.on('render', this.onRender.bind(this)); this.events.on('data-received', this.onDataReceived.bind(this)); this.events.on('data-error', this.onDataError.bind(this)); @@ -285,6 +283,9 @@ class GraphCtrl extends MetricsPanelCtrl { this.refresh(); } }); + + // TODO: maybe it's not the best idea + await this.onHasticDatasourceChange(); } onInitEditMode() { @@ -330,14 +331,21 @@ class GraphCtrl extends MetricsPanelCtrl { this._analyticUnitsToShow ); - this._updatePanelInfo(); - this.analyticsController.updateServerInfo(); + if(this.analyticService.isUp) { + await this.analyticsController.init(); + + this._updatePanelInfo(); + this.analyticsController.updateServerInfo(); + } this._graphRenderer = new GraphRenderer( this.$graphElem, this.timeSrv, this.contextSrv, this.$scope, this.analyticsController ); this._graphLegend = new GraphLegend(this.$legendElem, this.popoverSrv, this.$scope, this.analyticsController); - this.onRender(); + + if(!this.analyticService.isUp) { + this.refresh(); + } } issueQueries(datasource) { @@ -429,6 +437,7 @@ class GraphCtrl extends MetricsPanelCtrl { this._dataTimerange.to ); } + this.seriesList = seriesList; this.render(); diff --git a/src/panel/graph_panel/services/analytic_service.ts b/src/panel/graph_panel/services/analytic_service.ts index c6effda..64d1340 100644 --- a/src/panel/graph_panel/services/analytic_service.ts +++ b/src/panel/graph_panel/services/analytic_service.ts @@ -96,20 +96,27 @@ export class AnalyticService { return this.delete('/analyticUnits', { id }); } - private async _isDatasourceOk(): Promise { + private async _checkDatasourceAvailability(): Promise { if(!this._checkDatasourceConfig()) { this._isUp = false; - return false; + return; } - const response = await this.get('/'); - if(!isHasticServerResponse(response)) { - this.displayWrongUrlAlert(); - this._isUp = false; - } else if(!isSupportedServerVersion(response)) { - this.displayUnsupportedVersionAlert(response.packageVersion); + try { + const response = await this.get('/'); + if(!isHasticServerResponse(response)) { + this.displayWrongUrlAlert(); + this._isUp = false; + } else if(!isSupportedServerVersion(response)) { + this.displayUnsupportedVersionAlert(response.packageVersion); + this._isUp = false; + } + + this._isUp = true; + } catch(e) { + console.error(e); + this.displayNoConnectionAlert(); this._isUp = false; } - return this._isUp; } async updateSegments( @@ -240,8 +247,8 @@ export class AnalyticService { } async isDatasourceAvailable(): Promise { - const connected = await this._isDatasourceOk(); - if(!connected) { + await this._checkDatasourceAvailability(); + if(!this._isUp) { return false; } const message = [