From b47aed5bdb361171ecbf623bf951b2f50723dc90 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 26 Mar 2014 12:04:02 -0400 Subject: [PATCH] Wired up job relaunch for each type of job. --- awx/ui/static/js/controllers/Jobs.js | 59 ++++++++++++++++++++++--- awx/ui/static/js/helpers/Jobs.js | 49 +++++++++++++++++++- awx/ui/static/js/lists/CompletedJobs.js | 3 +- awx/ui/static/js/lists/QueuedJobs.js | 3 +- awx/ui/static/js/lists/RunningJobs.js | 3 +- 5 files changed, 107 insertions(+), 10 deletions(-) diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index 6befd935e2..6c659aebdb 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -11,13 +11,13 @@ 'use strict'; function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBreadCrumbs, LoadScope, RunningJobsList, CompletedJobsList, QueuedJobsList, - ScheduledJobsList, GetChoices, GetBasePath, Wait, DeleteJob, Find, DeleteSchedule, ToggleSchedule) { + ScheduledJobsList, GetChoices, GetBasePath, Wait, DeleteJob, Find, DeleteSchedule, ToggleSchedule, RelaunchInventory, RelaunchPlaybook, RelaunchSCM) { ClearScope(); var e, completed_scope, running_scope, queued_scope, scheduled_scope, - choicesCount = 0, listsCount = 0; + choicesCount = 0, listsCount = 0, relaunch, getTypeId; LoadBreadCrumbs(); @@ -26,6 +26,36 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea e.html(Breadcrumbs({ list: { editTitle: 'Jobs' } , mode: 'edit' })); $compile(e)($scope); + relaunch = function(params) { + var scope = params.scope, + id = params.id, + type = params.type, + name = params.name; + if (type === 'inventory_sync') { + RelaunchInventory({ scope: scope, id: id}); + } + else if (type === 'playbook_run') { + RelaunchPlaybook({ scope: scope, id: id, name: name }); + } + else if (type === 'scm_sync') { + RelaunchSCM({ }); + } + }; + + getTypeId = function(job) { + var type_id; + if (job.type === 'inventory_sync') { + type_id = job.inventory_source; + } + else if (job.type === 'scm_sync') { + type_id = job.poject; + } + else if (job.type === 'playbook_run') { + type_id = job.id; + } + return type_id; + }; + // After all the lists are loaded if ($scope.removeListLoaded) { $scope.removeListLoaded(); @@ -109,6 +139,24 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea callback: 'SchedulesRefresh' }); }; + + completed_scope.relaunch = function(id) { + var job = Find({ list: completed_scope.completed_jobs, key: 'id', val: id }), + type_id = getTypeId(job); + relaunch({ scope: completed_scope, id: type_id, type: job.type, name: job.name }); + }; + + running_scope.relaunch = function(id) { + var job = Find({ list: running_scope.running_jobs, key: 'id', val: id }), + type_id = getTypeId(job); + relaunch({ scope: running_scope, id: type_id, type: job.type, name: job.name }); + }; + + queued_scope.relaunch = function(id) { + var job = Find({ list: queued_scope.queued_jobs, key: 'id', val: id }), + type_id = getTypeId(job); + relaunch({ scope: queued_scope, id: type_id, type: job.type, name: job.name }); + }; }); @@ -143,7 +191,8 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea } JobsListController.$inject = ['$scope', '$compile', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'LoadScope', 'RunningJobsList', 'CompletedJobsList', - 'QueuedJobsList', 'ScheduledJobsList', 'GetChoices', 'GetBasePath', 'Wait', 'DeleteJob', 'Find', 'DeleteSchedule', 'ToggleSchedule']; + 'QueuedJobsList', 'ScheduledJobsList', 'GetChoices', 'GetBasePath', 'Wait', 'DeleteJob', 'Find', 'DeleteSchedule', 'ToggleSchedule', 'RelaunchInventory', + 'RelaunchPlaybook', 'RelaunchSCM']; function JobsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, JobForm, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, @@ -363,7 +412,7 @@ function JobsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, J GetChoices({ scope: $scope, - url: GetBasePath('jobs'), + url: GetBasePath('unified_jobs'), field: 'job_type', variable: 'job_type_options', callback: 'choicesReady' @@ -379,7 +428,7 @@ function JobsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, J GetChoices({ scope: $scope, - url: '/static/sample/data/types/data.json', //GetBasePath('jobs') + url: GetBasePath('unified_jobs'), //'/static/sample/data/types/data.json' field: 'type', variable: 'type_choices', callback: 'choicesReady' diff --git a/awx/ui/static/js/helpers/Jobs.js b/awx/ui/static/js/helpers/Jobs.js index 693ef6e496..11567cfae4 100644 --- a/awx/ui/static/js/helpers/Jobs.js +++ b/awx/ui/static/js/helpers/Jobs.js @@ -9,7 +9,8 @@ 'use strict'; -angular.module('JobsHelper', ['Utilities', 'FormGenerator', 'JobSummaryDefinition', 'InventoryHelper', 'GeneratorHelpers']) +angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'JobSummaryDefinition', 'InventoryHelper', 'GeneratorHelpers', + 'JobSubmissionHelper']) .factory('JobStatusToolTip', [ function () { @@ -215,7 +216,7 @@ angular.module('JobsHelper', ['Utilities', 'FormGenerator', 'JobSummaryDefinitio if (list.fields.type) { parent_scope.type_choices.every(function(choice) { if (choice.value === item.type) { - itm.type = choice.label; + itm.type_label = choice.label; return false; } return true; @@ -326,4 +327,48 @@ function(Find, GetBasePath, Rest, Wait, ProcessErrors, Prompt){ }); }; +}]) + +.factory('RelaunchInventory', ['Find', 'Wait', 'Rest', 'InventoryUpdate', 'ProcessErrors', 'GetBasePath', +function(Find, Wait, Rest, InventoryUpdate, ProcessErrors, GetBasePath) { + return function(params) { + var scope = params.scope, + id = params.id, + url = GetBasePath('inventory_sources') + id + '/'; + Wait('start'); + Rest.setUrl(url); + Rest.get() + .success(function (data) { + InventoryUpdate({ + scope: scope, + url: data.related.update, + group_name: data.summary_fields.group.name, + group_source: data.source, + tree_id: null, + group_id: data.group + }); + }) + .error(function (data, status) { + ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve inventory source: ' + + url + ' POST returned status: ' + status }); + }); + }; +}]) + +.factory('RelaunchPlaybook', ['SubmitJob', function(SubmitJob) { + return function(params) { + var scope = params.scope, + id = params.id, + name = params.name; + SubmitJob({ scope: scope, id: id, template: name }); + }; +}]) + +.factory('RelaunchSCM', ['ProjectUpdate', function(ProjectUpdate) { + return function(params) { + var scope = params.scope, + id = params.id; + ProjectUpdate({ scope: scope, id: id }); + }; }]); + diff --git a/awx/ui/static/js/lists/CompletedJobs.js b/awx/ui/static/js/lists/CompletedJobs.js index 2e57bead77..fd61197ebc 100644 --- a/awx/ui/static/js/lists/CompletedJobs.js +++ b/awx/ui/static/js/lists/CompletedJobs.js @@ -48,6 +48,7 @@ angular.module('CompletedJobsDefinition', []) }, type: { label: 'Type', + ngBind: 'completed_job.type_label', link: false, columnClass: "col-md-2 hidden-sm hidden-xs" }, @@ -101,7 +102,7 @@ angular.module('CompletedJobsDefinition', []) submit: { icon: 'icon-rocket', mode: 'all', - ngClick: 'submitJob(completed_job.id, completed_job.summary_fields.job_template.name)', + ngClick: 'relaunch(completed_job.id)', awToolTip: 'Relaunch the job', dataPlacement: 'top' }, diff --git a/awx/ui/static/js/lists/QueuedJobs.js b/awx/ui/static/js/lists/QueuedJobs.js index 514983d376..39d4394263 100644 --- a/awx/ui/static/js/lists/QueuedJobs.js +++ b/awx/ui/static/js/lists/QueuedJobs.js @@ -47,6 +47,7 @@ angular.module('QueuedJobsDefinition', []) }, type: { label: 'Type', + ngBind: 'queued_job.type_label', link: false, columnClass: "col-md-2 hidden-sm hidden-xs" }, @@ -78,7 +79,7 @@ angular.module('QueuedJobsDefinition', []) submit: { icon: 'icon-rocket', mode: 'all', - ngClick: 'submitJob(queued_job.id, queued_job.summary_fields.job_template.name)', + ngClick: 'relaunch(queued_job.id)', awToolTip: 'Launch another instance of the job', dataPlacement: 'top' }, diff --git a/awx/ui/static/js/lists/RunningJobs.js b/awx/ui/static/js/lists/RunningJobs.js index 19879e76b3..bbc8c43071 100644 --- a/awx/ui/static/js/lists/RunningJobs.js +++ b/awx/ui/static/js/lists/RunningJobs.js @@ -47,6 +47,7 @@ angular.module('RunningJobsDefinition', []) }, type: { label: 'Type', + ngBind: 'running_job.type_label', link: false, columnClass: "col-md-2 hidden-sm hidden-xs" }, @@ -81,7 +82,7 @@ angular.module('RunningJobsDefinition', []) submit: { icon: 'icon-rocket', mode: 'all', - ngClick: 'submitJob(running_job.id, running_job.summary_fields.job_template.name)', + ngClick: 'relaunch(running_job.id)', awToolTip: 'Launch another instance of the job', dataPlacement: 'top' },