mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
///<reference path="../../headers/common.d.ts" />
|
|
|
|
import angular from 'angular';
|
|
import _ from 'lodash';
|
|
import $ from 'jquery';
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
export class AnnotationsEditorCtrl {
|
|
mode: any;
|
|
datasources: any;
|
|
annotations: any;
|
|
currentAnnotation: any;
|
|
currentDatasource: any;
|
|
currentIsNew: any;
|
|
|
|
annotationDefaults: any = {
|
|
name: '',
|
|
datasource: null,
|
|
iconColor: 'rgba(255, 96, 96, 1)',
|
|
enable: true
|
|
};
|
|
|
|
/** @ngInject */
|
|
constructor(private $scope, private datasourceSrv) {
|
|
$scope.ctrl = this;
|
|
|
|
this.mode = 'list';
|
|
this.datasources = datasourceSrv.getAnnotationSources();
|
|
this.annotations = $scope.dashboard.annotations.list;
|
|
this.reset();
|
|
|
|
$scope.$watch('mode', newVal => {
|
|
if (newVal === 'new') {
|
|
this.reset();
|
|
}
|
|
});
|
|
}
|
|
|
|
datasourceChanged() {
|
|
return this.datasourceSrv.get(this.currentAnnotation.datasource).then(ds => {
|
|
this.currentDatasource = ds;
|
|
});
|
|
}
|
|
|
|
edit(annotation) {
|
|
this.currentAnnotation = annotation;
|
|
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';
|
|
this.$scope.broadcastRefresh();
|
|
};
|
|
|
|
add() {
|
|
this.annotations.push(this.currentAnnotation);
|
|
this.reset();
|
|
this.mode = 'list';
|
|
this.$scope.updateSubmenuVisibility();
|
|
this.$scope.broadcastRefresh();
|
|
};
|
|
|
|
removeAnnotation(annotation) {
|
|
var index = _.indexOf(this.annotations, annotation);
|
|
this.annotations.splice(index, 1);
|
|
this.$scope.updateSubmenuVisibility();
|
|
this.$scope.broadcastRefresh();
|
|
}
|
|
}
|
|
|
|
coreModule.controller('AnnotationsEditorCtrl', AnnotationsEditorCtrl);
|