diff --git a/awx/ui/static/js/controllers/Schedules.js b/awx/ui/static/js/controllers/Schedules.js index cda9f9cd45..222621f51f 100644 --- a/awx/ui/static/js/controllers/Schedules.js +++ b/awx/ui/static/js/controllers/Schedules.js @@ -16,7 +16,7 @@ LoadDialogPartial) { ClearScope(); - var base, e, id, parentObject, url; + var base, e, id, url, parentObject; base = $location.path().replace(/^\//, '').split('/')[0]; @@ -52,52 +52,31 @@ LoadDialogPartial) { }); // Change later to use GetBasePath(base) - switch(base) { - case 'job_templates': - url = '/static/sample/data/schedules/data.json'; - break; - case 'projects': - url = '/static/sample/data/schedules/projects/data.json'; - break; - } + //switch(base) { + // case 'job_templates': + // url = '/static/sample/data/schedules/data.json'; + // break; + // case 'projects': + // url = '/static/sample/data/schedules/projects/data.json'; + // break; + //} + + url += "schedules/"; + SearchInit({ scope: $scope, set: 'schedules', list: SchedulesList, url: url }); + PaginateInit({ scope: $scope, list: SchedulesList, url: url }); - Rest.setUrl(url); - Rest.get() - .success(function(data) { - var i, modifier; - PageRangeSetup({ - scope: $scope, - count: data.count, - next: data.next, - previous: data.previous, - iterator: SchedulesList.iterator - }); - $scope[SchedulesList.iterator + 'Loading'] = false; - for (i = 1; i <= 3; i++) { - modifier = (i === 1) ? '' : i; - $scope[SchedulesList.iterator + 'HoldInput' + modifier] = false; - } - $scope.schedules = data.results; - window.scrollTo(0, 0); - Wait('stop'); - $scope.$emit('PostRefresh'); - $scope.schedules = data.results; - }) - .error(function(data, status) { - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + ' failed. GET returned: ' + status }); - }); + $scope.search(SchedulesList.iterator); }); $scope.editSchedule = function(id) { @@ -107,22 +86,7 @@ LoadDialogPartial) { $scope.addSchedule = function() { var schedule = { }; - switch(base) { - case 'job_templates': - schedule.job_template = $routeParams.id; - schedule.job_type = 'playbook_run'; - schedule.job_class = "ansible:playbook"; - break; - case 'inventories': - schedule.inventory = $routeParams.id; - schedule.job_type = 'inventory_sync'; - schedule.job_class = "inventory:sync"; - break; - case 'projects': - schedule.project = $routeParams.id; - schedule.job_type = 'project_sync'; - schedule.job_class = "project:sync"; - } + schedule.enabled = true; AddSchedule({ scope: $scope, schedule: schedule, url: url }); }; @@ -163,7 +127,7 @@ LoadDialogPartial) { $scope.removeLoadParent = $scope.$on('LoadParent', function() { // Load the parent object id = $routeParams.id; - url = GetBasePath(base) + id; + url = GetBasePath(base) + id + '/'; Rest.setUrl(url); Rest.get() .success(function(data) { diff --git a/awx/ui/static/js/helpers/Schedules.js b/awx/ui/static/js/helpers/Schedules.js index 3a4245a2b8..0fb29e7724 100644 --- a/awx/ui/static/js/helpers/Schedules.js +++ b/awx/ui/static/js/helpers/Schedules.js @@ -111,8 +111,8 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) }; }]) - .factory('EditSchedule', ['SchedulerInit', 'ShowSchedulerModal', 'Wait', 'Rest', - function(SchedulerInit, ShowSchedulerModal, Wait, Rest) { + .factory('EditSchedule', ['SchedulerInit', 'ShowSchedulerModal', 'Wait', 'Rest', 'ToAPI', 'ProcessErrors', + function(SchedulerInit, ShowSchedulerModal, Wait, Rest, ToAPI, ProcessErrors) { return function(params) { var scope = params.scope, schedule = params.schedule, @@ -128,7 +128,7 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) scope.showRRuleDetail = false; if (!/DTSTART/.test(schedule.rrule)) { - schedule.rrule += ";DTSTART=" + schedule.dtstart; + schedule.rrule += ";DTSTART=" + schedule.dtstart.replace(/\.\d+Z$/,'Z'); } setTimeout(function(){ @@ -141,22 +141,24 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) }, 500); scope.saveSchedule = function() { - var newSchedule; + var newSchedule, rrule; $('#scheduler-tabs a:first').tab('show'); if (scheduler.isValid()) { Wait('start'); newSchedule = scheduler.getValue(); + rrule = scheduler.getRRule(); schedule.name = newSchedule.name; - schedule.rrule = newSchedule.rrule; + schedule.rrule = ToAPI(rrule.toString()); + schedule.description = (/error/.test(rrule.toText())) ? '' : rrule.toText(); Rest.setUrl(url); Rest.post(schedule) .success(function(){ Wait('stop'); $('#scheduler-modal-dialog').dialog('close'); }) - .error(function(){ - Wait('stop'); - $('#scheduler-modal-dialog').dialog('close'); + .error(function(data, status){ + ProcessErrors(scope, data, status, null, { hdr: 'Error!', + msg: 'POST to ' + url + ' returned: ' + status }); }); } }; @@ -171,8 +173,8 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) }; }]) - .factory('AddSchedule', ['SchedulerInit', 'ShowSchedulerModal', 'Wait', 'Rest', - function(SchedulerInit, ShowSchedulerModal, Wait, Rest) { + .factory('AddSchedule', ['SchedulerInit', 'ShowSchedulerModal', 'Wait', 'Rest', 'ToAPI', 'ProcessErrors', + function(SchedulerInit, ShowSchedulerModal, Wait, Rest, ToAPI, ProcessErrors) { return function(params) { var scope = params.scope, url = params.url, @@ -193,22 +195,24 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) }, 300); scope.saveSchedule = function() { - var newSchedule; + var newSchedule, rrule; $('#scheduler-tabs a:first').tab('show'); if (scheduler.isValid()) { Wait('start'); newSchedule = scheduler.getValue(); + rrule = scheduler.getRRule(); schedule.name = newSchedule.name; - schedule.rrule = newSchedule.rrule; + schedule.rrule = ToAPI(rrule.toString()); + schedule.description = (/error/.test(rrule.toText())) ? '' : rrule.toText(); Rest.setUrl(url); Rest.post(schedule) .success(function(){ Wait('stop'); $('#scheduler-modal-dialog').dialog('close'); }) - .error(function(){ - Wait('stop'); - $('#scheduler-modal-dialog').dialog('close'); + .error(function(data, status){ + ProcessErrors(scope, data, status, null, { hdr: 'Error!', + msg: 'POST to ' + url + ' returned: ' + status }); }); } }; @@ -242,7 +246,7 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) scope.$emit(callback); }) .error(function(data, status) { - ProcessErrors(scope, null, status, null, { hdr: 'Error!', + ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + ' failed. GET returned: ' + status }); }); }; @@ -348,6 +352,16 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) }); }; + }]) + + .factory('ToAPI', [ function() { + return function(rrule) { + var response; + response = rrule.replace(/(^.*(?=DTSTART))(DTSTART=.*?;)(.*$)/, function(str, p1, p2, p3) { + return p2.replace(/\;/,'').replace(/=/,':') + ' ' + 'RRULE:' + p1 + p3; + }); + return response; + }; }]); diff --git a/awx/ui/static/js/lists/Schedules.js b/awx/ui/static/js/lists/Schedules.js index 2a4d6c8464..d60c9404e1 100644 --- a/awx/ui/static/js/lists/Schedules.js +++ b/awx/ui/static/js/lists/Schedules.js @@ -26,19 +26,23 @@ angular.module('SchedulesListDefinition', []) ngClick: "editSchedule(schedule.id)", columnClass: "col-md-5 col-sm-3 col-xs-3" }, - dtstart: { - label: 'Start', + next_run: { + label: 'Next Run', + filter: "date:'MM/dd/yy HH:mm:ss'", searchable: false, columnClass: "col-md-2 col-sm-3 col-xs-3" }, - next_run: { - label: 'Next Run', + dtstart: { + label: 'Start', + filter: "date:'MM/dd/yy HH:mm:ss'", searchable: false, - columnClass: "col-md-2 col-sm-3 col-xs-3" + columnClass: "col-md-2 col-sm-3 hidden-xs" }, dtend: { label: 'End', - searchable: false + filter: "date:'MM/dd/yy HH:mm:ss'", + searchable: false, + columnClass: "col-md-2 col-sm-3 hidden-xs" } },