Fixed job_host_summaries and job_events page links and browser refersh issue.

This commit is contained in:
Chris Houseknecht 2014-04-05 02:52:21 -04:00
parent 221db9b296
commit 9af0d424b6
12 changed files with 101 additions and 91 deletions

View File

@ -112,18 +112,13 @@ angular.module('ansible', [
templateUrl: urlPrefix + 'partials/jobs.html',
controller: 'JobsListController'
}).
/* when('/jobs/:id', {
templateUrl: urlPrefix + 'partials/jobs.html',
controller: 'JobsEdit'
}). */
when('/jobs/:id/job_events', {
when('/job_events/:id', {
templateUrl: urlPrefix + 'partials/job_events.html',
controller: 'JobEventsList'
}).
when('/jobs/:id/job_host_summaries', {
when('/job_host_summaries/:id', {
templateUrl: urlPrefix + 'partials/job_host_summaries.html',
controller: 'JobHostSummaryList'
}).
@ -445,6 +440,7 @@ angular.module('ansible', [
base = 'home';
} else {
base.replace(/\_/g, ' ');
base = (base === 'job_events' || base === 'job_host_summaries') ? 'jobs' : base;
}
$('.nav-tabs a[href="#' + base + '"]').tab('show');
});
@ -466,6 +462,9 @@ angular.module('ansible', [
$location.path('/home');
} else {
base.replace(/\_/g, ' ');
if (base === 'jobevents' || base === 'jobhostsummaries') {
base = 'jobs';
}
}
$('.nav-tabs a[href="#' + base + '"]').tab('show');

View File

@ -373,8 +373,8 @@ function HomeGroups($scope, $filter, $compile, $location, $routeParams, LogViewe
". Click for details\" aw-tip-placement=\"top\"><i class=\"fa icon-job-" +
row.status + "\"></i></a></td>\n";
//html += "<td>" + ($filter('date')(row.finished,'MM/dd HH:mm:ss')).replace(/ /,'<br />') + "</td>";
html += "<td><a href=\"/#/jobs/" + row.id + "/job_events\">Events</a><br />" +
"<a href=\"/#/jobs/" + row.id + "/job_host_summaries\">Hosts</a></td>";
html += "<td><a href=\"/#/job_events/" + row.id + "\">Events</a><br />" +
"<a href=\"/#/job_host_summaries/" + row.id + "\">Hosts</a></td>";
html += "<td><a href=\"\" ng-click=\"viewJob('" + url + row.id + "/')\" >" + ellipsis(row.name) + "</a></td>";
html += "</tr>\n";
});

View File

@ -20,9 +20,7 @@ function JobEventsList($filter, $scope, $rootScope, $location, $log, $routeParam
defaultUrl = GetBasePath('jobs') + $routeParams.id + '/job_events/', //?parent__isnull=1';
generator = GenerateList,
page;
generator.inject(list, { mode: 'edit', scope: $scope });
list.base = $location.path();
$scope.job_id = $routeParams.id;
$rootScope.flashMessage = null;
@ -125,6 +123,7 @@ function JobEventsList($filter, $scope, $rootScope, $location, $log, $routeParam
}
$scope.removePostRefresh = $scope.$on('PostRefresh', function () {
// Initialize the parent levels
generator.inject(list, { mode: 'edit', scope: $scope });
var set = $scope[list.name], i;
for (i = 0; i < set.length; i++) {
set[i].event_display = set[i].event_display.replace(/^\u00a0*/g, '');
@ -179,9 +178,14 @@ function JobEventsList($filter, $scope, $rootScope, $location, $log, $routeParam
$scope.job_status = data.status;
$scope.job_name = data.summary_fields.job_template.name;
LoadBreadCrumbs({
path: '/jobs/' + $scope.job_id,
title: $scope.job_id + ' - ' + data.summary_fields.job_template.name
path: '/job_events/' + $scope.job_id,
title: $scope.job_id + ' - ' + data.summary_fields.job_template.name,
altPath: '/jobs'
});
$rootScope.breadcrumbs = [{
path: '/jobs',
title: $scope.job_id + ' - ' + data.summary_fields.job_template.name,
}];
$scope.$emit('SetHostLinks', data.inventory);
})
.error(function (data, status) {
@ -199,6 +203,7 @@ function JobEventsList($filter, $scope, $rootScope, $location, $log, $routeParam
});
page = ($routeParams.page) ? parseInt($routeParams.page,10) - 1 : null;
PaginateInit({
scope: $scope,
list: list,

View File

@ -17,28 +17,27 @@ function JobHostSummaryList($scope, $rootScope, $location, $log, $routeParams, R
ClearScope();
var list = JobHostList,
base = $location.path().replace(/^\//, '').split('/')[0],
defaultUrl = GetBasePath(base) + $routeParams.id + '/job_host_summaries/',
view = GenerateList,
scope = view.inject(list, { mode: 'edit' });
defaultUrl = GetBasePath('jobs') + $routeParams.id + '/job_host_summaries/',
view = GenerateList;
// When viewing all summaries for a particular host, show job ID, otherwise row ID.
if (base === 'hosts') {
list.index = false;
} else {
list.index = true;
}
//if (base === 'hosts') {
// list.index = false;
//} else {
// list.index = true;
//}
$scope.selected = [];
// control enable/disable/show of job specific view elements
if (base === 'hosts') {
$scope.job_id = null;
$scope.host_id = $routeParams.id;
} else {
$scope.job_id = $routeParams.id;
$scope.host_id = null;
}
//if (base === 'hosts') {
//$scope.job_id = null;
//$scope.host_id = $routeParams.id;
//} else {
//}
$scope.job_id = $routeParams.id;
$scope.host_id = null;
if ($scope.RemoveSetHostLink) {
$scope.RemoveSetHostLink();
@ -56,6 +55,8 @@ function JobHostSummaryList($scope, $rootScope, $location, $log, $routeParams, R
}
$scope.removePostRefresh = $scope.$on('PostRefresh', function () {
view.inject(list, { mode: 'edit', scope: $scope });
// Set status, tooltips, badges icons, etc.
$scope.jobhosts.forEach(function(element, i) {
$scope.jobhosts[i].host_name = ($scope.jobhosts[i].summary_fields.host) ? $scope.jobhosts[i].summary_fields.host.name : '';
@ -63,67 +64,71 @@ function JobHostSummaryList($scope, $rootScope, $location, $log, $routeParams, R
$scope.jobhosts[i].statusBadgeToolTip = JobStatusToolTip($scope.jobhosts[i].status) +
" Click to view details.";
if ($scope.jobhosts[i].summary_fields.host) {
$scope.jobhosts[i].statusLinkTo = '/#/jobs/' + $scope.jobhosts[i].job + '/job_events/?host=' +
$scope.jobhosts[i].statusLinkTo = '/#/job_events/' + $scope.jobhosts[i].job + '/?host=' +
encodeURI($scope.jobhosts[i].summary_fields.host.name);
}
else {
$scope.jobhosts[i].statusLinkTo = '/#/jobs/' + $scope.jobhosts[i].job + '/job_events';
$scope.jobhosts[i].statusLinkTo = '/#/job_events/' + $scope.jobhosts[i].job;
}
});
if ($scope.job_id !== null && $scope.job_id !== undefined && $scope.job_id !== '') {
//if ($scope.job_id !== null && $scope.job_id !== undefined && $scope.job_id !== '') {
// need job_status so we can show/hide refresh button
Rest.setUrl(GetBasePath('jobs') + $scope.job_id);
Rest.get()
.success(function (data) {
LoadBreadCrumbs({
path: '/jobs/' + data.id,
title: data.id + ' - ' +
data.summary_fields.job_template.name
});
$scope.job_status = data.status;
if (!(data.status === 'pending' || data.status === 'waiting' || data.status === 'running')) {
if ($rootScope.timer) {
clearInterval($rootScope.timer);
}
}
$scope.$emit('setHostLink', data.inventory);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, {
hdr: 'Error!',
msg: 'Failed to get job status for job: ' + $scope.job_id + '. GET status: ' + status
});
Rest.setUrl(GetBasePath('jobs') + $scope.job_id + '/');
Rest.get()
.success(function (data) {
LoadBreadCrumbs({
path: '/job_host_summaries/' + $scope.job_id,
title: $scope.job_id + ' - ' + data.summary_fields.job_template.name,
altPath: '/jobs'
});
$rootScope.breadcrumbs = [{
path: '/jobs',
title: $scope.job_id + ' - ' + data.summary_fields.job_template.name,
}];
$scope.job_status = data.status;
if (!(data.status === 'pending' || data.status === 'waiting' || data.status === 'running')) {
if ($rootScope.timer) {
clearInterval($rootScope.timer);
}
}
$scope.$emit('setHostLink', data.inventory);
})
.error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to get job status for job: ' + $scope.job_id + '. GET status: ' + status
});
} else {
// Make the host name appear in breadcrumbs
LoadBreadCrumbs({
path: '/hosts/' + $scope.host_id,
title: (($scope.jobhosts.length > 0) ? $scope.jobhosts[0].summary_fields.host.name : 'Host')
});
if ($routeParams.inventory) {
$scope.$emit('setHostLink', $routeParams.inventory);
}
}
//} else {
// Make the host name appear in breadcrumbs
// LoadBreadCrumbs({
// path: '/hosts/' + $scope.host_id,
// title: (($scope.jobhosts.length > 0) ? $scope.jobhosts[0].summary_fields.host.name : 'Host')
// });
// if ($routeParams.inventory) {
// $scope.$emit('setHostLink', $routeParams.inventory);
// }
//}
});
SearchInit({
scope: scope,
scope: $scope,
set: 'jobhosts',
list: list,
url: defaultUrl
});
PaginateInit({
scope: scope,
scope: $scope,
list: list,
url: defaultUrl
});
// Called from Inventories tab, host failed events link:
if ($routeParams.host_name) {
scope[list.iterator + 'SearchField'] = 'host';
scope[list.iterator + 'SearchValue'] = $routeParams.host_name;
scope[list.iterator + 'SearchFieldLabel'] = list.fields.host.label;
$scope[list.iterator + 'SearchField'] = 'host';
$scope[list.iterator + 'SearchValue'] = $routeParams.host_name;
$scope[list.iterator + 'SearchFieldLabel'] = list.fields.host.label;
}
$scope.search(list.iterator);
@ -141,7 +146,7 @@ function JobHostSummaryList($scope, $rootScope, $location, $log, $routeParams, R
$location.url('/jobs/' + data.id + '/job_events/?host=' + encodeURI(host_name));
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to lookup last job: ' + last_job +
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to lookup last job: ' + last_job +
'. GET status: ' + status });
});
};
@ -156,7 +161,7 @@ function JobHostSummaryList($scope, $rootScope, $location, $log, $routeParams, R
$scope.jobLoading = true;
Wait('start');
Refresh({
scope: scope,
scope: $scope,
set: 'jobhosts',
iterator: 'jobhost',
url: $scope.current_url

View File

@ -111,8 +111,8 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
"aw-tool-tip=\"" + job.status.charAt(0).toUpperCase() + job.status.slice(1) +
". Click for details\" data-placement=\"top\"><i class=\"fa icon-job-" +
job.status + "\"></i></a></td>\n";
html += "<td><a href=\"/#/jobs/" + job.id + "/job_events/?host=" + encodeURI(host.name) + "\">Events</a><br />" +
"<a href=\"/#/jobs/" + job.id + "/job_host_summaries/?host_name=" + encodeURI(host.name) + "\">Hosts</a></td>\n";
html += "<td><a href=\"/#/job_events/" + job.id + "/?host=" + encodeURI(host.name) + "\">Events</a><br />" +
"<a href=\"/#/job_host_summaries/" + job.id + "/?host_name=" + encodeURI(host.name) + "\">Hosts</a></td>\n";
html += "<td class=\"break\">" + ellipsis(job.name) + "</td>\n";
html += "</tr>\n";
}

View File

@ -108,8 +108,8 @@ angular.module('CompletedJobsDefinition', [])
'class': 'btn-default btn-xs',
options: [
//{ ngHref: '/#/jobs/{{ completed_job.id }}', label: 'Status' },
{ ngHref: '/#/jobs/{{ completed_job.id }}/job_events', label: 'Events', ngHide: "completed_job.status == 'new'" },
{ ngHref: '/#/jobs/{{ completed_job.id }}/job_host_summaries', label: 'Host Summary' }
{ ngHref: '/#/job_events/{{ completed_job.id }}', label: 'Events', ngHide: "completed_job.status == 'new'" },
{ ngHref: '/#/job_host_summaries/{{ completed_job.id }}', label: 'Host Summary' }
]
}
}

View File

@ -28,13 +28,13 @@ angular.module('JobEventsListDefinition', [])
// ngShow: 'job_id !== null'
//},
events: {
href: '/#/jobs/{{ job_id }}/job_events',
href: '/#/job_events/{{ job_id }}',
label: 'Events',
active: true,
icon: 'icon-list-ul'
},
hosts: {
href: '/#/jobs/{{ job_id }}/job_host_summaries',
href: '/#/job_host_summaries/{{ job_id }}',
label: 'Host Summary',
icon: 'icon-laptop'
}
@ -47,7 +47,7 @@ angular.module('JobEventsListDefinition', [])
key: true,
nosort: true,
searchable: false,
link: false
noLink: true
},
status: {
label: 'Status',

View File

@ -27,12 +27,12 @@ angular.module('JobHostDefinition', [])
// ngShow: "job_id !== null"
//},
events: {
href: "/#/jobs/{{ job_id }}/job_events",
href: "/#/job_events/{{ job_id }}",
label: 'Events',
icon: 'icon-list-ul'
},
hosts: {
href: "/#/jobs/{{ job_id }}/job_host_summaries",
href: "/#/job_host_summariess/{{ job_id }}",
label: 'Host Summary',
active: true,
icon: 'icon-laptop'
@ -67,6 +67,7 @@ angular.module('JobHostDefinition', [])
dataPlacement: 'top',
searchField: 'failed',
searchType: 'boolean',
showValue: false,
searchOptions: [{
name: "success",
value: 0
@ -132,8 +133,8 @@ angular.module('JobHostDefinition', [])
ngClick: "refresh()",
ngShow: "host_id == null" //don't show when viewing from inventory->hosts
}
},
}
fieldActions: {}
//fieldActions: {}
});

View File

@ -91,8 +91,8 @@ angular.module('RunningJobsDefinition', [])
'class': 'btn-default btn-xs',
options: [
//{ ngHref: '/#/jobs/{{ running_job.id }}', label: 'Status' },
{ ngHref: '/#/jobs/{{ running_job.id }}/job_events', label: 'Events' },
{ ngHref: '/#/jobs/{{ running_job.id }}/job_host_summaries', label: 'Host Summary' }
{ ngHref: '/#/job_events/{{ running_job.id }}', label: 'Events' },
{ ngHref: '/#/job_host_summaries/{{ running_job.id }}', label: 'Host Summary' }
]
}
}

View File

@ -246,7 +246,6 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
$rootScope.crumbCache.push(crumb);
}
}
paths = $location.path().replace(/^\//, '').split('/');
ppath = '';
$rootScope.breadcrumbs = [];

View File

@ -372,8 +372,8 @@ angular.module('GeneratorHelpers', [])
}
])
.factory('Breadcrumbs', ['Attr',
function (Attr) {
.factory('Breadcrumbs', ['$rootScope', 'Attr',
function ($rootScope, Attr) {
return function (params) {
// Generate breadcrumbs using the list-generator.js method.

View File

@ -409,9 +409,10 @@
<script>
// When user clicks on main tab, fire the matching Angular route
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
var url = $(e.target).text();
var regx = new RegExp('/\#\/' + url.toLowerCase().replace(/ /g,'_') + '/');
var loc = window.location.toString();
var url, regx, loc;
url = ($(e.target).text() === 'Jobs') ? 'job' : $(e.target).text().toLowerCase().replace(/ /g,'_');
regx = new RegExp('/\#\/' + url);
loc = window.location.toString();
if (! regx.test(loc)) {
window.location = '#/' + url.toLowerCase().replace(/ /g,'_');
}