Fixed jobs list on Job Templates page. All the buttons and links now work.

This commit is contained in:
Chris Houseknecht
2014-04-01 17:44:35 -04:00
committed by Chris Houseknecht
parent 658581cce0
commit 5ea4a68820
15 changed files with 256 additions and 180 deletions

View File

@@ -143,7 +143,7 @@ angular.module('ansible', [
controller: 'JobTemplatesAdd'
}).
when('/job_templates/:id', {
when('/job_templates/:template_id', {
templateUrl: urlPrefix + 'partials/job_templates.html',
controller: 'JobTemplatesEdit'
}).

View File

@@ -38,8 +38,8 @@ function JobEventsList($filter, $scope, $rootScope, $location, $log, $routeParam
$scope.removeSetHostLinks = $scope.$on('SetHostLinks', function (e, inventory_id) {
for (var i = 0; i < $scope.jobevents.length; i++) {
if ($scope.jobevents[i].summary_fields.host) {
$scope.jobevents[i].hostLink = "/#/inventories/" + inventory_id + "/hosts/?name=" +
encodeURI($scope.jobevents[i].summary_fields.host.name);
$scope.jobevents[i].hostLink = "/#/inventories/" + inventory_id;
//encodeURI($scope.jobevents[i].summary_fields.host.name);
}
}
});

View File

@@ -337,7 +337,8 @@ JobTemplatesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$lo
function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, GenerateForm, Rest,
Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList,
CredentialList, ProjectList, LookUpInit, GetBasePath, md5Setup, ParseTypeChange, JobStatusToolTip, FormatDate,
Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON, SchedulesControllerInit) {
Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON, SchedulesControllerInit, JobsControllerInit, JobsListUpdate,
GetChoices) {
ClearScope();
@@ -347,13 +348,15 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
loadingFinishedCount = 0,
base = $location.path().replace(/^\//, '').split('/')[0],
master = {},
id = $routeParams.id,
id = $routeParams.template_id,
relatedSets = {},
checkSCMStatus, getPlaybooks, callback;
checkSCMStatus, getPlaybooks, callback,
choicesCount = 0;
generator.inject(form, { mode: 'edit', related: true, scope: $scope });
$scope.parseType = 'yaml';
$scope.showJobType = false;
// Our job type options
$scope.job_type_options = [
@@ -475,22 +478,20 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
});
// Set the status/badge for each related job
if ($scope.removeRelatedJobs) {
$scope.removeRelatedJobs();
if ($scope.removeRelatedCompletedJobs) {
$scope.removeRelatedCompletedJobs();
}
$scope.removeRelatedJobs = $scope.$on('relatedjobs', function () {
var i, cDate;
if ($scope.jobs && $scope.jobs.length) {
for (i = 0; i < $scope.jobs.length; i++) {
// Convert created date to local time zone
cDate = new Date($scope.jobs[i].created);
$scope.jobs[i].created = FormatDate(cDate);
// Set tooltip and link
$scope.jobs[i].statusBadgeToolTip = JobStatusToolTip($scope.jobs[i].status) +
" Click to view status details.";
$scope.jobs[i].statusLinkTo = '/#/jobs/' + $scope.jobs[i].id;
}
}
$scope.removeRelatedCompletedJobs = $scope.$on('relatedcompleted_jobs', function () {
JobsControllerInit({
scope: $scope,
parent_scope: $scope,
iterator: form.related.completed_jobs.iterator
});
JobsListUpdate({
scope: $scope,
parent_scope: $scope,
list: form.related.completed_jobs
});
});
if ($scope.cloudCredentialReadyRemove) {
@@ -553,94 +554,126 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
});
Wait('start');
// Retrieve detail record and prepopulate the form
Rest.setUrl(defaultUrl + ':id/');
Rest.get({ params: { id: id } })
.success(function (data) {
var fld, i;
LoadBreadCrumbs({ path: '/job_templates/' + id, title: data.name });
for (fld in form.fields) {
if (fld !== 'variables' && data[fld] !== null && data[fld] !== undefined) {
if (form.fields[fld].type === 'select') {
if ($scope[fld + '_options'] && $scope[fld + '_options'].length > 0) {
for (i = 0; i < $scope[fld + '_options'].length; i++) {
if (data[fld] === $scope[fld + '_options'][i].value) {
$scope[fld] = $scope[fld + '_options'][i];
if ($scope.removeLoadJobs) {
$scope.rmoveLoadJobs();
}
$scope.removeLoadJobs = $scope.$on('LoadJobs', function() {
// Retrieve detail record and prepopulate the form
Rest.setUrl(defaultUrl + ':id/');
Rest.get({ params: { id: id } })
.success(function (data) {
var fld, i;
LoadBreadCrumbs({ path: '/job_templates/' + id, title: data.name });
for (fld in form.fields) {
if (fld !== 'variables' && data[fld] !== null && data[fld] !== undefined) {
if (form.fields[fld].type === 'select') {
if ($scope[fld + '_options'] && $scope[fld + '_options'].length > 0) {
for (i = 0; i < $scope[fld + '_options'].length; i++) {
if (data[fld] === $scope[fld + '_options'][i].value) {
$scope[fld] = $scope[fld + '_options'][i];
}
}
} else {
$scope[fld] = data[fld];
}
} else {
$scope[fld] = data[fld];
}
} else {
$scope[fld] = data[fld];
master[fld] = $scope[fld];
}
if (fld === 'variables') {
// Parse extra_vars, converting to YAML.
$scope.variables = ParseVariableString(data.extra_vars);
master.variables = $scope.variables;
}
if (form.fields[fld].type === 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) {
$scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
$scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField];
}
master[fld] = $scope[fld];
}
if (fld === 'variables') {
// Parse extra_vars, converting to YAML.
$scope.variables = ParseVariableString(data.extra_vars);
master.variables = $scope.variables;
}
if (form.fields[fld].type === 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) {
$scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
$scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField];
}
}
$scope.url = data.url;
relatedSets = form.relatedSets(data.related);
$scope.callback_url = data.related.callback;
master.callback_url = $scope.callback_url;
$scope.url = data.url;
relatedSets = form.relatedSets(data.related);
$scope.callback_url = data.related.callback;
master.callback_url = $scope.callback_url;
LookUpInit({
scope: $scope,
form: form,
current_item: data.inventory,
list: InventoryList,
field: 'inventory'
});
LookUpInit({
scope: $scope,
form: form,
current_item: data.inventory,
list: InventoryList,
field: 'inventory'
});
LookUpInit({
url: GetBasePath('credentials') + '?kind=ssh',
scope: $scope,
form: form,
current_item: data.credential,
list: CredentialList,
field: 'credential',
hdr: 'Select Machine Credential'
});
LookUpInit({
url: GetBasePath('credentials') + '?kind=ssh',
scope: $scope,
form: form,
current_item: data.credential,
list: CredentialList,
field: 'credential',
hdr: 'Select Machine Credential'
});
LookUpInit({
scope: $scope,
form: form,
current_item: data.project,
list: ProjectList,
field: 'project'
});
LookUpInit({
scope: $scope,
form: form,
current_item: data.project,
list: ProjectList,
field: 'project'
});
RelatedSearchInit({
scope: $scope,
form: form,
relatedSets: relatedSets
});
RelatedPaginateInit({
scope: $scope,
relatedSets: relatedSets
});
RelatedSearchInit({
scope: $scope,
form: form,
relatedSets: relatedSets
});
RelatedPaginateInit({
scope: $scope,
relatedSets: relatedSets
});
$scope.$emit('jobTemplateLoaded', data.related.cloud_credential);
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, {
hdr: 'Error!',
msg: 'Failed to retrieve job template: ' + $routeParams.id + '. GET status: ' + status
$scope.$emit('jobTemplateLoaded', data.related.cloud_credential);
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, {
hdr: 'Error!',
msg: 'Failed to retrieve job template: ' + $routeParams.template_id + '. GET status: ' + status
});
});
});
});
if ($scope.removeChoicesReady) {
$scope.removeChoicesReady();
}
$scope.removeChoicesReady = $scope.$on('choicesReady', function() {
choicesCount++;
if (choicesCount === 2) {
$scope.$emit('LoadJobs');
}
});
GetChoices({
scope: $scope,
url: GetBasePath('unified_jobs'),
field: 'status',
variable: 'status_choices',
callback: 'choicesReady'
});
GetChoices({
scope: $scope,
url: GetBasePath('unified_jobs'),
field: 'type',
variable: 'type_choices',
callback: 'choicesReady'
});
function saveCompleted() {
setTimeout(function() { $scope.$apply(function() { $location.path('/job_templates'); }); }, 500);
@@ -713,7 +746,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
// Related set: Add button
$scope.add = function (set) {
$rootScope.flashMessage = null;
$location.path('/' + base + '/' + $routeParams.id + '/' + set);
$location.path('/' + base + '/' + $routeParams.template_id + '/' + set);
};
// Related set: Edit button
@@ -757,5 +790,5 @@ JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$l
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit',
'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit',
'GetBasePath', 'md5Setup', 'ParseTypeChange', 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty', 'Prompt',
'ParseVariableString', 'ToJSON', 'SchedulesControllerInit'
'ParseVariableString', 'ToJSON', 'SchedulesControllerInit', 'JobsControllerInit', 'JobsListUpdate', 'GetChoices'
];

View File

@@ -21,6 +21,8 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea
LoadBreadCrumbs();
$scope.showJobType = true;
// Add breadcrumbs
e = angular.element(document.getElementById('breadcrumbs'));
e.html(Breadcrumbs({ list: { editTitle: 'Jobs' } , mode: 'edit' }));
@@ -62,7 +64,7 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea
scope: scheduled_scope,
list: ScheduledJobsList,
id: 'scheduled-jobs',
url: GetBasePath('schedules')
url: GetBasePath('schedules') + '?next_run__isnull=false'
});
$scope.refreshJobs = function() {

View File

@@ -23,7 +23,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
collapse: true,
collapseTitle: "Properties",
collapseMode: 'edit',
collapseOpenFirst: true, //Always open first panel
collapseOpenFirst: false, //Always open first panel
actions: {
stream: {
@@ -291,7 +291,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
schedules: {
include: "SchedulesList"
},
completed_jobs: {
"completed_jobs": {
include: "CompletedJobsList"
}
},
@@ -300,7 +300,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
return {
completed_jobs: {
iterator: 'completed_job',
url: urls.jobs
url: urls.jobs + '?or__status=successful&or__status=failed&or__status=error&or__status=canceled'
},
schedules: {
iterator: 'schedule',

View File

@@ -154,16 +154,21 @@ function(Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialList) {
}])
// Submit request to run a playbook
.factory('PlaybookRun', ['LaunchJob', 'PromptForPasswords', 'Rest', '$location', 'GetBasePath', 'ProcessErrors', 'Wait', 'Empty', 'PromptForCredential',
function (LaunchJob, PromptForPasswords, Rest, $location, GetBasePath, ProcessErrors, Wait, Empty, PromptForCredential) {
.factory('PlaybookRun', ['$location','$routeParams', 'LaunchJob', 'PromptForPasswords', 'Rest', 'GetBasePath', 'ProcessErrors', 'Wait', 'Empty', 'PromptForCredential',
function ($location, $routeParams, LaunchJob, PromptForPasswords, Rest, GetBasePath, ProcessErrors, Wait, Empty, PromptForCredential) {
return function (params) {
var scope = params.scope,
id = params.id,
base = $location.path().replace(/^\//, '').split('/')[0],
url = GetBasePath(base) + id + '/',
job_template,
new_job_id,
launch_url;
url, job_template, new_job_id, launch_url;
if (!Empty($routeParams.template_id)) {
// launching a job from job_template detail page
url = GetBasePath('jobs') + id + '/';
}
else {
url = GetBasePath(base) + id + '/';
}
if (scope.removePostTheJob) {
scope.removePostTheJob();

View File

@@ -22,7 +22,9 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
function($location, Find, DeleteJob, RelaunchJob, LogViewer) {
return function(params) {
var scope = params.scope,
parent_scope = params.parent_scope;
parent_scope = params.parent_scope,
iterator = (params.iterator) ? params.iterator : scope.iterator,
base = $location.path().replace(/^\//, '').split('/')[0];
scope.deleteJob = function(id) {
DeleteJob({ scope: scope, id: id });
@@ -59,7 +61,13 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
};
scope.refreshJobs = function() {
parent_scope.refreshJobs();
if (base === 'jobs') {
parent_scope.refreshJobs();
}
else {
scope.search(iterator);
}
};
scope.viewJobLog = function(id, url) {
@@ -80,8 +88,7 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
job = Find({ list: list, key: 'id', val: id });
LogViewer({
scope: scope,
url: job.url,
status_icon: 'icon-job-' + job.status
url: job.url
});
}
};
@@ -262,13 +269,77 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
}
])
.factory('JobsListUpdate', ['Rest', function(Rest) {
return function(params) {
var scope = params.scope,
parent_scope = params.scope,
list = params.list;
scope[list.name].forEach(function(item, item_idx) {
var fld, field,
itm = scope[list.name][item_idx];
// Set the item type label
if (list.fields.type) {
parent_scope.type_choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
return false;
}
return true;
});
}
// Set the job status label
parent_scope.status_choices.every(function(status) {
if (status.value === item.status) {
itm.status_label = status.label;
return false;
}
return true;
});
//Set the name link
if (item.type === "inventory_update") {
Rest.setUrl(item.related.inventory_source);
Rest.get()
.success(function(data) {
itm.nameHref = "/inventories/" + data.inventory;
});
}
else if (item.type === "project_update") {
itm.nameHref = "/projects/" + item.project;
}
else if (item.type === "job") {
itm.nameHref = "";
}
if (list.name === 'completed_jobs' || list.name === 'running_jobs') {
itm.status_tip = itm.status_label + '. Click for details.';
}
else if (list.name === 'queued_jobs') {
itm.status_tip = 'Pending';
}
// Copy summary_field values
for (field in list.fields) {
fld = list.fields[field];
if (fld.sourceModel) {
if (itm.summary_fields[fld.sourceModel]) {
itm[field] = itm.summary_fields[fld.sourceModel][fld.sourceField];
}
}
}
});
};
}])
/**
*
* Called from JobsList controller to load each section or list on the page
*
*/
.factory('LoadJobsScope', ['SearchInit', 'PaginateInit', 'GenerateList', 'JobsControllerInit', 'Rest',
function(SearchInit, PaginateInit, GenerateList, JobsControllerInit, Rest) {
.factory('LoadJobsScope', ['SearchInit', 'PaginateInit', 'GenerateList', 'JobsControllerInit', 'JobsListUpdate',
function(SearchInit, PaginateInit, GenerateList, JobsControllerInit, JobsListUpdate) {
return function(params) {
var parent_scope = params.parent_scope,
scope = params.scope,
@@ -298,70 +369,15 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
url: url,
pageSize: 5
});
scope.iterator = list.iterator;
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.$on('PostRefresh', function(){
JobsControllerInit({ scope: scope, parent_scope: parent_scope });
scope[list.name].forEach(function(item, item_idx) {
var fld, field,
itm = scope[list.name][item_idx];
// Set the item type label
if (list.fields.type) {
parent_scope.type_choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
return false;
}
return true;
});
}
// Set the job status label
parent_scope.status_choices.every(function(status) {
if (status.value === item.status) {
itm.status_label = status.label;
return false;
}
return true;
});
//Set the name link
if (item.type === "inventory_update") {
Rest.setUrl(item.related.inventory_source);
Rest.get()
.success(function(data) {
itm.nameHref = "/inventories/" + data.inventory;
});
}
else if (item.type === "project_update") {
itm.nameHref = "/projects/" + item.project;
}
else if (item.type === "job") {
itm.nameHref = "";
}
if (list.name === 'completed_jobs' || list.name === 'running_jobs') {
itm.status_tip = itm.status_label + '. Click for details.';
}
else if (list.name === 'queued_jobs') {
itm.status_tip = 'Pending';
}
// Copy summary_field values
for (field in list.fields) {
fld = list.fields[field];
if (fld.sourceModel) {
if (itm.summary_fields[fld.sourceModel]) {
itm[field] = itm.summary_fields[fld.sourceModel][fld.sourceField];
}
}
}
});
JobsListUpdate({ scope: scope, parent_scope: parent_scope, list: list });
parent_scope.$emit('listLoaded');
});
scope.search(list.iterator);
@@ -415,7 +431,7 @@ function(Find, GetBasePath, Rest, Wait, ProcessErrors, Prompt){
Rest.destroy()
.success(function () {
$('#prompt-modal').modal('hide');
scope.search(scope.iterator);
scope.refreshJobs();
})
.error(function (data, status) {
$('#prompt-modal').modal('hide');

View File

@@ -240,6 +240,9 @@ angular.module('LogViewerHelper', ['ModalDialog', 'Utilities', 'FormGenerator',
html += "<i class=\"fa icon-job-" + getIcon(scope[fld]) + "\"></i> " + scope[fld];
//html += "<i class=\"fa " + status_icon + scope[fld] + "\"></i> " + scope[fld];
}
else if (fld === 'status') {
html += "<i class=\"fa icon-job-" + scope[fld] + "\"></i> " + scope[fld];
}
else {
html += scope[fld];
}

View File

@@ -29,7 +29,7 @@ angular.module('ProjectsHelper', ['RestServices', 'Utilities', 'ProjectStatusDef
break;
case 'updating':
case 'running':
result = 'running pulsate';
result = 'running';
break;
case 'successful':
result = 'success';

View File

@@ -419,7 +419,7 @@ angular.module('SchedulesHelper', [ 'Utilities', 'RestServices', 'SchedulesHelpe
});
};
scope.refreshJobs = function() {
scope.refreshSchedule = function() {
if (base === 'jobs') {
parent_scope.refreshJobs();
}

View File

@@ -34,11 +34,25 @@ angular.module('RelatedSearchHelper', ['RestServices', 'Utilities', 'RefreshRela
iterator = form.related[set].iterator;
for (fld in form.related[set].fields) {
if (form.related[set].fields[fld].key) {
scope[iterator + 'SearchField'] = fld;
scope[iterator + 'SearchFieldLabel'] = form.related[set].fields[fld].label;
if (form.related[set].fields[fld].searchable === undefined || form.related[set].fields[fld].searchable === true) {
scope[iterator + 'SearchField'] = fld;
scope[iterator + 'SearchFieldLabel'] = form.related[set].fields[fld].label;
}
break;
}
}
if (Empty(scope[iterator + 'SearchField'])) {
// A field marked as key may not be 'searchable'. Find the first searchable field.
for (fld in form.related[set].fields) {
if (form.related[set].fields[fld].searchable === undefined || form.related[set].fields[fld].searchable === true) {
scope[iterator + 'SearchField'] = fld;
scope[iterator + 'SearchFieldLabel'] = form.related[set].fields[fld].label;
break;
}
}
}
scope[iterator + 'SortOrder'] = null;
scope[iterator + 'SearchType'] = 'icontains';
scope[iterator + 'SearchTypeLabel'] = 'Contains';
@@ -121,7 +135,7 @@ angular.module('RelatedSearchHelper', ['RestServices', 'Utilities', 'RefreshRela
scope.search = function (iterator) {
//scope[iterator + 'SearchSpin'] = true;
Wait('start');
scope[iterator + 'Loading'] = true;
scope[iterator + 'Loading'] = false;
scope[iterator + 'HoldInput'] = true;
if (scope[iterator + 'SearchValue']) {

View File

@@ -64,6 +64,7 @@ angular.module('CompletedJobsDefinition', [])
ngBind: 'completed_job.type_label',
link: false,
columnClass: "col-md-2 hidden-sm hidden-xs",
columnShow: "showJobType",
searchable: false
},
name: {

View File

@@ -28,7 +28,8 @@ angular.module('ScheduledJobsDefinition', [])
icon: 'icon-job-{{ schedule.status }}',
iconOnly: true,
ngClick: "toggleSchedule($event, schedule.id)",
searchable: false
searchable: false,
nosort: true
},
next_run: {
label: 'Next Run',
@@ -61,7 +62,7 @@ angular.module('ScheduledJobsDefinition', [])
refresh: {
mode: 'all',
awToolTip: "Refresh the page",
ngClick: "refreshJobs()"
ngClick: "refreshSchedule()"
}
},

View File

@@ -15,7 +15,7 @@ angular.module('SchedulesListDefinition', [])
iterator: 'schedule',
selectTitle: '',
editTitle: 'Schedules',
well: true,
well: false,
index: true,
hover: true,
@@ -55,7 +55,7 @@ angular.module('SchedulesListDefinition', [])
refresh: {
mode: 'all',
awToolTip: "Refresh the page",
ngClick: "refreshJobs()"
ngClick: "refreshSchedule()"
},
stream: {
ngClick: "showActivity()",

View File

@@ -1,4 +1,5 @@
<div class="tab-pane" id="job_templates">
<div ng-cloak id="htmlTemplate"></div>
<div ng-include="'/static/partials/schedule_dialog.html'"></div>
<div ng-include="'/static/partials/logviewer.html'"></div>
</div>