grafana/src/app/controllers/annotationsEditorCtrl.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

define([
'angular',
'app',
2014-08-26 02:32:30 -05:00
'lodash',
'jquery'
],
2014-08-26 02:32:30 -05:00
function (angular, app, _, $) {
'use strict';
var module = angular.module('grafana.controllers');
2014-08-26 02:32:30 -05:00
module.controller('AnnotationsEditorCtrl', function($scope, datasourceSrv, $timeout) {
var annotationDefaults = {
name: '',
datasource: null,
showLine: true,
iconColor: '#C0C6BE',
lineColor: 'rgba(255, 96, 96, 0.592157)',
iconSize: 13,
enable: true
};
$scope.init = function() {
$scope.currentAnnotation = angular.copy(annotationDefaults);
$scope.currentIsNew = true;
2014-08-26 02:32:30 -05:00
$scope.editor = { index: 0 };
$scope.datasources = datasourceSrv.getAnnotationSources();
$scope.annotations = $scope.dashboard.annotations.list;
if ($scope.datasources.length > 0) {
$scope.currentDatasource = $scope.datasources[0];
}
2014-08-26 02:32:30 -05:00
$scope.$watch('editor.index', function(newVal) {
console.log("value", newVal);
if (newVal !== 2) {
$scope.reset();
}
});
};
$scope.setDatasource = function() {
$scope.currentAnnotation.datasource = $scope.currentDatasource.name;
};
$scope.edit = function(annotation) {
$scope.currentAnnotation = annotation;
$scope.currentIsNew = false;
$scope.currentDatasource = _.findWhere($scope.datasources, { name: annotation.datasource });
if (!$scope.currentDatasource) {
$scope.currentDatasource = $scope.datasources[0];
}
2014-08-26 02:32:30 -05:00
$scope.editor.index = 2;
$(".tooltip.in").remove();
};
2014-08-26 02:32:30 -05:00
$scope.reset = function() {
$scope.currentAnnotation = angular.copy(annotationDefaults);
$scope.currentIsNew = true;
};
$scope.add = function() {
$scope.currentAnnotation.datasource = $scope.currentDatasource.name;
$scope.annotations.push($scope.currentAnnotation);
$scope.currentAnnotation = angular.copy(annotationDefaults);
};
$scope.removeAnnotation = function(annotation) {
var index = _.indexOf($scope.annotations, annotation);
$scope.annotations.splice(index, 1);
};
});
2014-08-25 10:27:19 -05:00
});