Browse Source

AlertSrv is deprecated in Grafana 5.4+ #137 (#138)

master
rozetko 6 years ago committed by GitHub
parent
commit
dd9ef7128e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      src/module.ts
  2. 17
      src/services/analytic_service.ts

35
src/module.ts

@ -145,8 +145,7 @@ class GraphCtrl extends MetricsPanelCtrl {
private keybindingSrv, private keybindingSrv,
private backendSrv: BackendSrv, private backendSrv: BackendSrv,
private popoverSrv, private popoverSrv,
private contextSrv, private contextSrv
private alertSrv: AlertSrv
) { ) {
super($scope, $injector); super($scope, $injector);
@ -157,7 +156,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.processor = new DataProcessor(this.panel); this.processor = new DataProcessor(this.panel);
this.analyticService = new AnalyticService(this.backendURL, $http, this.backendSrv, this.alertSrv); this.analyticService = new AnalyticService(this.backendURL, $http);
this.runBackendConnectivityCheck(); this.runBackendConnectivityCheck();
@ -227,10 +226,12 @@ class GraphCtrl extends MetricsPanelCtrl {
async runBackendConnectivityCheck() { async runBackendConnectivityCheck() {
if(this.backendURL === '' || this.backendURL === undefined) { if(this.backendURL === '' || this.backendURL === undefined) {
this.alertSrv.set( appEvents.emit(
`Dashboard variable $${BACKEND_VARIABLE_NAME} is missing`, 'alert-warning',
`Please set $${BACKEND_VARIABLE_NAME}`, [
'warning', 4000 `Dashboard variable $${BACKEND_VARIABLE_NAME} is missing`,
`Please set $${BACKEND_VARIABLE_NAME}`
]
); );
return; return;
} }
@ -238,10 +239,12 @@ class GraphCtrl extends MetricsPanelCtrl {
let connected = await this.analyticService.isBackendOk(); let connected = await this.analyticService.isBackendOk();
if(connected) { if(connected) {
this.updateAnalyticUnitTypes(); this.updateAnalyticUnitTypes();
this.alertSrv.set( appEvents.emit(
'Connected to Hastic server', 'alert-success',
`Hastic server: "${this.backendURL}"`, [
'success', 4000 'Connected to Hastic server',
`Hastic server: "${this.backendURL}"`
]
); );
} }
} }
@ -516,10 +519,12 @@ class GraphCtrl extends MetricsPanelCtrl {
panelUrl panelUrl
); );
} catch(e) { } catch(e) {
this.alertSrv.set( appEvents.emit(
'Error while saving analytic unit', 'alert-error',
e.message, [
'error', 7000 'Error while saving analytic unit',
e.message
]
); );
} }
this.$scope.$digest(); this.$scope.$digest();

17
src/services/analytic_service.ts

@ -5,8 +5,7 @@ import { SegmentsSet } from '../models/segment_set';
import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit'; import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit';
import { ServerInfo } from '../models/info'; import { ServerInfo } from '../models/info';
import { Threshold } from '../models/threshold'; import { Threshold } from '../models/threshold';
import { BackendSrv } from 'grafana/app/core/services/backend_srv'; import { appEvents } from 'grafana/app/core/core';
import { AlertSrv } from 'grafana/app/core/services/alert_srv';
export class AnalyticService { export class AnalyticService {
@ -14,9 +13,7 @@ export class AnalyticService {
constructor( constructor(
private _backendURL: string, private _backendURL: string,
private $http, private $http
private _backendSrv: BackendSrv,
private _alertSrv: AlertSrv
) { ) {
this.isBackendOk(); this.isBackendOk();
} }
@ -202,10 +199,12 @@ export class AnalyticService {
} }
private displayConnectionAlert() { private displayConnectionAlert() {
this._alertSrv.set( appEvents.emit(
'No connection to Hastic server', 'alert-success',
`Hastic server: "${this._backendURL}"`, [
'warning', 4000 'No connection to Hastic server',
`Hastic server: "${this._backendURL}"`,
]
); );
} }

Loading…
Cancel
Save