Add template variables to dropdown metric list, closes #310

This commit is contained in:
Alexander Zobnin
2017-02-11 21:31:08 +03:00
parent 48018744bd
commit 77108fa05a
4 changed files with 52 additions and 27 deletions

View File

@@ -35,10 +35,6 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}
// Get list of metric names for bs-typeahead directive
function getMetricNames(scope, metricList) {
return _.uniq(_.map(scope.metric[metricList], 'name'));
}
return {
setters: [function (_appPluginsSdk) {
QueryCtrl = _appPluginsSdk.QueryCtrl;
@@ -94,10 +90,10 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
};
// Map functions for bs-typeahead
_this.getGroupNames = _.partial(getMetricNames, _this, 'groupList');
_this.getHostNames = _.partial(getMetricNames, _this, 'hostList');
_this.getApplicationNames = _.partial(getMetricNames, _this, 'appList');
_this.getItemNames = _.partial(getMetricNames, _this, 'itemList');
_this.getGroupNames = _.bind(_this.getMetricNames, _this, 'groupList');
_this.getHostNames = _.bind(_this.getMetricNames, _this, 'hostList');
_this.getApplicationNames = _.bind(_this.getMetricNames, _this, 'appList');
_this.getItemNames = _.bind(_this.getMetricNames, _this, 'itemList');
// Update metric suggestion when template variable was changed
$rootScope.$on('template-variable-value-updated', function () {
@@ -163,6 +159,18 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
var itemtype = this.editorModes[this.target.mode].value;
return Promise.all([this.suggestGroups(), this.suggestHosts(), this.suggestApps(), this.suggestItems(itemtype)]);
}
}, {
key: 'getMetricNames',
value: function getMetricNames(metricList) {
var metrics = _.uniq(_.map(this.metric[metricList], 'name'));
// Add template variables
_.forEach(this.templateSrv.variables, function (variable) {
metrics.unshift('$' + variable.name);
});
return metrics;
}
}, {
key: 'suggestGroups',
value: function suggestGroups() {