2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import coreModule from 'app/core/core_module';
|
2019-02-04 04:19:45 -06:00
|
|
|
import { DashboardModel } from 'app/features/dashboard/state';
|
2019-08-01 07:38:34 -05:00
|
|
|
import DatasourceSrv from '../plugins/datasource_srv';
|
2019-09-04 07:00:37 -05:00
|
|
|
import appEvents from 'app/core/app_events';
|
2016-09-08 04:25:45 -05:00
|
|
|
|
|
|
|
export class AnnotationsEditorCtrl {
|
|
|
|
mode: any;
|
|
|
|
datasources: any;
|
|
|
|
annotations: any;
|
|
|
|
currentAnnotation: any;
|
|
|
|
currentDatasource: any;
|
|
|
|
currentIsNew: any;
|
2019-02-04 04:19:45 -06:00
|
|
|
dashboard: DashboardModel;
|
2016-09-08 04:25:45 -05:00
|
|
|
|
|
|
|
annotationDefaults: any = {
|
2017-12-20 05:33:33 -06:00
|
|
|
name: '',
|
2016-09-08 04:25:45 -05:00
|
|
|
datasource: null,
|
2017-12-20 05:33:33 -06:00
|
|
|
iconColor: 'rgba(255, 96, 96, 1)',
|
2017-04-12 08:01:17 -05:00
|
|
|
enable: true,
|
2017-04-14 05:46:02 -05:00
|
|
|
showIn: 0,
|
2017-12-20 05:33:33 -06:00
|
|
|
hide: false,
|
2016-09-08 04:25:45 -05:00
|
|
|
};
|
|
|
|
|
2019-08-20 10:19:21 -05:00
|
|
|
emptyListCta = {
|
|
|
|
title: 'There are no custom annotation queries added yet',
|
|
|
|
buttonIcon: 'gicon gicon-annotation',
|
|
|
|
buttonTitle: 'Add Annotation Query',
|
|
|
|
infoBox: {
|
|
|
|
__html: `<p>Annotations provide a way to integrate event data into your graphs. They are visualized as vertical lines
|
|
|
|
and icons on all graph panels. When you hover over an annotation icon you can get event text & tags for
|
|
|
|
the event. You can add annotation events directly from grafana by holding CTRL or CMD + click on graph (or
|
|
|
|
drag region). These will be stored in Grafana's annotation database.
|
|
|
|
</p>
|
|
|
|
Checkout the
|
|
|
|
<a class='external-link' target='_blank' href='http://docs.grafana.org/reference/annotations/'
|
|
|
|
>Annotations documentation</a
|
|
|
|
>
|
|
|
|
for more information.`,
|
|
|
|
},
|
|
|
|
infoBoxTitle: 'What are annotations?',
|
|
|
|
};
|
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
showOptions: any = [{ text: 'All Panels', value: 0 }, { text: 'Specific Panels', value: 1 }];
|
2017-04-12 08:01:17 -05:00
|
|
|
|
2016-09-08 07:31:30 -05:00
|
|
|
/** @ngInject */
|
2019-08-01 07:38:34 -05:00
|
|
|
constructor($scope: any, private datasourceSrv: DatasourceSrv) {
|
2016-09-08 04:25:45 -05:00
|
|
|
$scope.ctrl = this;
|
|
|
|
|
2019-02-04 04:19:45 -06:00
|
|
|
this.dashboard = $scope.dashboard;
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'list';
|
2016-09-08 04:25:45 -05:00
|
|
|
this.datasources = datasourceSrv.getAnnotationSources();
|
2019-02-04 04:19:45 -06:00
|
|
|
this.annotations = this.dashboard.annotations.list;
|
2016-09-08 04:25:45 -05:00
|
|
|
this.reset();
|
2017-10-09 06:54:14 -05:00
|
|
|
|
|
|
|
this.onColorChange = this.onColorChange.bind(this);
|
2016-09-08 04:25:45 -05:00
|
|
|
}
|
|
|
|
|
2019-08-01 07:38:34 -05:00
|
|
|
async datasourceChanged() {
|
|
|
|
return (this.currentDatasource = await this.datasourceSrv.get(this.currentAnnotation.datasource));
|
2016-09-08 04:25:45 -05:00
|
|
|
}
|
|
|
|
|
2019-08-01 07:38:34 -05:00
|
|
|
edit(annotation: any) {
|
2016-09-08 04:25:45 -05:00
|
|
|
this.currentAnnotation = annotation;
|
2017-04-14 05:46:02 -05:00
|
|
|
this.currentAnnotation.showIn = this.currentAnnotation.showIn || 0;
|
2016-09-08 04:25:45 -05:00
|
|
|
this.currentIsNew = false;
|
|
|
|
this.datasourceChanged();
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'edit';
|
|
|
|
$('.tooltip.in').remove();
|
2016-09-08 04:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.currentAnnotation = angular.copy(this.annotationDefaults);
|
|
|
|
this.currentAnnotation.datasource = this.datasources[0].name;
|
|
|
|
this.currentIsNew = true;
|
|
|
|
this.datasourceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
this.reset();
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'list';
|
2017-04-20 04:16:37 -05:00
|
|
|
}
|
2016-09-08 04:25:45 -05:00
|
|
|
|
2019-08-20 10:19:21 -05:00
|
|
|
setupNew = () => {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'new';
|
2017-10-07 03:31:39 -05:00
|
|
|
this.reset();
|
2019-08-20 10:19:21 -05:00
|
|
|
};
|
2017-10-07 03:31:39 -05:00
|
|
|
|
2017-12-11 06:09:25 -06:00
|
|
|
backToList() {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'list';
|
2017-12-11 06:09:25 -06:00
|
|
|
}
|
|
|
|
|
2019-08-01 07:38:34 -05:00
|
|
|
move(index: number, dir: number) {
|
2019-04-15 05:11:52 -05:00
|
|
|
// @ts-ignore
|
2018-05-29 07:02:52 -05:00
|
|
|
_.move(this.annotations, index, index + dir);
|
|
|
|
}
|
|
|
|
|
2016-09-08 04:25:45 -05:00
|
|
|
add() {
|
2019-09-04 07:00:37 -05:00
|
|
|
const sameName: any = _.find(this.annotations, { name: this.currentAnnotation.name });
|
|
|
|
if (sameName) {
|
|
|
|
appEvents.emit('alert-warning', ['Validation', 'Annotations with the same name already exists']);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-08 04:25:45 -05:00
|
|
|
this.annotations.push(this.currentAnnotation);
|
|
|
|
this.reset();
|
2017-12-20 05:33:33 -06:00
|
|
|
this.mode = 'list';
|
2019-02-04 04:19:45 -06:00
|
|
|
this.dashboard.updateSubmenuVisibility();
|
2017-04-20 04:16:37 -05:00
|
|
|
}
|
2016-09-08 04:25:45 -05:00
|
|
|
|
2019-08-01 07:38:34 -05:00
|
|
|
removeAnnotation(annotation: any) {
|
2018-08-29 07:27:29 -05:00
|
|
|
const index = _.indexOf(this.annotations, annotation);
|
2016-09-08 04:25:45 -05:00
|
|
|
this.annotations.splice(index, 1);
|
2019-02-04 04:19:45 -06:00
|
|
|
this.dashboard.updateSubmenuVisibility();
|
2016-09-08 04:25:45 -05:00
|
|
|
}
|
2017-10-07 03:31:39 -05:00
|
|
|
|
2019-08-01 07:38:34 -05:00
|
|
|
onColorChange(newColor: string) {
|
2017-10-09 06:54:14 -05:00
|
|
|
this.currentAnnotation.iconColor = newColor;
|
|
|
|
}
|
2016-09-08 04:25:45 -05:00
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.controller('AnnotationsEditorCtrl', AnnotationsEditorCtrl);
|