| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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 & 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);
|