don't be looping if there ain't nothing to loop on

This commit is contained in:
Chris Meyers
2017-01-27 13:53:57 -05:00
parent 1b0c2cbb32
commit 08832428cc

View File

@@ -38,31 +38,34 @@ export function CredentialsList($scope, $rootScope, $location, $log,
$scope.$on(`${list.iterator}_options`, function(event, data){ $scope.$on(`${list.iterator}_options`, function(event, data){
$scope.options = data.data.actions.GET; $scope.options = data.data.actions.GET;
console.log($scope.options);
optionsRequestDataProcessing(); optionsRequestDataProcessing();
}); });
$scope.$watchCollection(`${$scope.list.name}`, function() { $scope.$watchCollection(`${$scope.list.name}`, function() {
optionsRequestDataProcessing(); optionsRequestDataProcessing();
} });
);
// iterate over the list and add fields like type label, after the // iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched // OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){ function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) { if ($scope[list.name] !== undefined) {
var itm = $scope[list.name][item_idx]; $scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label // Set the item type label
if (list.fields.kind && $scope.options && if (list.fields.kind && $scope.options &&
$scope.options.hasOwnProperty('kind')) { $scope.options.hasOwnProperty('kind')) {
$scope.options.kind.choices.every(function(choice) { $scope.options.kind.choices.every(function(choice) {
if (choice[0] === item.kind) { if (choice[0] === item.kind) {
itm.kind_label = choice[1]; itm.kind_label = choice[1];
return false; return false;
} }
return true; return true;
}); });
} }
}); });
}
} }
$scope.addCredential = function() { $scope.addCredential = function() {