Add "track by item.name" for metrics selection.

This commit is contained in:
Alexander Zobnin
2015-06-09 12:24:58 +03:00
parent d9c08ca439
commit 2745f832fd
2 changed files with 6 additions and 33 deletions

View File

@@ -59,7 +59,7 @@
ng-change="selectHostGroup()" ng-change="selectHostGroup()"
ng-model="target.group" ng-model="target.group"
bs-tooltip="target.group.name.length > 25 ? target.group.name : ''" bs-tooltip="target.group.name.length > 25 ? target.group.name : ''"
ng-options="group.visible_name ? group.visible_name : group.name for group in metric.groupList" > ng-options="group.visible_name ? group.visible_name : group.name for group in metric.groupList track by group.name" >
<option value="">-- Select host group --</option> <option value="">-- Select host group --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
@@ -75,7 +75,7 @@
ng-change="selectHost()" ng-change="selectHost()"
ng-model="target.host" ng-model="target.host"
bs-tooltip="target.host.name.length > 25 ? target.host.name : ''" bs-tooltip="target.host.name.length > 25 ? target.host.name : ''"
ng-options="host.visible_name ? host.visible_name : host.name for host in metric.hostList" > ng-options="host.visible_name ? host.visible_name : host.name for host in metric.hostList track by host.name" >
<option value="">-- Select host --</option> <option value="">-- Select host --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
@@ -91,7 +91,7 @@
ng-change="selectApplication()" ng-change="selectApplication()"
ng-model="target.application" ng-model="target.application"
bs-tooltip="target.application.name.length > 15 ? target.application.name : ''" bs-tooltip="target.application.name.length > 15 ? target.application.name : ''"
ng-options="app.visible_name ? app.visible_name : app.name for app in metric.applicationList" > ng-options="app.visible_name ? app.visible_name : app.name for app in metric.applicationList track by app.name" >
<option value="">-- Select application --</option> <option value="">-- Select application --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
@@ -107,7 +107,7 @@
ng-change="selectItem()" ng-change="selectItem()"
ng-model="target.item" ng-model="target.item"
bs-tooltip="target.name.length > 30 ? target.name : ''" bs-tooltip="target.name.length > 30 ? target.name : ''"
ng-options="item.name for item in metric.itemList" > ng-options="item.name for item in metric.itemList track by item.name" >
<option value="">-- Select item --</option> <option value="">-- Select item --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"

View File

@@ -131,15 +131,8 @@ function (angular, _) {
$scope.metric.groupList = [{name: '*', visible_name: 'All'}]; $scope.metric.groupList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.groupList); addTemplatedVariables($scope.metric.groupList);
$scope.datasource.performHostGroupSuggestQuery().then(function (series) { $scope.datasource.performHostGroupSuggestQuery().then(function (groups) {
$scope.metric.groupList = $scope.metric.groupList.concat(series); $scope.metric.groupList = $scope.metric.groupList.concat(groups);
if ($scope.target.group) {
$scope.target.group = $scope.metric.groupList.filter(function (item, index, array) {
// Find selected host in metric.hostList
return item.name == $scope.target.group.name;
}).pop();
}
}); });
}; };
@@ -154,13 +147,6 @@ function (angular, _) {
var groups = $scope.target.group ? splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; var groups = $scope.target.group ? splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
$scope.datasource.hostFindQuery(groups).then(function (hosts) { $scope.datasource.hostFindQuery(groups).then(function (hosts) {
$scope.metric.hostList = $scope.metric.hostList.concat(hosts); $scope.metric.hostList = $scope.metric.hostList.concat(hosts);
if ($scope.target.host) {
$scope.target.host = $scope.metric.hostList.filter(function (item, index, array) {
// Find selected host in metric.hostList
return item.name == $scope.target.host.name;
}).pop();
}
}); });
}; };
@@ -180,13 +166,6 @@ function (angular, _) {
return {name: appname}; return {name: appname};
}); });
$scope.metric.applicationList = $scope.metric.applicationList.concat(apps); $scope.metric.applicationList = $scope.metric.applicationList.concat(apps);
if ($scope.target.application) {
$scope.target.application = $scope.metric.applicationList.filter(function (app) {
// Find selected application in metric.hostList
return app.name == $scope.target.application.name;
}).pop();
}
}); });
}; };
@@ -214,12 +193,6 @@ function (angular, _) {
item.name = expandItemName(item); 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();
}
}); });
}; };