From d980e7c21e5bf1715ce6a1c4c9bad2c02d8fe895 Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 17 Jan 2019 20:31:30 +0300 Subject: [PATCH] Send metric configuration after labeling #121 hotfix --- src/controllers/analytic_controller.ts | 4 ++-- src/module.ts | 10 ++++++++-- src/services/analytic_service.ts | 11 +++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 8828b7e..c7795bd 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -89,10 +89,10 @@ export class AnalyticController { } } - async saveNew(panelUrl: string) { + async saveNew(metric: MetricExpanded, datasource: DatasourceRequest, panelUrl: string) { this._savingNewAnalyticUnit = true; this._newAnalyticUnit.id = await this._analyticService.postNewItem( - this._newAnalyticUnit, panelUrl + this._newAnalyticUnit, metric, datasource, panelUrl ); if(this._newAnalyticUnit.detectorType === 'threshold') { await this.saveThreshold(this._newAnalyticUnit.id); diff --git a/src/module.ts b/src/module.ts index 7f654df..7a11634 100644 --- a/src/module.ts +++ b/src/module.ts @@ -34,7 +34,7 @@ class GraphCtrl extends MetricsPanelCtrl { // annotations: any = []; private _datasourceRequest: DatasourceRequest; - private _datasources: any; + private _datasources: any; private _panelPath: any; private _renderError: boolean = false; @@ -509,7 +509,13 @@ class GraphCtrl extends MetricsPanelCtrl { const panelId = this.panel.id; const panelUrl = window.location.origin + window.location.pathname + `?panelId=${panelId}`; - await this.analyticsController.saveNew(panelUrl); + const datasource = await this._getDatasourceRequest(); + + await this.analyticsController.saveNew( + new MetricExpanded(this.panel.datasource, this.panel.targets), + datasource, + panelUrl + ); } catch(e) { this.alertSrv.set( 'Error while saving analytic unit', diff --git a/src/services/analytic_service.ts b/src/services/analytic_service.ts index da3a111..c24348f 100644 --- a/src/services/analytic_service.ts +++ b/src/services/analytic_service.ts @@ -34,11 +34,18 @@ export class AnalyticService { return await this.patch('/threshold', threshold); } - async postNewItem(newItem: AnalyticUnit, panelUrl: string): Promise { + async postNewItem( + newItem: AnalyticUnit, + metric: MetricExpanded, + datasource: DatasourceRequest, + panelUrl: string + ): Promise { const response = await this.post('/analyticUnits', { panelUrl, type: newItem.type, - name: newItem.name + name: newItem.name, + metric: metric.toJSON(), + datasource }); return response.id as AnalyticUnitId;