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

@@ -67,10 +67,10 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
};
// Map functions for bs-typeahead
_this.getGroupNames = _lodash2.default.partial(getMetricNames, _this, 'groupList');
_this.getHostNames = _lodash2.default.partial(getMetricNames, _this, 'hostList');
_this.getApplicationNames = _lodash2.default.partial(getMetricNames, _this, 'appList');
_this.getItemNames = _lodash2.default.partial(getMetricNames, _this, 'itemList');
_this.getGroupNames = _lodash2.default.bind(_this.getMetricNames, _this, 'groupList');
_this.getHostNames = _lodash2.default.bind(_this.getMetricNames, _this, 'hostList');
_this.getApplicationNames = _lodash2.default.bind(_this.getMetricNames, _this, 'appList');
_this.getItemNames = _lodash2.default.bind(_this.getMetricNames, _this, 'itemList');
// Update metric suggestion when template variable was changed
$rootScope.$on('template-variable-value-updated', function () {
@@ -136,6 +136,21 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
var itemtype = this.editorModes[this.target.mode].value;
return Promise.all([this.suggestGroups(), this.suggestHosts(), this.suggestApps(), this.suggestItems(itemtype)]);
}
// Get list of metric names for bs-typeahead directive
}, {
key: 'getMetricNames',
value: function getMetricNames(metricList) {
var metrics = _lodash2.default.uniq(_lodash2.default.map(this.metric[metricList], 'name'));
// Add template variables
_lodash2.default.forEach(this.templateSrv.variables, function (variable) {
metrics.unshift('$' + variable.name);
});
return metrics;
}
}, {
key: 'suggestGroups',
value: function suggestGroups() {
@@ -371,8 +386,3 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
ZabbixQueryController.templateUrl = 'datasource-zabbix/partials/query.editor.html';
// Get list of metric names for bs-typeahead directive
function getMetricNames(scope, metricList) {
return _lodash2.default.uniq(_lodash2.default.map(scope.metric[metricList], 'name'));
}