1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Improved how LogViewer determines status icon.

This commit is contained in:
Chris Houseknecht 2014-04-01 14:16:27 -04:00
parent 54599578a0
commit 8fc0450dd9
4 changed files with 75 additions and 162 deletions

View File

@ -12,7 +12,7 @@
function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, ProjectList, GenerateList, LoadBreadCrumbs,
Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, SelectionInit, ProjectUpdate,
ProjectStatus, FormatDate, Refresh, Wait, Stream, GetChoices, Empty, Find, LogViewer) {
Refresh, Wait, Stream, GetChoices, Empty, Find, LogViewer, GetProjectIcon, GetProjectToolTip) {
ClearScope();
@ -48,30 +48,9 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
if ($scope.projects) {
$scope.projects.forEach(function(project, i) {
if (project.status === 'ok') {
$scope.projects[i].status = 'n/a';
}
switch (project.status) {
case 'n/a':
case 'never updated':
$scope.projects[i].statusIcon = 'none';
$scope.projects[i].statusTip = 'No SCM updates have run for this project';
break;
case 'updating':
case 'running':
$scope.projects[i].statusIcon = 'running pulsate';
$scope.projects[i].statusTip = 'Running! Click for details';
break;
case 'successful':
$scope.projects[i].statusIcon = 'success';
$scope.projects[i].statusTip = 'Success! Click for details';
break;
case 'failed':
case 'missing':
$scope.projects[i].statusTip = 'Failed. Click for details';
$scope.projects[i].statusIcon = 'error';
break;
}
$scope.projects[i].statusIcon = GetProjectIcon(project.status);
$scope.projects[i].statusTip = GetProjectToolTip(project.status);
if (project.status === 'failed' && project.summary_fields.last_update && project.summary_fields.last_update.status === 'canceled') {
$scope.projects[i].statusTip = 'Canceled. Click for details';
@ -201,22 +180,18 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
} else {
if (project.related.current_update) {
Wait('start');
ProjectStatus({
project_id: id,
last_update: project.related.current_update
LogViewer({
scope: $scope,
url: project.related.current_update,
getIcon: GetProjectIcon
});
} else if (project.related.last_update) {
Wait('start');
LogViewer({
scope: $scope,
url: project.related.last_update,
status_icon: 'icon-job-' + project.statusIcon
getIcon: GetProjectIcon
});
/*
ProjectStatus({
project_id: id,
last_update: project.related.last_update
});*/
} else {
Alert('No Updates Available', 'There is no SCM update information available for this project. An update has not yet been ' +
' completed. If you have not already done so, start an update for this project.', 'alert-info');
@ -361,8 +336,8 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
ProjectsList.$inject = ['$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'ProjectList', 'GenerateList',
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors', 'GetBasePath',
'SelectionInit', 'ProjectUpdate', 'ProjectStatus', 'FormatDate', 'Refresh', 'Wait', 'Stream', 'GetChoices', 'Empty', 'Find',
'LogViewer'
'SelectionInit', 'ProjectUpdate', 'Refresh', 'Wait', 'Stream', 'GetChoices', 'Empty', 'Find',
'LogViewer', 'GetProjectIcon', 'GetProjectToolTip'
];

View File

@ -16,7 +16,7 @@ angular.module('LogViewerHelper', ['ModalDialog', 'Utilities', 'FormGenerator',
return function(params) {
var parent_scope = params.scope,
url = params.url,
status_icon = params.status_icon,
getIcon = params.getIcon,
scope = parent_scope.$new();
if (scope.removeModalReady) {
@ -37,8 +37,8 @@ angular.module('LogViewerHelper', ['ModalDialog', 'Utilities', 'FormGenerator',
scope[key] = data[key];
}
AddTable({ scope: scope, form: LogViewerStatusForm, id: 'status-form-container', status_icon: status_icon });
AddTable({ scope: scope, form: LogViewerOptionsForm, id: 'options-form-container', status_icon: status_icon });
AddTable({ scope: scope, form: LogViewerStatusForm, id: 'status-form-container', getIcon: getIcon });
AddTable({ scope: scope, form: LogViewerOptionsForm, id: 'options-form-container', getIcon: getIcon });
if (data.result_stdout) {
AddPreFormattedText({
@ -212,7 +212,7 @@ angular.module('LogViewerHelper', ['ModalDialog', 'Utilities', 'FormGenerator',
var form = params.form,
id = params.id,
scope = params.scope,
status_icon = params.status_icon,
getIcon = params.getIcon,
fld, html, url,
urls = [
{ "variable": "credential", "url": "/#/credentials/" },
@ -236,8 +236,9 @@ angular.module('LogViewerHelper', ['ModalDialog', 'Utilities', 'FormGenerator',
else if (fld === 'elapsed') {
html += scope[fld] + " <span class=\"small-text\">seconds</span>";
}
else if (status_icon && fld === 'status') {
html += "<i class=\"fa " + status_icon + "\"></i> " + scope[fld];
else if (getIcon && fld === 'status') {
html += "<i class=\"fa icon-job-" + getIcon(scope[fld]) + "\"></i> " + scope[fld];
//html += "<i class=\"fa " + status_icon + scope[fld] + "\"></i> " + scope[fld];
}
else {
html += scope[fld];

View File

@ -13,123 +13,60 @@
angular.module('ProjectsHelper', ['RestServices', 'Utilities', 'ProjectStatusDefinition', 'ProjectFormDefinition'])
.factory('ProjectStatus', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm',
'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'ProjectStatusForm', 'Wait',
function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath,
FormatDate, ProjectStatusForm, Wait) {
return function (params) {
var project_id = params.project_id,
last_update = params.last_update,
generator = GenerateForm,
form = ProjectStatusForm,
html, scope, ww, wh, x, y, maxrows;
Wait('start');
html = "<div id=\"status-modal-dialog\"><div id=\"form-container\" style=\"width: 100%;\"></div></div>\n";
$('#projects-modal-container').empty().append(html);
scope = generator.inject(form, { mode: 'edit', id: 'form-container', related: false, breadCrumbs: false });
generator.reset();
// Set modal dimensions based on viewport width
ww = $(document).width();
wh = $('body').height();
if (ww > 1199) {
// desktop
x = 675;
y = (750 > wh) ? wh - 20 : 750;
maxrows = 20;
} else if (ww <= 1199 && ww >= 768) {
x = 550;
y = (620 > wh) ? wh - 15 : 620;
maxrows = 15;
} else {
x = (ww - 20);
y = (500 > wh) ? wh : 500;
maxrows = 10;
.factory('GetProjectIcon', [ function() {
return function(status) {
var result = '';
switch (status) {
case 'n/a':
case 'ok':
case 'never updated':
result = 'none';
break;
case 'pending':
case 'waiting':
case 'new':
result = 'none';
break;
case 'updating':
case 'running':
result = 'running pulsate';
break;
case 'successful':
result = 'success';
break;
case 'failed':
case 'missing':
result = 'error';
}
// Create the modal
$('#status-modal-dialog').dialog({
buttons: {
"OK": function () {
$(this).dialog("close");
}
},
modal: true,
width: x,
height: y,
autoOpen: false,
create: function () {
// fix the close button
$('.ui-dialog[aria-describedby="status-modal-dialog"]').find('.ui-dialog-titlebar button').empty().attr({
'class': 'close'
}).text('x');
// fix the OK button
$('.ui-dialog[aria-describedby="status-modal-dialog"]').find('.ui-dialog-buttonset button:first')
.attr({
'class': 'btn btn-primary'
});
},
resizeStop: function () {
var dialog = $('.ui-dialog[aria-describedby="status-modal-dialog"]'),
titleHeight = dialog.find('.ui-dialog-titlebar').outerHeight(),
buttonHeight = dialog.find('.ui-dialog-buttonpane').outerHeight(),
content = dialog.find('#status-modal-dialog');
content.width(dialog.width() - 28);
content.css({ height: (dialog.height() - titleHeight - buttonHeight - 10) });
},
close: function () {
// Destroy on close
// Destroy on close
$('.tooltip').each(function () {
// Remove any lingering tooltip <div> elements
$(this).remove();
});
$('.popover').each(function () {
// remove lingering popover <div> elements
$(this).remove();
});
$('#status-modal-dialog').dialog('destroy');
$('#projects-modal-container').empty();
},
open: function () {
Wait('stop');
}
});
// Retrieve detail record and prepopulate the form
Rest.setUrl(last_update);
Rest.get()
.success(function (data) {
var results = data, fld;
for (fld in form.fields) {
if (results[fld]) {
if (fld === 'created') {
scope[fld] = FormatDate(new Date(results[fld]));
} else {
scope[fld] = results[fld];
}
} else {
if (results.summary_fields.project[fld]) {
scope[fld] = results.summary_fields.project[fld];
}
}
}
$('#status-modal-dialog')
.dialog({
title: results.summary_fields.project.name + ' Status'
})
.dialog('open');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to retrieve project: ' + project_id + '. GET returned: ' + status
});
});
return result;
};
}
]);
}])
.factory('GetProjectToolTip', [ function() {
return function(status) {
var result = '';
switch (status) {
case 'n/a':
case 'ok':
case 'never updated':
result = 'No SCM updates have run for this project';
break;
case 'pending':
case 'waiting':
case 'new':
result = 'Queued. Click for details';
break;
case 'updating':
case 'running':
result = 'Running! Click for details';
break;
case 'successful':
result = 'Success! Click for details';
break;
case 'failed':
case 'missing':
result = 'Failed. Click for details';
}
return result;
};
}]);

View File

@ -60,7 +60,7 @@ angular.module('ProjectsListDefinition', [])
ngClick: 'addProject()',
awToolTip: 'Create a new project'
},
help: {
/*help: {
awPopOver: "<dl>\n<dt>Updating</dt><dd>A source control update is in progress.</dd>\n" +
"<dt>Never Updated</dt><dd>This project has not yet been updated from source control.</dd>\n" +
"<dt>Failed</dt><dd>An error occurred during the most recent source control update, click the status " +
@ -74,7 +74,7 @@ angular.module('ProjectsListDefinition', [])
mode: 'edit',
awToolTip: 'Click for help',
awTipPlacement: 'top'
},
},*/
refresh: {
mode: 'all',
awToolTip: "Refresh the page",