fixing options request for template list

This commit is contained in:
jaredevantabor 2016-12-12 18:21:35 -08:00
parent 9c444e084e
commit d2f267c34c
2 changed files with 39 additions and 31 deletions

View File

@ -4,15 +4,16 @@
* All Rights Reserved
*************************************************/
export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest', 'Alert',
'TemplateList', 'Prompt', 'ClearScope', 'ProcessErrors', 'GetBasePath',
'InitiatePlaybookRun', 'Wait', '$state', '$filter', 'Dataset', 'rbacUiControlService', 'TemplatesService',
'QuerySet', 'GetChoices', 'TemplateCopyService',
export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest',
'Alert','TemplateList', 'Prompt', 'ClearScope', 'ProcessErrors',
'GetBasePath', 'InitiatePlaybookRun', 'Wait', '$state', '$filter',
'Dataset', 'rbacUiControlService', 'TemplatesService','QuerySet',
'GetChoices', 'TemplateCopyService', 'DataOptions',
function(
$scope, $rootScope, $location, $stateParams, Rest, Alert,
TemplateList, Prompt, ClearScope, ProcessErrors, GetBasePath,
InitiatePlaybookRun, Wait, $state, $filter, Dataset, rbacUiControlService, TemplatesService,
qs, GetChoices, TemplateCopyService
qs, GetChoices, TemplateCopyService, DataOptions
) {
ClearScope();
@ -36,38 +37,31 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Rest', 'Al
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.options = DataOptions;
$rootScope.flashMessage = null;
if ($scope.removeChoicesReady) {
$scope.removeChoicesReady();
}
$scope.removeChoicesReady = $scope.$on('choicesReady', function() {
$scope[list.name].forEach(function(item, item_idx) {
var itm = $scope[list.name][item_idx];
$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.type_choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
return false;
}
return true;
});
}
});
});
GetChoices({
scope: $scope,
url: GetBasePath('unified_job_templates'),
field: 'type',
variable: 'type_choices',
callback: 'choicesReady'
});
// 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(`ws-jobs`, function () {
// @issue - this is no longer quite as ham-fisted but I'd like for someone else to take a peek
// calling $state.reload(); here was problematic when launching a job because job launch also

View File

@ -46,6 +46,20 @@ 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;
}
]
}
};