grafana/public/app/features/annotations/editor_ctrl.ts
Tobias Skarhed ec492e55dc
Refactor: EmptyListCTA (#18516)
* Rewrite EmptyListCTA props and start removing css classes

* Add watchDepth onClick

* EmptyListCTA with React in annotaitons/editor

* Begin conversion of DashLinks editor EmptyListCTA

* Use React component in DashLinks, Variables and TeamGroupSync

* Remove scss file and add emotion styles

* Update snapshot

* Remove style import

* Fix feedback

* Update snapshot
2019-08-20 17:19:21 +02:00

118 lines
3.2 KiB
TypeScript

import angular from 'angular';
import _ from 'lodash';
import $ from 'jquery';
import coreModule from 'app/core/core_module';
import { DashboardModel } from 'app/features/dashboard/state';
import DatasourceSrv from '../plugins/datasource_srv';
export class AnnotationsEditorCtrl {
mode: any;
datasources: any;
annotations: any;
currentAnnotation: any;
currentDatasource: any;
currentIsNew: any;
dashboard: DashboardModel;
annotationDefaults: any = {
name: '',
datasource: null,
iconColor: 'rgba(255, 96, 96, 1)',
enable: true,
showIn: 0,
hide: false,
};
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 &amp; 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?',
};
showOptions: any = [{ text: 'All Panels', value: 0 }, { text: 'Specific Panels', value: 1 }];
/** @ngInject */
constructor($scope: any, private datasourceSrv: DatasourceSrv) {
$scope.ctrl = this;
this.dashboard = $scope.dashboard;
this.mode = 'list';
this.datasources = datasourceSrv.getAnnotationSources();
this.annotations = this.dashboard.annotations.list;
this.reset();
this.onColorChange = this.onColorChange.bind(this);
}
async datasourceChanged() {
return (this.currentDatasource = await this.datasourceSrv.get(this.currentAnnotation.datasource));
}
edit(annotation: any) {
this.currentAnnotation = annotation;
this.currentAnnotation.showIn = this.currentAnnotation.showIn || 0;
this.currentIsNew = false;
this.datasourceChanged();
this.mode = 'edit';
$('.tooltip.in').remove();
}
reset() {
this.currentAnnotation = angular.copy(this.annotationDefaults);
this.currentAnnotation.datasource = this.datasources[0].name;
this.currentIsNew = true;
this.datasourceChanged();
}
update() {
this.reset();
this.mode = 'list';
}
setupNew = () => {
this.mode = 'new';
this.reset();
};
backToList() {
this.mode = 'list';
}
move(index: number, dir: number) {
// @ts-ignore
_.move(this.annotations, index, index + dir);
}
add() {
this.annotations.push(this.currentAnnotation);
this.reset();
this.mode = 'list';
this.dashboard.updateSubmenuVisibility();
}
removeAnnotation(annotation: any) {
const index = _.indexOf(this.annotations, annotation);
this.annotations.splice(index, 1);
this.dashboard.updateSubmenuVisibility();
}
onColorChange(newColor: string) {
this.currentAnnotation.iconColor = newColor;
}
}
coreModule.controller('AnnotationsEditorCtrl', AnnotationsEditorCtrl);