2014-02-09 12:31:06 -06:00
|
|
|
define([
|
|
|
|
'angular',
|
|
|
|
'app',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash'
|
2014-02-09 12:31:06 -06:00
|
|
|
],
|
|
|
|
function (angular, app, _) {
|
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.controllers');
|
2014-02-09 12:31:06 -06:00
|
|
|
|
2014-08-26 03:16:21 -05:00
|
|
|
module.controller('SubmenuCtrl', function($scope, $q, $rootScope, datasourceSrv) {
|
2014-06-06 23:38:33 -05:00
|
|
|
var _d = {
|
|
|
|
enable: true
|
|
|
|
};
|
2014-02-09 12:31:06 -06:00
|
|
|
|
2014-06-06 23:38:33 -05:00
|
|
|
_.defaults($scope.pulldown,_d);
|
2014-02-09 12:31:06 -06:00
|
|
|
|
2014-06-06 23:38:33 -05:00
|
|
|
$scope.init = function() {
|
|
|
|
$scope.panel = $scope.pulldown;
|
|
|
|
$scope.row = $scope.pulldown;
|
|
|
|
};
|
2014-02-09 12:31:06 -06:00
|
|
|
|
2014-08-25 08:36:44 -05:00
|
|
|
$scope.filterOptionSelected = function(templateParameter, option, recursive) {
|
|
|
|
templateParameter.current = option;
|
|
|
|
|
|
|
|
$scope.filter.updateTemplateData();
|
|
|
|
|
|
|
|
return $scope.applyFilterToOtherFilters(templateParameter)
|
|
|
|
.then(function() {
|
|
|
|
// only refresh in the outermost call
|
|
|
|
if (!recursive) {
|
|
|
|
$scope.dashboard.emit_refresh();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.applyFilterToOtherFilters = function(updatedTemplatedParam) {
|
|
|
|
var promises = _.map($scope.filter.templateParameters, function(templateParam) {
|
|
|
|
if (templateParam === updatedTemplatedParam) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (templateParam.query.indexOf('[[' + updatedTemplatedParam.name + ']]') !== -1) {
|
|
|
|
return $scope.applyFilter(templateParam);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return $q.all(promises);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.applyFilter = function(templateParam) {
|
|
|
|
return datasourceSrv.default.metricFindQuery($scope.filter, templateParam.query)
|
|
|
|
.then(function (results) {
|
|
|
|
templateParam.options = _.map(results, function(node) {
|
|
|
|
return { text: node.text, value: node.text };
|
|
|
|
});
|
|
|
|
|
|
|
|
if (templateParam.includeAll) {
|
|
|
|
var allExpr = '{';
|
|
|
|
_.each(templateParam.options, function(option) {
|
|
|
|
allExpr += option.text + ',';
|
|
|
|
});
|
|
|
|
allExpr = allExpr.substring(0, allExpr.length - 1) + '}';
|
|
|
|
templateParam.options.unshift({text: 'All', value: allExpr});
|
|
|
|
}
|
|
|
|
|
|
|
|
// if parameter has current value
|
|
|
|
// if it exists in options array keep value
|
|
|
|
if (templateParam.current) {
|
|
|
|
var currentExists = _.findWhere(templateParam.options, { value: templateParam.current.value });
|
|
|
|
if (currentExists) {
|
|
|
|
return $scope.filterOptionSelected(templateParam, templateParam.current, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $scope.filterOptionSelected(templateParam, templateParam.options[0], true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-08-26 03:16:21 -05:00
|
|
|
$scope.disableAnnotation = function (annotation) {
|
|
|
|
annotation.enable = !annotation.enable;
|
|
|
|
$rootScope.$broadcast('refresh');
|
|
|
|
};
|
|
|
|
|
2014-06-06 23:38:33 -05:00
|
|
|
$scope.init();
|
2014-02-09 12:31:06 -06:00
|
|
|
|
2014-06-06 23:38:33 -05:00
|
|
|
});
|
2014-02-09 12:31:06 -06:00
|
|
|
|
2014-08-25 06:31:31 -05:00
|
|
|
});
|