Browse Source

Merge branch 'master' into show-progress-when-reconnecting-to-hastic-datasource-#412

master
rozetko 5 years ago
parent
commit
2afb909ecb
  1. 39
      src/panel/graph_panel/graph_ctrl.ts
  2. 24
      src/panel/graph_panel/services/analytic_service.ts

39
src/panel/graph_panel/graph_ctrl.ts

@ -338,12 +338,22 @@ class GraphCtrl extends MetricsPanelCtrl {
this._analyticUnitsToShow this._analyticUnitsToShow
); );
if(this.analyticService === undefined) {
appEvents.emit(
'alert-error',
[
'Select Hastic datasource',
'Panel config -> Visualization'
]
);
} else {
if(this.analyticService.isUp) { if(this.analyticService.isUp) {
await this.analyticsController.init(); await this.analyticsController.init();
this._updatePanelInfo(); this._updatePanelInfo();
this.analyticsController.updateServerInfo(); this.analyticsController.updateServerInfo();
} }
}
this._graphRenderer = new GraphRenderer( this._graphRenderer = new GraphRenderer(
this.$graphElem, this.timeSrv, this.contextSrv, this.$scope, this.analyticsController this.$graphElem, this.timeSrv, this.contextSrv, this.$scope, this.analyticsController
@ -582,12 +592,37 @@ class GraphCtrl extends MetricsPanelCtrl {
panelId: string, panelId: string,
datasourceUrl: string datasourceUrl: string
) => { ) => {
// TODO: use template variables from form try {
// TODO: use template variables from form (or not?)
await this.importPanel(JSON.parse(panelTemplate), { await this.importPanel(JSON.parse(panelTemplate), {
grafanaUrl: this._grafanaUrl, grafanaUrl: this._grafanaUrl,
panelId: this._panelId, panelId: this._panelId,
datasourceUrl: this._datasourceRequest.url datasourceUrl: this._datasourceRequest.url
}); });
appEvents.emit(
'alert-success',
[
// TODO: analytic units count?
'Analytic units are imported successfully'
]
);
await this.onHasticDatasourceChange();
} catch(e) {
let status = e.status !== undefined ? `Status code: ${e.status}` : '';
let message = e.message;
if(e.data !== undefined && e.data.message !== undefined) {
message = e.data.message;
}
appEvents.emit(
'alert-error',
[
`Error while importing analytic units. ${status}`,
message
]
);
}
}; };
this.publishAppEvent('show-modal', { this.publishAppEvent('show-modal', {
@ -598,7 +633,7 @@ class GraphCtrl extends MetricsPanelCtrl {
async importPanel(panelTemplate: PanelTemplate, templateVariables: TemplateVariables): Promise<void> { async importPanel(panelTemplate: PanelTemplate, templateVariables: TemplateVariables): Promise<void> {
// TODO: show import errors properly // TODO: show import errors properly
await this.analyticsController.importPanel(panelTemplate, templateVariables); return this.analyticsController.importPanel(panelTemplate, templateVariables);
} }
// getAnnotationsByTag(tag) { // getAnnotationsByTag(tag) {

24
src/panel/graph_panel/services/analytic_service.ts

@ -80,7 +80,8 @@ export class AnalyticService {
panelTemplate: PanelTemplate, panelTemplate: PanelTemplate,
templateVariables: TemplateVariables templateVariables: TemplateVariables
): Promise<void> { ): Promise<void> {
await this.post('/panels/template', { panelTemplate, templateVariables }); const rawError = true;
return this.post('/panels/template', { panelTemplate, templateVariables }, rawError);
} }
async postNewAnalyticUnit( async postNewAnalyticUnit(
@ -291,7 +292,7 @@ export class AnalyticService {
return this.post('/analyticUnits/detect', { ids, from, to }); return this.post('/analyticUnits/detect', { ids, from, to });
} }
private async _analyticRequest(method: string, url: string, data?: any) { private async _analyticRequest(method: string, url: string, data?: any, rawError: boolean = false) {
try { try {
method = method.toUpperCase(); method = method.toUpperCase();
url = this._hasticDatasourceURL + url; url = this._hasticDatasourceURL + url;
@ -305,6 +306,9 @@ export class AnalyticService {
this._isUp = true; this._isUp = true;
return response.data; return response.data;
} catch(error) { } catch(error) {
if(rawError) {
throw error;
}
// xhrStatus may be one of: ('complete', 'error', 'timeout' or 'abort') // xhrStatus may be one of: ('complete', 'error', 'timeout' or 'abort')
// See: https://github.com/angular/angular.js/blob/55075b840c9194b8524627a293d6166528b9a1c2/src/ng/http.js#L919-L920 // See: https://github.com/angular/angular.js/blob/55075b840c9194b8524627a293d6166528b9a1c2/src/ng/http.js#L919-L920
if(error.xhrStatus !== 'complete' || error.status > 500) { if(error.xhrStatus !== 'complete' || error.status > 500) {
@ -345,20 +349,20 @@ export class AnalyticService {
return true; return true;
} }
private async get(url, params?) { private async get(url: string, params?: any, rawError: boolean = false): Promise<any> {
return this._analyticRequest('GET', url, params); return this._analyticRequest('GET', url, params, rawError);
} }
private async post(url, data?) { private async post(url: string, data?: any, rawError: boolean = false): Promise<any> {
return this._analyticRequest('POST', url, data); return this._analyticRequest('POST', url, data, rawError);
} }
private async patch(url, data?) { private async patch(url: string, data?: any, rawError: boolean = false): Promise<any> {
return this._analyticRequest('PATCH', url, data); return this._analyticRequest('PATCH', url, data, rawError);
} }
private async delete(url, data?) { private async delete(url: string, data?: any, rawError: boolean = false): Promise<any> {
return this._analyticRequest('DELETE', url, data); return this._analyticRequest('DELETE', url, data, rawError);
} }
private _displayNoConnectionAlert(statusText: string): void { private _displayNoConnectionAlert(statusText: string): void {

Loading…
Cancel
Save