2014-08-25 08:36:44 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
2014-08-26 02:32:30 -05:00
|
|
|
'lodash',
|
|
|
|
'jquery'
|
2014-08-25 08:36:44 -05:00
|
|
|
],
|
2014-08-26 07:17:46 -05:00
|
|
|
function (angular, _, $) {
|
2014-08-25 08:36:44 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
|
|
2014-08-26 02:46:15 -05:00
|
|
|
module.controller('AnnotationsEditorCtrl', function($scope, datasourceSrv) {
|
2014-08-25 08:36:44 -05:00
|
|
|
var annotationDefaults = {
|
|
|
|
name: '',
|
|
|
|
datasource: null,
|
|
|
|
showLine: true,
|
|
|
|
iconColor: '#C0C6BE',
|
|
|
|
lineColor: 'rgba(255, 96, 96, 0.592157)',
|
|
|
|
iconSize: 13,
|
|
|
|
enable: true
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.init = function() {
|
2014-08-26 02:32:30 -05:00
|
|
|
$scope.editor = { index: 0 };
|
2014-08-25 08:36:44 -05:00
|
|
|
$scope.datasources = datasourceSrv.getAnnotationSources();
|
|
|
|
$scope.annotations = $scope.dashboard.annotations.list;
|
2014-08-29 02:59:18 -05:00
|
|
|
$scope.reset();
|
2014-08-26 02:32:30 -05:00
|
|
|
|
|
|
|
$scope.$watch('editor.index', function(newVal) {
|
|
|
|
if (newVal !== 2) {
|
|
|
|
$scope.reset();
|
|
|
|
}
|
|
|
|
});
|
2014-08-25 08:36:44 -05:00
|
|
|
};
|
|
|
|
|
2014-08-29 02:59:18 -05:00
|
|
|
$scope.datasourceChanged = function() {
|
|
|
|
$scope.currentDatasource = _.findWhere($scope.datasources, { name: $scope.currentAnnotation.datasource });
|
|
|
|
if (!$scope.currentDatasource) {
|
|
|
|
$scope.currentDatasource = $scope.datasources[0];
|
|
|
|
}
|
2014-08-25 08:36:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.edit = function(annotation) {
|
|
|
|
$scope.currentAnnotation = annotation;
|
|
|
|
$scope.currentIsNew = false;
|
2014-08-29 02:59:18 -05:00
|
|
|
$scope.datasourceChanged();
|
2014-08-26 02:32:30 -05:00
|
|
|
|
|
|
|
$scope.editor.index = 2;
|
|
|
|
$(".tooltip.in").remove();
|
2014-08-25 08:36:44 -05:00
|
|
|
};
|
|
|
|
|
2014-08-26 02:32:30 -05:00
|
|
|
$scope.reset = function() {
|
2014-08-25 08:36:44 -05:00
|
|
|
$scope.currentAnnotation = angular.copy(annotationDefaults);
|
|
|
|
$scope.currentIsNew = true;
|
2014-08-29 02:59:18 -05:00
|
|
|
$scope.datasourceChanged();
|
|
|
|
$scope.currentAnnotation.datasource = $scope.currentDatasource.name;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.update = function() {
|
|
|
|
$scope.reset();
|
|
|
|
$scope.editor.index = 0;
|
2015-02-22 01:09:58 -06:00
|
|
|
$scope.broadcastRefresh();
|
2014-08-25 08:36:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.add = function() {
|
|
|
|
$scope.annotations.push($scope.currentAnnotation);
|
2014-08-26 07:17:46 -05:00
|
|
|
$scope.reset();
|
|
|
|
$scope.editor.index = 0;
|
2015-02-20 05:20:10 -06:00
|
|
|
$scope.updateSubmenuVisibility();
|
2015-02-22 01:09:58 -06:00
|
|
|
$scope.broadcastRefresh();
|
2014-08-25 08:36:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeAnnotation = function(annotation) {
|
|
|
|
var index = _.indexOf($scope.annotations, annotation);
|
|
|
|
$scope.annotations.splice(index, 1);
|
2015-02-20 05:20:10 -06:00
|
|
|
$scope.updateSubmenuVisibility();
|
2015-02-22 01:09:58 -06:00
|
|
|
$scope.broadcastRefresh();
|
2014-08-25 08:36:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|
2014-08-25 10:27:19 -05:00
|
|
|
|
2014-08-25 08:36:44 -05:00
|
|
|
});
|