Fixed item filtering by types.

This commit is contained in:
Alexander Zobnin
2016-02-01 14:31:20 +03:00
parent fbebb1f04e
commit 5ead2950b8
3 changed files with 27 additions and 33 deletions

View File

@@ -294,8 +294,8 @@ function (angular, _, dateMath, utils, metricFunctions) {
// Get items
if (parts.length === 4) {
//var items = this.queryProcessor.filterItems(template.host, template.app, true);
return this.queryProcessor.filterItems(template.group, template.host, template.app, true)
return this.queryProcessor.filterItems(template.group, template.host,
template.app, 'all', true)
.then(function(items) {
return _.map(items, formatMetric);
});

View File

@@ -17,9 +17,10 @@ define([
$scope.init = function () {
$scope.targetLetters = targetLetters;
if (!$scope.metric) {
$scope.metric = {};
}
var scopeDefaults = {
metric: {}
};
_.defaults($scope, scopeDefaults);
// Load default values
var targetDefaults = {
@@ -51,10 +52,7 @@ define([
$scope.target.downsampleFunction = $scope.downsampleFunctionList[0];
}
// Load metrics from cache
$scope.getMetricsFromCache().then(function() {
$scope.initFilters();
});
}
else if ($scope.target.mode === 1) {
$scope.slaPropertyList = [
@@ -70,29 +68,12 @@ define([
};
$scope.initFilters = function () {
$scope.filterGroups();
$scope.filterHosts();
$scope.filterApplications();
$scope.filterItems();
};
$scope.getMetricsFromCache = function() {
var item_type = $scope.editorModes[$scope.target.mode];
var promises = [
zabbixCache.getGroups(),
zabbixCache.getHosts(),
zabbixCache.getApplications(),
zabbixCache.getItems(item_type)
];
return $q.all(promises).then(function(results) {
$scope.metric = {
groupList: results[0],
hostList: results[1],
applicationList: results[2],
itemList: results[3]
};
});
};
// Get list of metric names for bs-typeahead directive
function getMetricNames(scope, metricList) {
return _.uniq(_.map(scope.metric[metricList], 'name'));
@@ -111,6 +92,12 @@ define([
});
};
$scope.filterGroups = function() {
$scope.datasource.queryProcessor.filterGroups().then(function(groups) {
$scope.metric.groupList = groups;
});
};
$scope.filterApplications = function () {
var groupFilter = templateSrv.replace($scope.target.group.filter);
var hostFilter = templateSrv.replace($scope.target.host.filter);
@@ -121,11 +108,12 @@ define([
};
$scope.filterItems = function () {
var item_type = $scope.editorModes[$scope.target.mode];
var groupFilter = templateSrv.replace($scope.target.group.filter);
var hostFilter = templateSrv.replace($scope.target.host.filter);
var appFilter = templateSrv.replace($scope.target.application.filter);
$scope.datasource.queryProcessor.filterItems(groupFilter, hostFilter, appFilter,
$scope.target.showDisabledItems).then(function(items) {
item_type, $scope.target.showDisabledItems).then(function(items) {
$scope.metric.filteredItems = items;
});
};

View File

@@ -28,6 +28,12 @@ function (angular, _, utils) {
}
};
this.filterGroups = function(groupFilter) {
return self.cache.getGroups().then(function(groupList) {
return groupList;
});
};
this.filterHosts = function(groupFilter) {
var groups = [];
var hosts = [];
@@ -103,7 +109,7 @@ function (angular, _, utils) {
});
};
this.filterItems = function (groupFilter, hostFilter, appFilter, showDisabledItems) {
this.filterItems = function (groupFilter, hostFilter, appFilter, itemType, showDisabledItems) {
var hosts = [];
var apps = [];
var items = [];
@@ -111,7 +117,7 @@ function (angular, _, utils) {
var promises = [
this.filterHosts(groupFilter),
this.filterApplications(groupFilter, hostFilter),
this.cache.getItems(),
this.cache.getItems(itemType),
];
return $q.all(promises).then(function(results) {