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;
|
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 {
|
return {
|
||||||
setters: [function (_appPluginsSdk) {
|
setters: [function (_appPluginsSdk) {
|
||||||
QueryCtrl = _appPluginsSdk.QueryCtrl;
|
QueryCtrl = _appPluginsSdk.QueryCtrl;
|
||||||
@@ -94,10 +90,10 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Map functions for bs-typeahead
|
// Map functions for bs-typeahead
|
||||||
_this.getGroupNames = _.partial(getMetricNames, _this, 'groupList');
|
_this.getGroupNames = _.bind(_this.getMetricNames, _this, 'groupList');
|
||||||
_this.getHostNames = _.partial(getMetricNames, _this, 'hostList');
|
_this.getHostNames = _.bind(_this.getMetricNames, _this, 'hostList');
|
||||||
_this.getApplicationNames = _.partial(getMetricNames, _this, 'appList');
|
_this.getApplicationNames = _.bind(_this.getMetricNames, _this, 'appList');
|
||||||
_this.getItemNames = _.partial(getMetricNames, _this, 'itemList');
|
_this.getItemNames = _.bind(_this.getMetricNames, _this, 'itemList');
|
||||||
|
|
||||||
// Update metric suggestion when template variable was changed
|
// Update metric suggestion when template variable was changed
|
||||||
$rootScope.$on('template-variable-value-updated', function () {
|
$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;
|
var itemtype = this.editorModes[this.target.mode].value;
|
||||||
return Promise.all([this.suggestGroups(), this.suggestHosts(), this.suggestApps(), this.suggestItems(itemtype)]);
|
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',
|
key: 'suggestGroups',
|
||||||
value: function 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
|
// Map functions for bs-typeahead
|
||||||
_this.getGroupNames = _lodash2.default.partial(getMetricNames, _this, 'groupList');
|
_this.getGroupNames = _lodash2.default.bind(_this.getMetricNames, _this, 'groupList');
|
||||||
_this.getHostNames = _lodash2.default.partial(getMetricNames, _this, 'hostList');
|
_this.getHostNames = _lodash2.default.bind(_this.getMetricNames, _this, 'hostList');
|
||||||
_this.getApplicationNames = _lodash2.default.partial(getMetricNames, _this, 'appList');
|
_this.getApplicationNames = _lodash2.default.bind(_this.getMetricNames, _this, 'appList');
|
||||||
_this.getItemNames = _lodash2.default.partial(getMetricNames, _this, 'itemList');
|
_this.getItemNames = _lodash2.default.bind(_this.getMetricNames, _this, 'itemList');
|
||||||
|
|
||||||
// Update metric suggestion when template variable was changed
|
// Update metric suggestion when template variable was changed
|
||||||
$rootScope.$on('template-variable-value-updated', function () {
|
$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;
|
var itemtype = this.editorModes[this.target.mode].value;
|
||||||
return Promise.all([this.suggestGroups(), this.suggestHosts(), this.suggestApps(), this.suggestItems(itemtype)]);
|
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',
|
key: 'suggestGroups',
|
||||||
value: function suggestGroups() {
|
value: function suggestGroups() {
|
||||||
@@ -371,8 +386,3 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
|||||||
|
|
||||||
|
|
||||||
ZabbixQueryController.templateUrl = 'datasource-zabbix/partials/query.editor.html';
|
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'));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Map functions for bs-typeahead
|
// Map functions for bs-typeahead
|
||||||
this.getGroupNames = _.partial(getMetricNames, this, 'groupList');
|
this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');
|
||||||
this.getHostNames = _.partial(getMetricNames, this, 'hostList');
|
this.getHostNames = _.bind(this.getMetricNames, this, 'hostList');
|
||||||
this.getApplicationNames = _.partial(getMetricNames, this, 'appList');
|
this.getApplicationNames = _.bind(this.getMetricNames, this, 'appList');
|
||||||
this.getItemNames = _.partial(getMetricNames, this, 'itemList');
|
this.getItemNames = _.bind(this.getMetricNames, this, 'itemList');
|
||||||
|
|
||||||
// Update metric suggestion when template variable was changed
|
// Update metric suggestion when template variable was changed
|
||||||
$rootScope.$on('template-variable-value-updated', () => this.onVariableChange());
|
$rootScope.$on('template-variable-value-updated', () => this.onVariableChange());
|
||||||
@@ -110,6 +110,18 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get list of metric names for bs-typeahead directive
|
||||||
|
getMetricNames(metricList) {
|
||||||
|
let metrics = _.uniq(_.map(this.metric[metricList], 'name'));
|
||||||
|
|
||||||
|
// Add template variables
|
||||||
|
_.forEach(this.templateSrv.variables, variable => {
|
||||||
|
metrics.unshift('$' + variable.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
|
||||||
suggestGroups() {
|
suggestGroups() {
|
||||||
return this.zabbix.getAllGroups()
|
return this.zabbix.getAllGroups()
|
||||||
.then(groups => {
|
.then(groups => {
|
||||||
@@ -302,8 +314,3 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
|
|
||||||
// Set templateUrl as static property
|
// Set templateUrl as static property
|
||||||
ZabbixQueryController.templateUrl = 'datasource-zabbix/partials/query.editor.html';
|
ZabbixQueryController.templateUrl = 'datasource-zabbix/partials/query.editor.html';
|
||||||
|
|
||||||
// Get list of metric names for bs-typeahead directive
|
|
||||||
function getMetricNames(scope, metricList) {
|
|
||||||
return _.uniq(_.map(scope.metric[metricList], 'name'));
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user