2014-08-25 08:36:44 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
|
|
|
'app',
|
|
|
|
'lodash'
|
|
|
|
],
|
|
|
|
function (angular, app, _) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
|
|
|
|
|
module.controller('AnnotationsEditorCtrl', function($scope, datasourceSrv) {
|
|
|
|
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;
|
|
|
|
$scope.datasources = datasourceSrv.getAnnotationSources();
|
|
|
|
$scope.annotations = $scope.dashboard.annotations.list;
|
|
|
|
|
|
|
|
if ($scope.datasources.length > 0) {
|
|
|
|
$scope.currentDatasource = $scope.datasources[0];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$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];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.update = 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
|
|
|
|
|
|
|
module.controller('EditViewCtrl', function($scope) {
|
2014-08-26 00:27:43 -05:00
|
|
|
$scope.editPanelSrc = null;
|
2014-08-25 10:27:19 -05:00
|
|
|
|
|
|
|
$scope.onAppEvent('show-edit-panel', function(evt, payload) {
|
2014-08-25 15:39:40 -05:00
|
|
|
if (payload.src === $scope.editPanelSrc) {
|
|
|
|
$scope.dismiss();
|
|
|
|
return;
|
|
|
|
}
|
2014-08-25 10:27:19 -05:00
|
|
|
$scope.editPanelSrc = payload.src;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.dismiss = function() {
|
|
|
|
$scope.editPanelSrc = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-08-25 08:36:44 -05:00
|
|
|
});
|