diff --git a/awx/ui/client/src/management-jobs/scheduler/main.js b/awx/ui/client/src/management-jobs/scheduler/main.js index 49498debbd..4a9bc10217 100644 --- a/awx/ui/client/src/management-jobs/scheduler/main.js +++ b/awx/ui/client/src/management-jobs/scheduler/main.js @@ -40,7 +40,7 @@ export default }); $stateExtender.addState({ name: 'managementJobSchedules.edit', - route: '/add', + route: '/edit/:schedule_id', templateUrl: templateUrl('management-jobs/scheduler/schedulerForm'), controller: 'managementJobEditController', resolve: { diff --git a/awx/ui/client/src/scheduler/main.js b/awx/ui/client/src/scheduler/main.js index 5d322e828f..46fa46d94e 100644 --- a/awx/ui/client/src/scheduler/main.js +++ b/awx/ui/client/src/scheduler/main.js @@ -34,15 +34,7 @@ export default resolve: { features: ['FeaturesService', function(FeaturesService) { return FeaturesService.get(); - }], - JobTemplateExtraVars: ['Rest', 'GetBasePath', 'ToJSON', '$stateParams', function(Rest, GetBasePath, ToJSON, $stateParams) { - var defaultUrl = GetBasePath('job_templates') + $stateParams.id + '/'; - Rest.setUrl(defaultUrl); - return Rest.get().then(function(res){ - // handle unescaped newlines - return JSON.parse(JSON.stringify(res.data.extra_vars)) - }); - }] + }] } }); $stateExtender.addState({ diff --git a/awx/ui/client/src/scheduler/schedulerAdd.controller.js b/awx/ui/client/src/scheduler/schedulerAdd.controller.js index 3022092a6f..4bb6cd9ac1 100644 --- a/awx/ui/client/src/scheduler/schedulerAdd.controller.js +++ b/awx/ui/client/src/scheduler/schedulerAdd.controller.js @@ -1,8 +1,7 @@ -export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'JobTemplateExtraVars', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, JobTemplateExtraVars) { +export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'GetBasePath', 'Rest', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, GetBasePath, Rest) { $scope.$on("ScheduleFormCreated", function(e, scope) { $scope.hideForm = false; $scope = angular.extend($scope, scope); - $scope.$on("formUpdated", function() { $rootScope.$broadcast("loadSchedulerDetailPane"); }); @@ -46,29 +45,47 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s $state.go("^"); }; - $scope.parseType = 'yaml'; - $scope.extraVars = JobTemplateExtraVars === '' ? '---' : JobTemplateExtraVars; - ParseTypeChange({ - scope: $scope, - variable: 'extraVars', - parse_variable: 'parseType', - field_id: 'SchedulerForm-extraVars' - }); - - $scope.$watch('extraVars', function(){ - if ($scope.parseType === 'yaml'){ - try{ - $scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars); + // extra_data field is not manifested in the UI when scheduling a Management Job + if ($state.current.name === 'jobTemplateSchedules.add'){ + $scope.parseType = 'yaml'; + var defaultUrl = GetBasePath('job_templates') + $stateParams.id + '/'; + Rest.setUrl(defaultUrl); + Rest.get().then(function(res){ + // sanitize + var data = JSON.parse(JSON.stringify(res.data.extra_vars)); + $scope.extraVars = data === '' ? '---' : data; + ParseTypeChange({ + scope: $scope, + variable: 'extraVars', + parse_variable: 'parseType', + field_id: 'SchedulerForm-extraVars' + }); + }); + $scope.$watch('extraVars', function(){ + if ($scope.parseType === 'yaml'){ + try{ + $scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars); + } + catch(err){ return; } } - catch(err){ return; } - } - else if ($scope.parseType === 'json'){ - try{ - $scope.serializedExtraVars = JSON.parse($scope.extraVars); + else if ($scope.parseType === 'json'){ + try{ + $scope.serializedExtraVars = JSON.parse($scope.extraVars); + } + catch(err){ return; } } - catch(err){ return; } - } - }); + }); + } + else if ($state.current.name === 'projectSchedules.add'){ + $scope.extraVars = '---'; + $scope.parseType = 'yaml'; + ParseTypeChange({ + scope: $scope, + variable: 'extraVars', + parse_variable: 'parseType', + field_id: 'SchedulerForm-extraVars' + }); + } AddSchedule({ scope: $scope, @@ -88,4 +105,5 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s }); callSelect2(); + }]; diff --git a/awx/ui/client/src/scheduler/schedulerEdit.controller.js b/awx/ui/client/src/scheduler/schedulerEdit.controller.js index 48b57151ec..f75b47a51f 100644 --- a/awx/ui/client/src/scheduler/schedulerEdit.controller.js +++ b/awx/ui/client/src/scheduler/schedulerEdit.controller.js @@ -48,41 +48,44 @@ export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$ $state.go("^"); } - $scope.$on('ScheduleFound', function(){ - if ($scope.parseType === 'yaml'){ - try{ - $scope.extraVars = '---\n' + jsyaml.safeDump($scope.serializedExtraVars); + // extra_data field is not manifested in the UI when scheduling a Management Job + if ($state.current.name !== ('managementJobSchedules.add' || 'managementJobSchedules.edit')){ + $scope.$on('ScheduleFound', function(){ + if ($scope.parseType === 'yaml'){ + try{ + $scope.extraVars = '---\n' + jsyaml.safeDump($scope.serializedExtraVars); + } + catch(err){ return; } } - catch(err){ return; } - } - else if ($scope.parseType === 'json'){ - try{ - $scope.extraVars = JSON.stringify($scope.serializedExtraVars, null, ' '); + else if ($scope.parseType === 'json'){ + try{ + $scope.extraVars = JSON.stringify($scope.serializedExtraVars, null, ' '); + } + catch(err){ return; } } - catch(err){ return; } - } - ParseTypeChange({ - scope: $scope, - variable: 'extraVars', - parse_variable: 'parseType', - field_id: 'SchedulerForm-extraVars' + ParseTypeChange({ + scope: $scope, + variable: 'extraVars', + parse_variable: 'parseType', + field_id: 'SchedulerForm-extraVars' + }); }); - }); - - $scope.$watch('extraVars', function(){ - if ($scope.parseType === 'yaml'){ - try{ - $scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars); + + $scope.$watch('extraVars', function(){ + if ($scope.parseType === 'yaml'){ + try{ + $scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars); + } + catch(err){ return; } } - catch(err){ return; } - } - else if ($scope.parseType === 'json'){ - try{ - $scope.serializedExtraVars = JSON.parse($scope.extraVars); + else if ($scope.parseType === 'json'){ + try{ + $scope.serializedExtraVars = JSON.parse($scope.extraVars); + } + catch(err){ return; } } - catch(err){ return; } - } - }); + }); + } EditSchedule({ scope: $scope,