From d2f267c34c32998609e97ac6d65ca8d178ccfc2f Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Mon, 12 Dec 2016 18:21:35 -0800 Subject: [PATCH] fixing options request for template list --- .../list/templates-list.controller.js | 56 +++++++++---------- .../templates/list/templates-list.route.js | 14 +++++ 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/awx/ui/client/src/templates/list/templates-list.controller.js b/awx/ui/client/src/templates/list/templates-list.controller.js index 93f32807ea..ff75f8f79b 100644 --- a/awx/ui/client/src/templates/list/templates-list.controller.js +++ b/awx/ui/client/src/templates/list/templates-list.controller.js @@ -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 diff --git a/awx/ui/client/src/templates/list/templates-list.route.js b/awx/ui/client/src/templates/list/templates-list.route.js index e615e52db1..5a79700bdb 100644 --- a/awx/ui/client/src/templates/list/templates-list.route.js +++ b/awx/ui/client/src/templates/list/templates-list.route.js @@ -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; + } ] } };