Add template variables to dropdown metric list, closes #310
This commit is contained in:
24
dist/datasource-zabbix/query.controller.js
vendored
24
dist/datasource-zabbix/query.controller.js
vendored
@@ -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() {
|
||||
|
||||
File diff suppressed because one or more lines are too long
28
dist/test/datasource-zabbix/query.controller.js
vendored
28
dist/test/datasource-zabbix/query.controller.js
vendored
@@ -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'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user