From b78ed36abf3e9e05cb56517bdb57408a5ca49be5 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Thu, 15 Dec 2016 13:47:12 -0800 Subject: [PATCH] post processing for scheduled jobs list --- awx/ui/client/src/controllers/Schedules.js | 2 +- awx/ui/client/src/lists/ScheduledJobs.js | 3 +- awx/ui/client/src/scheduler/main.js | 54 +++++++++++++- .../src/scheduler/schedulerList.controller.js | 72 ++++++++++++++----- 4 files changed, 106 insertions(+), 25 deletions(-) diff --git a/awx/ui/client/src/controllers/Schedules.js b/awx/ui/client/src/controllers/Schedules.js index edebf66a84..5a29150215 100644 --- a/awx/ui/client/src/controllers/Schedules.js +++ b/awx/ui/client/src/controllers/Schedules.js @@ -65,7 +65,7 @@ GetBasePath, Wait, Find, LoadSchedulesScope, GetChoices) { msg: 'Call to ' + url + ' failed. GET returned: ' + status }); }); }); - + debugger; $scope.refreshJobs = function() { // @issue: OLD SEARCH // $scope.search(SchedulesList.iterator); diff --git a/awx/ui/client/src/lists/ScheduledJobs.js b/awx/ui/client/src/lists/ScheduledJobs.js index e4a17496c6..a771a75b8f 100644 --- a/awx/ui/client/src/lists/ScheduledJobs.js +++ b/awx/ui/client/src/lists/ScheduledJobs.js @@ -31,8 +31,7 @@ export default name: { label: i18n._('Name'), columnClass: 'col-lg-4 col-md-5 col-sm-5 col-xs-7 List-staticColumnAdjacent', - sourceModel: 'unified_job_template', - sourceField: 'name', + ngBind: 'schedule.summary_fields.unified_job_template.name', ngClick: "editSchedule(schedule)", awToolTip: "{{ schedule.nameTip | sanitize}}", dataTipWatch: 'schedule.nameTip', diff --git a/awx/ui/client/src/scheduler/main.js b/awx/ui/client/src/scheduler/main.js index 840197d944..f8620c880e 100644 --- a/awx/ui/client/src/scheduler/main.js +++ b/awx/ui/client/src/scheduler/main.js @@ -45,7 +45,19 @@ export default let path = `${GetBasePath('job_templates')}${$stateParams.id}`; Rest.setUrl(path); return Rest.get(path).then((res) => res.data); - }] + }], + UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', + function(Rest, GetBasePath, $stateParams, $q) { + Rest.setUrl(GetBasePath('unified_jobs')); + var val = $q.defer(); + Rest.options() + .then(function(data) { + val.resolve(data.data); + }, function(data) { + val.reject(data); + }); + return val.promise; + }] }, views: { '@': { @@ -119,7 +131,19 @@ export default let path = `${GetBasePath('workflow_job_templates')}${$stateParams.id}`; Rest.setUrl(path); return Rest.get(path).then((res) => res.data); - }] + }], + UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', + function(Rest, GetBasePath, $stateParams, $q) { + Rest.setUrl(GetBasePath('unified_jobs')); + var val = $q.defer(); + Rest.options() + .then(function(data) { + val.resolve(data.data); + }, function(data) { + val.reject(data); + }); + return val.promise; + }] }, views: { '@': { @@ -190,7 +214,19 @@ export default let path = `${GetBasePath('projects')}${$stateParams.id}`; Rest.setUrl(path); return Rest.get(path).then((res) => res.data); - }] + }], + UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', + function(Rest, GetBasePath, $stateParams, $q) { + Rest.setUrl(GetBasePath('unified_jobs')); + var val = $q.defer(); + Rest.options() + .then(function(data) { + val.resolve(data.data); + }, function(data) { + val.reject(data); + }); + return val.promise; + }] }, views: { '@': { @@ -268,6 +304,18 @@ export default } ], ParentObject: [() =>{return {endpoint:'/api/v1/schedules'}; }], + UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q', + function(Rest, GetBasePath, $stateParams, $q) { + Rest.setUrl(GetBasePath('unified_jobs')); + var val = $q.defer(); + Rest.options() + .then(function(data) { + val.resolve(data.data); + }, function(data) { + val.reject(data); + }); + return val.promise; + }] }, views: { 'list@jobs': { diff --git a/awx/ui/client/src/scheduler/schedulerList.controller.js b/awx/ui/client/src/scheduler/schedulerList.controller.js index e003ea1fd2..4f9e9809d3 100644 --- a/awx/ui/client/src/scheduler/schedulerList.controller.js +++ b/awx/ui/client/src/scheduler/schedulerList.controller.js @@ -14,12 +14,12 @@ export default [ '$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest', 'ProcessErrors', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Wait', 'rbacUiControlService', - 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetChoices', '$q', '$state', 'Dataset', 'ParentObject', + 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetChoices', '$q', '$state', 'Dataset', 'ParentObject', 'UnifiedJobsOptions', function($scope, $compile, $location, $stateParams, SchedulesList, Rest, ProcessErrors, ReturnToCaller, ClearScope, GetBasePath, Wait, rbacUiControlService, Find, ToggleSchedule, DeleteSchedule, GetChoices, - $q, $state, Dataset, ParentObject) { + $q, $state, Dataset, ParentObject, UnifiedJobsOptions) { ClearScope(); @@ -43,11 +43,45 @@ export default [ $scope.list = list; $scope[`${list.iterator}_dataset`] = Dataset.data; $scope[list.name] = $scope[`${list.iterator}_dataset`].results; + $scope.unified_job_options = UnifiedJobsOptions.actions.GET; - _.forEach($scope[list.name], buildTooltips); + // _.forEach($scope[list.name], buildTooltips); + } + + $scope.$on(`${list.iterator}_options`, function(event, data){ + $scope.options = data.data.actions.GET; + optionsRequestDataProcessing(); + }); + + $scope.$watchCollection(`${$scope.list.name}`, 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.unified_job_options && + $scope.unified_job_options.hasOwnProperty('type')) { + $scope.unified_job_options.type.choices.every(function(choice) { + if (choice[0] === itm.summary_fields.unified_job_template.unified_job_type) { + itm.type_label = choice[1]; + return false; + } + return true; + }); + } + buildTooltips(itm); + + }); } function buildTooltips(schedule) { + var job = schedule.summary_fields.unified_job_template; if (schedule.enabled) { schedule.play_tip = 'Schedule is active. Click to stop.'; schedule.status = 'active'; @@ -57,6 +91,18 @@ export default [ schedule.status = 'stopped'; schedule.status_tip = 'Schedule is stopped. Click to activate.'; } + + schedule.nameTip = schedule.name; + // include the word schedule if the schedule name does not include the word schedule + if (schedule.name.indexOf("schedule") === -1 && schedule.name.indexOf("Schedule") === -1) { + schedule.nameTip += " schedule"; + } + schedule.nameTip += " for "; + if (job.name.indexOf("job") === -1 && job.name.indexOf("Job") === -1) { + schedule.nameTip += "job "; + } + schedule.nameTip += job.name; + schedule.nameTip += ". Click to edit schedule."; } $scope.refreshSchedules = function() { @@ -99,7 +145,7 @@ export default [ name: 'projectSchedules.edit', params: { id: schedule.unified_job_template, - schedule_id: schedule.id + schedule_id: schedule.id } }); break; @@ -109,7 +155,7 @@ export default [ name: 'managementJobSchedules.edit', params: { id: schedule.unified_job_template, - schedule_id: schedule.id + schedule_id: schedule.id } }); break; @@ -136,7 +182,7 @@ export default [ throw err; } }); - }); + }); } }; @@ -160,7 +206,7 @@ export default [ }; base = $location.path().replace(/^\//, '').split('/')[0]; - + if (base === 'management_jobs') { $scope.base = base = 'system_job_templates'; } @@ -175,17 +221,5 @@ export default [ $scope.formCancel = function() { $state.go('^', null, { reload: true }); }; - - // @issue - believe this is no longer necessary now that parent object is resolved prior to controller initilizing - - // Wait('start'); - - // GetChoices({ - // scope: $scope, - // url: GetBasePath('unified_jobs'), //'/static/sample/data/types/data.json' - // field: 'type', - // variable: 'type_choices', - // callback: 'choicesReady' - // }); } ];