From c71ad03cf5e2d3699f10732e010bab46cb3e7c06 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sun, 31 May 2015 09:25:07 +0300 Subject: [PATCH] Improve app search in query editor - return only unique app names and search by app name in multiple hosts. --- zabbix/queryCtrl.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/zabbix/queryCtrl.js b/zabbix/queryCtrl.js index 3c3401b..f8056c1 100644 --- a/zabbix/queryCtrl.js +++ b/zabbix/queryCtrl.js @@ -159,12 +159,15 @@ function (angular, _) { var hostid = $scope.target.host ? $scope.target.host.hostid : null; var groupid = $scope.target.hostGroup ? $scope.target.hostGroup.groupid: null; $scope.datasource.performAppSuggestQuery(hostid, groupid).then(function (series) { - $scope.metric.applicationList = $scope.metric.applicationList.concat(series); + var apps = _.map(_.uniq(_.map(series, 'name')), function (appname) { + return {name: appname}; + }); + $scope.metric.applicationList = $scope.metric.applicationList.concat(apps); if ($scope.target.application) { - $scope.target.application = $scope.metric.applicationList.filter(function (item, index, array) { + $scope.target.application = $scope.metric.applicationList.filter(function (app) { // Find selected application in metric.hostList - return item.name == $scope.target.application.name; + return app.name == $scope.target.application.name; }).pop(); } }); @@ -180,23 +183,27 @@ function (angular, _) { var groupids = $scope.target.hostGroup ? $scope.target.hostGroup.groupid: null; var hostids = $scope.target.host ? $scope.target.host.hostid : null; - var applicationids = $scope.target.application ? $scope.target.application.applicationid : null; + var application = $scope.target.application || null; - $scope.datasource.performItemSuggestQuery(hostids, applicationids, groupids).then(function (series) { - $scope.metric.itemList = $scope.metric.itemList.concat(series); + // Get application ids from name + $scope.datasource.findZabbixApp(application).then(function (result) { + var applicationids = _.map(result, 'applicationid'); + $scope.datasource.performItemSuggestQuery(hostids, applicationids, groupids).then(function (series) { + $scope.metric.itemList = $scope.metric.itemList.concat(series); - // Expand item parameters - $scope.metric.itemList.forEach(function (item, index, array) { - if (item && item.key_ && item.name) { - item.name = expandItemName(item); + // Expand item parameters + $scope.metric.itemList.forEach(function (item, index, array) { + if (item && item.key_ && item.name) { + item.name = expandItemName(item); + } + }); + if ($scope.target.item) { + $scope.target.item = $scope.metric.itemList.filter(function (item, index, array) { + // Find selected item in metric.hostList + return item.name == $scope.target.item.name; + }).pop(); } }); - if ($scope.target.item) { - $scope.target.item = $scope.metric.itemList.filter(function (item, index, array) { - // Find selected item in metric.hostList - return item.name == $scope.target.item.name; - }).pop(); - } }); };