diff --git a/awx/ui/client/src/job-detail/job-detail.factory.js b/awx/ui/client/src/job-detail/host-event/host-event.route.js similarity index 100% rename from awx/ui/client/src/job-detail/job-detail.factory.js rename to awx/ui/client/src/job-detail/host-event/host-event.route.js diff --git a/awx/ui/client/src/job-detail/job-detail.controller.js b/awx/ui/client/src/job-detail/job-detail.controller.js index 447cec8d8c..e36dbb13de 100644 --- a/awx/ui/client/src/job-detail/job-detail.controller.js +++ b/awx/ui/client/src/job-detail/job-detail.controller.js @@ -1,5 +1,5 @@ /************************************************* - * Copyright (c) 2015 Ansible, Inc. + * Copyright (c) 2016 Ansible, Inc. * * All Rights Reserved *************************************************/ @@ -12,23 +12,22 @@ export default [ '$location', '$rootScope', '$filter', '$scope', '$compile', - '$stateParams', '$log', 'ClearScope', 'GetBasePath', 'Wait', 'Rest', + '$stateParams', '$log', 'ClearScope', 'GetBasePath', 'Wait', 'ProcessErrors', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'DrawGraph', 'LoadHostSummary', 'ReloadHostSummaryList', - 'JobIsFinished', 'SetTaskStyles', 'DigestEvent', 'UpdateDOM', - 'EventViewer', 'DeleteJob', 'PlaybookRun', 'HostEventsViewer', + 'JobIsFinished', 'SetTaskStyles', 'DigestEvent', 'UpdateDOM', 'DeleteJob', 'PlaybookRun', 'HostEventsViewer', 'LoadPlays', 'LoadTasks', 'LoadHosts', 'HostsEdit', 'ParseVariableString', 'GetChoices', 'fieldChoices', 'fieldLabels', - 'EditSchedule', 'ParseTypeChange', + 'EditSchedule', 'ParseTypeChange', 'JobDetailService', 'EventViewer', function( $location, $rootScope, $filter, $scope, $compile, $stateParams, - $log, ClearScope, GetBasePath, Wait, Rest, ProcessErrors, + $log, ClearScope, GetBasePath, Wait, ProcessErrors, SelectPlay, SelectTask, Socket, GetElapsed, DrawGraph, LoadHostSummary, ReloadHostSummaryList, JobIsFinished, - SetTaskStyles, DigestEvent, UpdateDOM, EventViewer, DeleteJob, + SetTaskStyles, DigestEvent, UpdateDOM, DeleteJob, PlaybookRun, HostEventsViewer, LoadPlays, LoadTasks, LoadHosts, HostsEdit, ParseVariableString, GetChoices, fieldChoices, - fieldLabels, EditSchedule, ParseTypeChange + fieldLabels, EditSchedule, ParseTypeChange, JobDetailService, EventViewer ) { ClearScope(); @@ -283,15 +282,15 @@ export default scope.removeInitialLoadComplete(); } scope.removeInitialLoadComplete = scope.$on('InitialLoadComplete', function() { - var url; Wait('stop'); if (JobIsFinished(scope)) { scope.liveEventProcessing = false; // signal that event processing is over and endless scroll scope.pauseLiveEvents = false; // should be enabled - url = scope.job.related.job_events + '?event=playbook_on_stats'; - Rest.setUrl(url); - Rest.get() + var params = { + event: 'playbook_on_stats' + }; + JobDetailService.getRelatedJobEvents(scope.job.id, params) .success(function(data) { if (data.results.length > 0) { LoadHostSummary({ @@ -327,11 +326,11 @@ export default } scope.removeHostSummaries = scope.$on('LoadHostSummaries', function() { if(scope.job){ - var url = scope.job.related.job_host_summaries + '?'; - url += '&page_size=' + scope.hostSummariesMaxRows + '&order=host_name'; - - Rest.setUrl(url); - Rest.get() + var params = { + page_size: scope.hostSummariesMaxRows, + order: 'host_name' + }; + JobDetailService.getJobHostSummaries(scope.job.id, params) .success(function(data) { scope.next_host_summaries = data.next; if (data.results.length > 0) { @@ -357,10 +356,6 @@ export default }; }); scope.$emit('InitialLoadComplete'); - }) - .error(function(data, status) { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + '. GET returned: ' + status }); }); } @@ -373,17 +368,17 @@ export default if (scope.activeTask) { var play = scope.jobData.plays[scope.activePlay], - task, // = play.tasks[scope.activeTask], - url; + task; if(play){ task = play.tasks[scope.activeTask]; } if (play && task) { - url = scope.job.related.job_events + '?parent=' + task.id + '&'; - url += 'event__startswith=runner&page_size=' + scope.hostResultsMaxRows + '&order=host_name,counter'; - - Rest.setUrl(url); - Rest.get() + var params = { + parent: task.id, + event__startswith: 'runner', + page_size: scope.hostResultsMaxRows + }; + JobDetailService.getRelatedJobEvents(scope.job.id, params) .success(function(data) { var idx, event, status, status_text, item, msg; if (data.results.length > 0) { @@ -450,10 +445,6 @@ export default } } scope.$emit('LoadHostSummaries'); - }) - .error(function(data, status) { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + '. GET returned: ' + status }); }); } else { scope.$emit('LoadHostSummaries'); @@ -468,14 +459,15 @@ export default } scope.removeLoadTasks = scope.$on('LoadTasks', function() { if (scope.activePlay) { - var play = scope.jobData.plays[scope.activePlay], url; + var play = scope.jobData.plays[scope.activePlay]; if (play) { - url = scope.job.url + 'job_tasks/?event_id=' + play.id; - url += '&page_size=' + scope.tasksMaxRows + '&order=id'; - - Rest.setUrl(url); - Rest.get() + var params = { + event_id: play.id, + page_size: scope.tasksMaxRows, + order: 'id' + } + JobDetailService.getJobTasks(scope.job.id, params) .success(function(data) { scope.next_tasks = data.next; if (data.results.length > 0) { @@ -585,12 +577,10 @@ export default scope.host_summary.failed = 0; scope.host_summary.total = 0; scope.jobData.plays = {}; - - var url = scope.job.url + 'job_plays/?order_by=id'; - url += '&page_size=' + scope.playsMaxRows + '&order_by=id'; - - Rest.setUrl(url); - Rest.get() + var params = { + order_by: 'id' + }; + JobDetailService.getJobPlays(scope.job.id, params) .success( function(data) { scope.next_plays = data.next; if (data.results.length > 0) { @@ -681,10 +671,6 @@ export default scope.jobData.plays[scope.activePlay].playActiveClass = 'JobDetail-tableRow--selected'; } scope.$emit('LoadTasks', events_url); - }) - .error( function(data, status) { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + '. GET returned: ' + status }); }); }); @@ -702,8 +688,7 @@ export default scope.LoadHostSummaries = true; // Load the job record - Rest.setUrl(GetBasePath('jobs') + job_id + '/'); - Rest.get() + JobDetailService.getJob(job_id) .success(function(data) { var i; scope.job = data; @@ -1177,8 +1162,7 @@ export default if (((!scope.liveEventProcessing) || (scope.liveEventProcessing && scope.pauseLiveEvents)) && scope.next_plays) { $('#playsMoreRows').fadeIn(); scope.playsLoading = true; - Rest.setUrl(scope.next_plays); - Rest.get() + JobDetailService.getNextPage(scope.next_plays) .success( function(data) { scope.next_plays = data.next; data.results.forEach(function(event, idx) { @@ -1243,8 +1227,7 @@ export default if (((!scope.liveEventProcessing) || (scope.liveEventProcessing && scope.pauseLiveEvents)) && scope.next_tasks) { $('#tasksMoreRows').fadeIn(); scope.tasksLoading = true; - Rest.setUrl(scope.next_tasks); - Rest.get() + JobDetailService.getNextPage(scope.next_tasks) .success(function(data) { scope.next_tasks = data.next; data.results.forEach(function(event, idx) { @@ -1315,8 +1298,7 @@ export default if (((!scope.liveEventProcessing) || (scope.liveEventProcessing && scope.pauseLiveEvents)) && scope.next_host_results) { $('#hostResultsMoreRows').fadeIn(); scope.hostResultsLoading = true; - Rest.setUrl(scope.next_host_results); - Rest.get() + JobDetailService.getNextPage(scope.next_host_results) .success(function(data) { scope.next_host_results = data.next; data.results.forEach(function(row) { @@ -1387,8 +1369,7 @@ export default // check for more hosts when user scrolls to bottom of host summaries list... if (((!scope.liveEventProcessing) || (scope.liveEventProcessing && scope.pauseLiveEvents)) && scope.next_host_summaries) { scope.hostSummariesLoading = true; - Rest.setUrl(scope.next_host_summaries); - Rest.get() + JobDetailService.getNextPage(scope.next_host_summaries) .success(function(data) { scope.next_host_summaries = data.next; data.results.forEach(function(row) { diff --git a/awx/ui/client/src/job-detail/job-detail.partial.html b/awx/ui/client/src/job-detail/job-detail.partial.html index 8bbbc4aaaa..3ff7262d1c 100644 --- a/awx/ui/client/src/job-detail/job-detail.partial.html +++ b/awx/ui/client/src/job-detail/job-detail.partial.html @@ -344,7 +344,7 @@ - + diff --git a/awx/ui/client/src/job-detail/job-detail.service.js b/awx/ui/client/src/job-detail/job-detail.service.js new file mode 100644 index 0000000000..8597fff9f1 --- /dev/null +++ b/awx/ui/client/src/job-detail/job-detail.service.js @@ -0,0 +1,118 @@ +export default + ['$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors', function($rootScope, Rest, GetBasePath, ProcessErrors){ + return { + + /* + For ES6 + it might be useful to set some default params here, e.g. + getJobHostSummaries: function(id, page_size=200, order='host_name'){} + without ES6, we'd have to supply defaults like this: + this.page_size = params.page_size ? params.page_size : 200; + */ + + // GET events related to a job run + // e.g. + // ?event=playbook_on_stats + // ?parent=206&event__startswith=runner&page_size=200&order=host_name,counter + getRelatedJobEvents: function(id, params){ + var url = GetBasePath('jobs'); + url = url + id + '/job_events/?'; + Object.keys(params).forEach(function(key, index) { + // the API is tolerant of extra ampersands + // ?&event=playbook_on_start == ?event=playbook_on_stats + url = url + '&' + key + '=' + params[key]; + }); + Rest.setUrl(url); + return Rest.get() + .success(function(data){ + return data + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + }, + // GET job host summaries related to a job run + // e.g. ?page_size=200&order=host_name + getJobHostSummaries: function(id, params){ + var url = GetBasePath('jobs'); + url = url + id + '/job_host_summaries/?' + Object.keys(params).forEach(function(key, index) { + // the API is tolerant of extra ampersands + url = url + '&' + key + '=' + params[key]; + }); + Rest.setUrl(url); + return Rest.get() + .success(function(data){ + return data + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + }, + // GET job plays related to a job run + // e.g. ?page_size=200 + getJobPlays: function(id, params){ + var url = GetBasePath('jobs'); + url = url + id + '/job_plays/?'; + Object.keys(params).forEach(function(key, index) { + // the API is tolerant of extra ampersands + url = url + '&' + key + '=' + params[key]; + }); + Rest.setUrl(url); + return Rest.get() + .success(function(data){ + return data + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + }, + getJobTasks: function(id, params){ + var url = GetBasePath('jobs'); + url = url + id + '/job_tasks/?'; + Object.keys(params).forEach(function(key, index) { + // the API is tolerant of extra ampersands + url = url + '&' + key + '=' + params[key]; + }); + Rest.setUrl(url); + return Rest.get() + .success(function(data){ + return data + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + }, + getJob: function(id){ + var url = GetBasePath('jobs'); + url = url + id; + Rest.setUrl(url); + return Rest.get() + .success(function(data){ + return data + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + }, + // GET next set of paginated results + // expects 'next' param returned by the API e.g. + // "/api/v1/jobs/51/job_plays/?order_by=id&page=2&page_size=1" + getNextPage: function(url){ + return Rest.get() + .success(function(data){ + return data + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + url + '. GET returned: ' + status }); + }); + } + } + } + ]; \ No newline at end of file diff --git a/awx/ui/client/src/job-detail/main.js b/awx/ui/client/src/job-detail/main.js index 42e9cae45c..d985a310e6 100644 --- a/awx/ui/client/src/job-detail/main.js +++ b/awx/ui/client/src/job-detail/main.js @@ -6,10 +6,12 @@ import route from './job-detail.route'; import controller from './job-detail.controller'; +import service from './job-detail.service'; export default angular.module('jobDetail', []) .controller('JobDetailController', controller) + .service('JobDetailService', service) .run(['$stateExtender', function($stateExtender) { $stateExtender.addState(route); }]);
{{ result.name }}{{ result.name }}{{ result.name }}{{ result.name }} {{ result.item }} {{ result.msg }}