applying callback mechanism to job tmeplate list

This commit is contained in:
jaredevantabor 2016-12-14 14:59:05 -08:00
parent 976e9bfe82
commit c4ce68b4de
2 changed files with 31 additions and 35 deletions

View File

@ -8,12 +8,12 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest',
'Alert','TemplateList', 'Prompt', 'ClearScope', 'ProcessErrors',
'GetBasePath', 'InitiatePlaybookRun', 'Wait', '$state', '$filter',
'Dataset', 'rbacUiControlService', 'TemplatesService','QuerySet',
'GetChoices', 'TemplateCopyService', 'DataOptions',
'GetChoices', 'TemplateCopyService',
function(
$scope, $rootScope, $location, $stateParams, Rest, Alert,
TemplateList, Prompt, ClearScope, ProcessErrors, GetBasePath,
InitiatePlaybookRun, Wait, $state, $filter, Dataset, rbacUiControlService, TemplatesService,
qs, GetChoices, TemplateCopyService, DataOptions
qs, GetChoices, TemplateCopyService
) {
ClearScope();
@ -37,29 +37,39 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest',
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.options = DataOptions;
$scope.options = {};
$rootScope.flashMessage = null;
$scope.$watchCollection('templates', function() {
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.type) {
$scope.options.type.choices.every(function(choice) {
if (choice[0] === item.type) {
itm.type_label = choice[1];
return false;
}
return true;
});
}
});
}
);
}
$scope.$on(`${list.iterator}_options`, function(event, data){
debugger;
$scope.options = data.data.actions.GET;
optionsRequestDataProcessing();
});
$scope.$watchCollection('templates', function() {
optionsRequestDataProcessing();
}
);
// iterate over the list and add fields like type label, after the
// OPTIONS request returns, or the list is sorted/paginated/searched
function optionsRequestDataProcessing(){
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
// Set the item type label
if (list.fields.type && $scope.options.hasOwnProperty('type')) {
$scope.options.type.choices.every(function(choice) {
if (choice[0] === item.type) {
itm.type_label = choice[1];
return false;
}
return true;
});
}
});
}
$scope.$on(`ws-jobs`, function () {

View File

@ -46,20 +46,6 @@ export default {
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
return qs.search(path, $stateParams[`${list.iterator}_search`]);
}
],
DataOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', 'TemplateList',
function(Rest, GetBasePath, $stateParams, $q, list) {
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
Rest.setUrl(path);
var val = $q.defer();
Rest.options()
.then(function(data) {
val.resolve(data.data.actions.GET);
}, function(data) {
val.reject(data);
});
return val.promise;
}
]
}
};