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();
}
$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;
}
if ($scope.removeRelatedCompletedJobs) {
$scope.removeRelatedCompletedJobs();
}
$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,6 +554,11 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
});
Wait('start');
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 } })
@@ -638,9 +644,36 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
.error(function (data, status) {
ProcessErrors($scope, data, status, form, {
hdr: 'Error!',
msg: 'Failed to retrieve job template: ' + $routeParams.id + '. GET status: ' + status
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() {
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,51 +269,12 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
}
])
/**
*
* 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('JobsListUpdate', ['Rest', function(Rest) {
return function(params) {
var parent_scope = params.parent_scope,
scope = params.scope,
list = params.list,
id = params.id,
url = params.url;
GenerateList.inject(list, {
mode: 'edit',
id: id,
breadCrumbs: false,
scope: scope,
searchSize: 'col-lg-4 col-md-6 col-sm-12 col-xs-12',
showSearch: true
});
SearchInit({
scope: scope,
set: list.name,
list: list,
url: url
});
PaginateInit({
scope: scope,
list: list,
url: url,
pageSize: 5
});
scope.iterator = list.iterator;
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.$on('PostRefresh', function(){
JobsControllerInit({ scope: scope, parent_scope: parent_scope });
var scope = params.scope,
parent_scope = params.scope,
list = params.list;
scope[list.name].forEach(function(item, item_idx) {
var fld, field,
@@ -362,6 +330,54 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job
}
}
});
};
}])
/**
*
* Called from JobsList controller to load each section or list on the page
*
*/
.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,
list = params.list,
id = params.id,
url = params.url;
GenerateList.inject(list, {
mode: 'edit',
id: id,
breadCrumbs: false,
scope: scope,
searchSize: 'col-lg-4 col-md-6 col-sm-12 col-xs-12',
showSearch: true
});
SearchInit({
scope: scope,
set: list.name,
list: list,
url: url
});
PaginateInit({
scope: scope,
list: list,
url: url,
pageSize: 5
});
scope.iterator = list.iterator;
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.$on('PostRefresh', function(){
JobsControllerInit({ scope: scope, parent_scope: parent_scope });
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) {
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>