|
|
@ -12,12 +12,15 @@ import { BOUND_TYPES } from './models/analytic_units/anomaly_analytic_unit'; |
|
|
|
import { AnalyticService } from './services/analytic_service'; |
|
|
|
import { AnalyticService } from './services/analytic_service'; |
|
|
|
import { AnalyticController } from './controllers/analytic_controller'; |
|
|
|
import { AnalyticController } from './controllers/analytic_controller'; |
|
|
|
import { HasticPanelInfo } from './models/hastic_panel_info'; |
|
|
|
import { HasticPanelInfo } from './models/hastic_panel_info'; |
|
|
|
|
|
|
|
import { PanelTemplate, TemplateVariables } from './models/panel'; |
|
|
|
import { axesEditorComponent } from './axes_editor'; |
|
|
|
import { axesEditorComponent } from './axes_editor'; |
|
|
|
|
|
|
|
|
|
|
|
import { MetricsPanelCtrl } from 'grafana/app/plugins/sdk'; |
|
|
|
import { MetricsPanelCtrl } from 'grafana/app/plugins/sdk'; |
|
|
|
import { appEvents } from 'grafana/app/core/core' |
|
|
|
import { appEvents } from 'grafana/app/core/core' |
|
|
|
import { BackendSrv } from 'grafana/app/core/services/backend_srv'; |
|
|
|
import { BackendSrv } from 'grafana/app/core/services/backend_srv'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import angular from 'angular'; |
|
|
|
|
|
|
|
|
|
|
|
import _ from 'lodash'; |
|
|
|
import _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -65,6 +68,8 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
to?: number |
|
|
|
to?: number |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public panelTemplate: PanelTemplate = {}; |
|
|
|
|
|
|
|
|
|
|
|
panelDefaults = { |
|
|
|
panelDefaults = { |
|
|
|
// datasource name, null = default datasource
|
|
|
|
// datasource name, null = default datasource
|
|
|
|
datasource: null, |
|
|
|
datasource: null, |
|
|
@ -305,7 +310,8 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
onInitPanelActions(actions: { text: string, click: string }[]): void { |
|
|
|
onInitPanelActions(actions: { text: string, click: string }[]): void { |
|
|
|
actions.push({ text: 'Export CSV', click: 'ctrl.exportCsv()' }); |
|
|
|
actions.push({ text: 'Export CSV', click: 'ctrl.exportCsv()' }); |
|
|
|
actions.push({ text: 'Toggle legend', click: 'ctrl.toggleLegend()' }); |
|
|
|
actions.push({ text: 'Toggle legend', click: 'ctrl.toggleLegend()' }); |
|
|
|
actions.push({ text: 'Export analytic units', click: 'ctrl.exportAnalyticUnits()' }); |
|
|
|
actions.push({ text: 'Export analytic units', click: 'ctrl.exportPanel()' }); |
|
|
|
|
|
|
|
actions.push({ text: 'Import analytic units', click: 'ctrl.displayImportPanelModal()' }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async onHasticDatasourceChange() { |
|
|
|
async onHasticDatasourceChange() { |
|
|
@ -553,14 +559,44 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async exportAnalyticUnits(): Promise<void> { |
|
|
|
async exportPanel(): Promise<void> { |
|
|
|
const json = await this.analyticsController.exportAnalyticUnits(); |
|
|
|
const panelTemplate = await this.analyticsController.exportPanel(); |
|
|
|
this.publishAppEvent('show-modal', { |
|
|
|
this.publishAppEvent('show-modal', { |
|
|
|
src: 'public/app/partials/edit_json.html', |
|
|
|
src: 'public/app/partials/edit_json.html', |
|
|
|
model: { object: json, enableCopy: true } |
|
|
|
model: { object: panelTemplate, enableCopy: true } |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async displayImportPanelModal(): Promise<void> { |
|
|
|
|
|
|
|
const modalScope = this.$scope.$new(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const prettify = true; |
|
|
|
|
|
|
|
modalScope.panelTemplate = angular.toJson({}, prettify); |
|
|
|
|
|
|
|
modalScope.import = async ( |
|
|
|
|
|
|
|
panelTemplate: string, |
|
|
|
|
|
|
|
grafanaUrl: string, |
|
|
|
|
|
|
|
panelId: string, |
|
|
|
|
|
|
|
datasourceUrl: string |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
// TODO: use template variables from form
|
|
|
|
|
|
|
|
await this.importPanel(JSON.parse(panelTemplate), { |
|
|
|
|
|
|
|
grafanaUrl: this._grafanaUrl, |
|
|
|
|
|
|
|
panelId: this._panelId, |
|
|
|
|
|
|
|
datasourceUrl: this._datasourceRequest.url |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.publishAppEvent('show-modal', { |
|
|
|
|
|
|
|
src: `${this.partialsPath}/import_panel.html`, |
|
|
|
|
|
|
|
scope: modalScope |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async importPanel(panelTemplate: PanelTemplate, templateVariables: TemplateVariables): Promise<void> { |
|
|
|
|
|
|
|
// TODO: show import errors properly
|
|
|
|
|
|
|
|
await this.analyticsController.importPanel(panelTemplate, templateVariables); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// getAnnotationsByTag(tag) {
|
|
|
|
// getAnnotationsByTag(tag) {
|
|
|
|
// var res = [];
|
|
|
|
// var res = [];
|
|
|
|
// for (var annotation of this.annotations) {
|
|
|
|
// for (var annotation of this.annotations) {
|
|
|
|