mirror of
https://github.com/ansible/awx.git
synced 2026-04-08 03:29:21 -02:30
Add a re-run button to Jobs page.
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, JobTemplateList,
|
function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, JobTemplateList,
|
||||||
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
||||||
ClearScope, ProcessErrors, GetBasePath, PromptPasswords, JobTemplateForm, CredentialList,
|
ClearScope, ProcessErrors, GetBasePath, PromptPasswords, JobTemplateForm, CredentialList,
|
||||||
LookUpInit)
|
LookUpInit, SubmitJob)
|
||||||
{
|
{
|
||||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||||
//scope.
|
//scope.
|
||||||
@@ -133,100 +133,15 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function postJob(data) {
|
|
||||||
// Create the job record
|
|
||||||
(scope.credentialWatchRemove) ? scope.credentialWatchRemove() : null;
|
|
||||||
var dt = new Date().toISOString();
|
|
||||||
Rest.setUrl(data.related.jobs);
|
|
||||||
Rest.post({
|
|
||||||
name: data.name + ' ' + dt, // job name required and unique
|
|
||||||
description: data.description,
|
|
||||||
job_template: data.id,
|
|
||||||
inventory: data.inventory,
|
|
||||||
project: data.project,
|
|
||||||
playbook: data.playbook,
|
|
||||||
credential: data.credential,
|
|
||||||
forks: data.forks,
|
|
||||||
limit: data.limit,
|
|
||||||
verbosity: data.verbosity,
|
|
||||||
extra_vars: data.extra_vars
|
|
||||||
})
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
if (data.passwords_needed_to_start.length > 0) {
|
|
||||||
// Passwords needed. Prompt for passwords, then start job.
|
|
||||||
PromptPasswords({
|
|
||||||
scope: scope,
|
|
||||||
passwords: data.passwords_needed_to_start,
|
|
||||||
start_url: data.related.start
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// No passwords needed, start the job!
|
|
||||||
Rest.setUrl(data.related.start);
|
|
||||||
Rest.post()
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
$location.path('/jobs');
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to start job. POST returned status: ' + status });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to create job. POST returned status: ' + status });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
scope.submitJob = function(id) {
|
scope.submitJob = function(id) {
|
||||||
// Get the job details
|
SubmitJob({ scope: scope, id: id });
|
||||||
Rest.setUrl(defaultUrl + id + '/');
|
}
|
||||||
Rest.get()
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
// Create a job record
|
|
||||||
scope.credential = '';
|
|
||||||
if (data.credential == '' || data.credential == null) {
|
|
||||||
// Template does not have credential, prompt for one
|
|
||||||
if (scope.credentialWatchRemove) {
|
|
||||||
scope.credentialWatchRemove();
|
|
||||||
}
|
|
||||||
scope.credentialWatchRemove = scope.$watch('credential', function(newVal, oldVal) {
|
|
||||||
if (newVal !== oldVal) {
|
|
||||||
// After user selects a credential from the modal,
|
|
||||||
// submit the job
|
|
||||||
if (scope.credential != '' && scope.credential !== null && scope.credential !== undefined) {
|
|
||||||
data.credential = scope.credential;
|
|
||||||
postJob(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
LookUpInit({
|
|
||||||
scope: scope,
|
|
||||||
form: JobTemplateForm,
|
|
||||||
current_item: null,
|
|
||||||
list: CredentialList,
|
|
||||||
field: 'credential',
|
|
||||||
hdr: 'Credential Required'
|
|
||||||
});
|
|
||||||
scope.lookUpCredential();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// We have what we need, submit the job
|
|
||||||
postJob(data);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to get job template details. GET returned status: ' + status });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'JobTemplateList',
|
JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'JobTemplateList',
|
||||||
'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
|
'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
|
||||||
'ProcessErrors','GetBasePath', 'PromptPasswords', 'JobTemplateForm', 'CredentialList', 'LookUpInit'
|
'ProcessErrors','GetBasePath', 'PromptPasswords', 'JobTemplateForm', 'CredentialList', 'LookUpInit',
|
||||||
|
'SubmitJob'
|
||||||
];
|
];
|
||||||
|
|
||||||
function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
|
function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
function JobsListCtrl ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, JobList,
|
function JobsListCtrl ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, JobList,
|
||||||
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
||||||
ClearScope, ProcessErrors, GetBasePath, LookUpInit)
|
ClearScope, ProcessErrors, GetBasePath, LookUpInit, SubmitJob)
|
||||||
{
|
{
|
||||||
ClearScope('htmlTemplate');
|
ClearScope('htmlTemplate');
|
||||||
var list = JobList;
|
var list = JobList;
|
||||||
@@ -105,11 +105,14 @@ function JobsListCtrl ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope.submitJob = function(id, template) {
|
||||||
|
SubmitJob({ scope: scope, id: id, template: template });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JobsListCtrl.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'JobList',
|
JobsListCtrl.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'JobList',
|
||||||
'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
|
'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope',
|
||||||
'ProcessErrors','GetBasePath', 'LookUpInit'
|
'ProcessErrors','GetBasePath', 'LookUpInit', 'SubmitJob'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
* JobTemplateHelper
|
* JobTemplateHelper
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
angular.module('JobTemplateHelper', [ 'RestServices', 'Utilities', 'CredentialFormDefinition' ])
|
angular.module('JobTemplateHelper', [ 'RestServices', 'Utilities', 'CredentialFormDefinition', 'CredentialsListDefinition',
|
||||||
.factory('PromptPasswords',['CredentialForm', '$compile', 'Rest', '$location', function(JobTemplateForm, $compile, Rest, $location) {
|
'LookUpHelper', 'JobTemplateFormDefinition' ])
|
||||||
|
|
||||||
|
.factory('PromptPasswords',['CredentialForm', '$compile', 'Rest', '$location',
|
||||||
|
function(JobTemplateForm, $compile, Rest, $location) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var scope = params.scope;
|
var scope = params.scope;
|
||||||
@@ -24,7 +27,13 @@ angular.module('JobTemplateHelper', [ 'RestServices', 'Utilities', 'CredentialFo
|
|||||||
Rest.setUrl(start_url);
|
Rest.setUrl(start_url);
|
||||||
Rest.post(pswd)
|
Rest.post(pswd)
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
$location.path('/jobs');
|
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||||
|
if (base == 'jobs') {
|
||||||
|
scope.refreshJob();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$location.path('/jobs');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.error( function(data, status, headers, config) {
|
.error( function(data, status, headers, config) {
|
||||||
ProcessErrors(scope, data, status, null,
|
ProcessErrors(scope, data, status, null,
|
||||||
@@ -32,6 +41,7 @@ angular.module('JobTemplateHelper', [ 'RestServices', 'Utilities', 'CredentialFo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
html += html += "<form class=\"form-horizontal\" name=\"password_form\" novalidate>\n";
|
html += html += "<form class=\"form-horizontal\" name=\"password_form\" novalidate>\n";
|
||||||
for (var i=0; i < passwords.length; i++) {
|
for (var i=0; i < passwords.length; i++) {
|
||||||
// Add the password field
|
// Add the password field
|
||||||
@@ -86,6 +96,114 @@ angular.module('JobTemplateHelper', [ 'RestServices', 'Utilities', 'CredentialFo
|
|||||||
$compile(element.contents())(scope);
|
$compile(element.contents())(scope);
|
||||||
$('#password-modal').modal();
|
$('#password-modal').modal();
|
||||||
}
|
}
|
||||||
|
}])
|
||||||
|
|
||||||
|
.factory('SubmitJob',['PromptPasswords', 'CredentialForm', '$compile', 'Rest', '$location', 'GetBasePath', 'CredentialList',
|
||||||
|
'LookUpInit', 'JobTemplateForm', 'ProcessErrors',
|
||||||
|
function(PromptPasswords, JobTemplateForm, $compile, Rest, $location, GetBasePath, CredentialList, LookUpInit, JobTemplateForm,
|
||||||
|
ProcessErrors) {
|
||||||
|
return function(params) {
|
||||||
|
var scope = params.scope;
|
||||||
|
var id = params.id;
|
||||||
|
var template_name = (params.template) ? params.template : null;
|
||||||
|
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||||
|
var url = GetBasePath(base) + id + '/';
|
||||||
|
|
||||||
|
function postJob(data) {
|
||||||
|
// Create the job record
|
||||||
|
(scope.credentialWatchRemove) ? scope.credentialWatchRemove() : null;
|
||||||
|
var dt = new Date().toISOString();
|
||||||
|
var url = (data.related.jobs) ? data.related.jobs : data.related.job_template + 'jobs/';
|
||||||
|
var name = (template_name) ? template_name : data.name;
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post({
|
||||||
|
name: name + ' ' + dt, // job name required and unique
|
||||||
|
description: data.description,
|
||||||
|
job_template: data.id,
|
||||||
|
inventory: data.inventory,
|
||||||
|
project: data.project,
|
||||||
|
playbook: data.playbook,
|
||||||
|
credential: data.credential,
|
||||||
|
forks: data.forks,
|
||||||
|
limit: data.limit,
|
||||||
|
verbosity: data.verbosity,
|
||||||
|
extra_vars: data.extra_vars
|
||||||
|
})
|
||||||
|
.success( function(data, status, headers, config) {
|
||||||
|
if (data.passwords_needed_to_start.length > 0) {
|
||||||
|
// Passwords needed. Prompt for passwords, then start job.
|
||||||
|
PromptPasswords({
|
||||||
|
scope: scope,
|
||||||
|
passwords: data.passwords_needed_to_start,
|
||||||
|
start_url: data.related.start
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// No passwords needed, start the job!
|
||||||
|
Rest.setUrl(data.related.start);
|
||||||
|
Rest.post()
|
||||||
|
.success( function(data, status, headers, config) {
|
||||||
|
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||||
|
if (base == 'jobs') {
|
||||||
|
scope.refreshJob();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$location.path('/jobs');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.error( function(data, status, headers, config) {
|
||||||
|
ProcessErrors(scope, data, status, null,
|
||||||
|
{ hdr: 'Error!', msg: 'Failed to start job. POST returned status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.error( function(data, status, headers, config) {
|
||||||
|
ProcessErrors(scope, data, status, null,
|
||||||
|
{ hdr: 'Error!', msg: 'Failed to create job. POST returned status: ' + status });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the job or job_template record
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.get()
|
||||||
|
.success( function(data, status, headers, config) {
|
||||||
|
// Create a job record
|
||||||
|
scope.credential = '';
|
||||||
|
if (data.credential == '' || data.credential == null) {
|
||||||
|
// Template does not have credential, prompt for one
|
||||||
|
if (scope.credentialWatchRemove) {
|
||||||
|
scope.credentialWatchRemove();
|
||||||
|
}
|
||||||
|
scope.credentialWatchRemove = scope.$watch('credential', function(newVal, oldVal) {
|
||||||
|
if (newVal !== oldVal) {
|
||||||
|
// After user selects a credential from the modal,
|
||||||
|
// submit the job
|
||||||
|
if (scope.credential != '' && scope.credential !== null && scope.credential !== undefined) {
|
||||||
|
data.credential = scope.credential;
|
||||||
|
postJob(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LookUpInit({
|
||||||
|
scope: scope,
|
||||||
|
form: JobTemplateForm,
|
||||||
|
current_item: null,
|
||||||
|
list: CredentialList,
|
||||||
|
field: 'credential',
|
||||||
|
hdr: 'Credential Required'
|
||||||
|
});
|
||||||
|
scope.lookUpCredential();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// We have what we need, submit the job
|
||||||
|
postJob(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.error( function(data, status, headers, config) {
|
||||||
|
ProcessErrors(scope, data, status, null,
|
||||||
|
{ hdr: 'Error!', msg: 'Failed to get job template details. GET returned status: ' + status });
|
||||||
|
});
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
@@ -109,6 +227,5 @@ angular.module('JobTemplateHelper', [ 'RestServices', 'Utilities', 'CredentialFo
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'PaginateHelper', 'ListGenerator', 'ApiLoader' ])
|
angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'PaginateHelper', 'ListGenerator', 'ApiLoader' ])
|
||||||
|
|
||||||
.factory('LookUpInit', ['Alert', 'Rest', 'GenerateList', 'SearchInit', 'PaginateInit', 'GetBasePath',
|
.factory('LookUpInit', ['Alert', 'Rest', 'GenerateList', 'SearchInit', 'PaginateInit', 'GetBasePath',
|
||||||
function(Alert, Rest, GenerateList, SearchInit, PaginateInit, GetBasePath) {
|
function(Alert, Rest, GenerateList, SearchInit, PaginateInit, GetBasePath) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|||||||
@@ -60,13 +60,6 @@ angular.module('JobsListDefinition', [])
|
|||||||
},
|
},
|
||||||
|
|
||||||
fieldActions: {
|
fieldActions: {
|
||||||
edit: {
|
|
||||||
icon: 'icon-edit',
|
|
||||||
label: 'Edit',
|
|
||||||
ngClick: "editJob(\{\{ job.id \}\}, '\{\{ job.name \}\}')",
|
|
||||||
class: 'btn-success btn-small',
|
|
||||||
awToolTip: 'Edit job details',
|
|
||||||
},
|
|
||||||
summary: {
|
summary: {
|
||||||
label: 'Hosts',
|
label: 'Hosts',
|
||||||
icon: 'icon-th-large',
|
icon: 'icon-th-large',
|
||||||
@@ -84,14 +77,27 @@ angular.module('JobsListDefinition', [])
|
|||||||
awToolTip: 'View events',
|
awToolTip: 'View events',
|
||||||
ngDisabled: "job.status == 'new'"
|
ngDisabled: "job.status == 'new'"
|
||||||
},
|
},
|
||||||
|
edit: {
|
||||||
|
icon: 'icon-edit',
|
||||||
|
label: 'Edit',
|
||||||
|
ngClick: "editJob(\{\{ job.id \}\}, '\{\{ job.name \}\}')",
|
||||||
|
class: 'btn-success btn-small',
|
||||||
|
awToolTip: 'Edit job details',
|
||||||
|
},
|
||||||
|
rerun: {
|
||||||
|
icon: 'icon-retweet',
|
||||||
|
mode: 'all',
|
||||||
|
ngClick: "submitJob(\{\{ job.id \}\}, '\{\{ job.summary_fields.job_template.name \}\}' )",
|
||||||
|
class: 'btn-success btn-small',
|
||||||
|
awToolTip: 'Re-run this job',
|
||||||
|
},
|
||||||
cancel: {
|
cancel: {
|
||||||
icon: 'icon-minus-sign',
|
icon: 'icon-minus-sign',
|
||||||
label: 'Cancel',
|
mode: 'all',
|
||||||
mode: 'all',
|
|
||||||
ngClick: 'deleteJob(\{\{ job.id \}\})',
|
ngClick: 'deleteJob(\{\{ job.id \}\})',
|
||||||
class: 'btn-danger btn-small',
|
class: 'btn-danger btn-small',
|
||||||
awToolTip: 'Cancel job',
|
awToolTip: 'Cancel job',
|
||||||
ngDisabled: "job.status != 'new' && job.status != 'pending' && job.status != 'running'"
|
ngDisabled: "job.status != 'new' && job.status != 'pending' && job.status != 'running'"
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user