Add templated variables to selection list in query editor.
This commit is contained in:
@@ -106,8 +106,8 @@
|
|||||||
class="tight-form-input input-medium"
|
class="tight-form-input input-medium"
|
||||||
ng-change="selectItem()"
|
ng-change="selectItem()"
|
||||||
ng-model="target.item"
|
ng-model="target.item"
|
||||||
bs-tooltip="target.expandedName.length > 30 ? target.expandedName : ''"
|
bs-tooltip="target.name.length > 30 ? target.name : ''"
|
||||||
ng-options="item.expandedName for item in metric.itemList" >
|
ng-options="item.name for item in metric.itemList" >
|
||||||
<option value="">--select item--</option>
|
<option value="">--select item--</option>
|
||||||
</select>
|
</select>
|
||||||
<a bs-tooltip="target.errors.metric"
|
<a bs-tooltip="target.errors.metric"
|
||||||
|
|||||||
@@ -143,12 +143,16 @@ function (angular, _) {
|
|||||||
* Update list of host groups
|
* Update list of host groups
|
||||||
*/
|
*/
|
||||||
$scope.updateHostGroupList = function() {
|
$scope.updateHostGroupList = function() {
|
||||||
|
$scope.metric.hostGroupList = [];
|
||||||
|
addTemplatedVariables($scope.metric.hostGroupList);
|
||||||
|
|
||||||
$scope.datasource.performHostGroupSuggestQuery().then(function (series) {
|
$scope.datasource.performHostGroupSuggestQuery().then(function (series) {
|
||||||
$scope.metric.hostGroupList = series;
|
$scope.metric.hostGroupList = $scope.metric.hostGroupList.concat(series);
|
||||||
|
|
||||||
if ($scope.target.hostGroup) {
|
if ($scope.target.hostGroup) {
|
||||||
$scope.target.hostGroup = $scope.metric.hostGroupList.filter(function (item, index, array) {
|
$scope.target.hostGroup = $scope.metric.hostGroupList.filter(function (item, index, array) {
|
||||||
// Find selected host in metric.hostList
|
// Find selected host in metric.hostList
|
||||||
return (item.groupid == $scope.target.hostGroup.groupid);
|
return (item.name == $scope.target.hostGroup.name);
|
||||||
}).pop();
|
}).pop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -159,21 +163,16 @@ function (angular, _) {
|
|||||||
* Update list of hosts
|
* Update list of hosts
|
||||||
*/
|
*/
|
||||||
$scope.updateHostList = function(groupid) {
|
$scope.updateHostList = function(groupid) {
|
||||||
$scope.datasource.performHostSuggestQuery(groupid).then(function (series) {
|
$scope.metric.hostList = [];
|
||||||
$scope.metric.hostList = series;
|
addTemplatedVariables($scope.metric.hostList);
|
||||||
|
|
||||||
// Add templated variables
|
$scope.datasource.performHostSuggestQuery(groupid).then(function (series) {
|
||||||
_.each(templateSrv.variables, function(variable) {
|
$scope.metric.hostList = $scope.metric.hostList.concat(series);
|
||||||
$scope.metric.hostList.push({
|
|
||||||
'name': '$' + variable.name,
|
|
||||||
'hostid': 0
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if ($scope.target.host) {
|
if ($scope.target.host) {
|
||||||
$scope.target.host = $scope.metric.hostList.filter(function (item, index, array) {
|
$scope.target.host = $scope.metric.hostList.filter(function (item, index, array) {
|
||||||
// Find selected host in metric.hostList
|
// Find selected host in metric.hostList
|
||||||
return (item.hostid == $scope.target.host.hostid);
|
return (item.name == $scope.target.host.name);
|
||||||
}).pop();
|
}).pop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -184,12 +183,23 @@ function (angular, _) {
|
|||||||
* Update list of host applications
|
* Update list of host applications
|
||||||
*/
|
*/
|
||||||
$scope.updateAppList = function(hostid) {
|
$scope.updateAppList = function(hostid) {
|
||||||
|
$scope.metric.applicationList = [];
|
||||||
|
addTemplatedVariables($scope.metric.applicationList);
|
||||||
|
|
||||||
$scope.datasource.performAppSuggestQuery(hostid).then(function (series) {
|
$scope.datasource.performAppSuggestQuery(hostid).then(function (series) {
|
||||||
$scope.metric.applicationList = series;
|
$scope.metric.applicationList = $scope.metric.applicationList.concat(series);
|
||||||
|
|
||||||
|
// Add templated variables
|
||||||
|
_.each(templateSrv.variables, function(variable) {
|
||||||
|
$scope.metric.applicationList.push({
|
||||||
|
name: '$' + variable.name
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
if ($scope.target.application) {
|
if ($scope.target.application) {
|
||||||
$scope.target.application = $scope.metric.applicationList.filter(function (item, index, array) {
|
$scope.target.application = $scope.metric.applicationList.filter(function (item, index, array) {
|
||||||
// Find selected application in metric.hostList
|
// Find selected application in metric.hostList
|
||||||
return (item.applicationid == $scope.target.application.applicationid);
|
return (item.name == $scope.target.application.name);
|
||||||
}).pop();
|
}).pop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -200,28 +210,39 @@ function (angular, _) {
|
|||||||
* Update list of items
|
* Update list of items
|
||||||
*/
|
*/
|
||||||
$scope.updateItemList = function(hostid, applicationid) {
|
$scope.updateItemList = function(hostid, applicationid) {
|
||||||
|
$scope.metric.itemList = [];
|
||||||
|
addTemplatedVariables($scope.metric.itemList);
|
||||||
|
|
||||||
// Update only if host selected
|
// Update only if host selected
|
||||||
if (hostid) {
|
if (hostid) {
|
||||||
$scope.datasource.performItemSuggestQuery(hostid, applicationid).then(function (series) {
|
$scope.datasource.performItemSuggestQuery(hostid, applicationid).then(function (series) {
|
||||||
$scope.metric.itemList = series;
|
$scope.metric.itemList = $scope.metric.itemList.concat(series);
|
||||||
|
|
||||||
// Expand item parameters
|
// Expand item parameters
|
||||||
$scope.metric.itemList.forEach(function (item, index, array) {
|
$scope.metric.itemList.forEach(function (item, index, array) {
|
||||||
if (item && item.key_ && item.name) {
|
if (item && item.key_ && item.name) {
|
||||||
item.expandedName = expandItemName(item);
|
item.name = expandItemName(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if ($scope.target.item) {
|
if ($scope.target.item) {
|
||||||
$scope.target.item = $scope.metric.itemList.filter(function (item, index, array) {
|
$scope.target.item = $scope.metric.itemList.filter(function (item, index, array) {
|
||||||
// Find selected item in metric.hostList
|
// Find selected item in metric.hostList
|
||||||
return (item.itemid == $scope.target.item.itemid);
|
return (item.name == $scope.target.item.name);
|
||||||
}).pop();
|
}).pop();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function addTemplatedVariables(metricList) {
|
||||||
|
_.each(templateSrv.variables, function(variable) {
|
||||||
|
metricList.push({
|
||||||
|
name: '$' + variable.name,
|
||||||
|
templated: true
|
||||||
|
})
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
$scope.metric.itemList = [];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user