From 8fc0450dd9943f4e7913c4a4ac759bf8ac42a336 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Tue, 1 Apr 2014 14:16:27 -0400 Subject: [PATCH] Improved how LogViewer determines status icon. --- awx/ui/static/js/controllers/Projects.js | 47 ++---- awx/ui/static/js/helpers/LogViewer.js | 13 +- awx/ui/static/js/helpers/Projects.js | 173 +++++++---------------- awx/ui/static/js/lists/Projects.js | 4 +- 4 files changed, 75 insertions(+), 162 deletions(-) diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index 6c92171d33..275eed2545 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -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' ]; diff --git a/awx/ui/static/js/helpers/LogViewer.js b/awx/ui/static/js/helpers/LogViewer.js index 56b8404eef..7322af9cf0 100644 --- a/awx/ui/static/js/helpers/LogViewer.js +++ b/awx/ui/static/js/helpers/LogViewer.js @@ -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] + " seconds"; } - else if (status_icon && fld === 'status') { - html += " " + scope[fld]; + else if (getIcon && fld === 'status') { + html += " " + scope[fld]; + //html += " " + scope[fld]; } else { html += scope[fld]; diff --git a/awx/ui/static/js/helpers/Projects.js b/awx/ui/static/js/helpers/Projects.js index 37ee28038f..ee9081c347 100644 --- a/awx/ui/static/js/helpers/Projects.js +++ b/awx/ui/static/js/helpers/Projects.js @@ -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 = "
\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
elements - $(this).remove(); - }); - $('.popover').each(function () { - // remove lingering popover
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; }; - } -]); \ No newline at end of file + }]) + + .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; + }; + }]); \ No newline at end of file diff --git a/awx/ui/static/js/lists/Projects.js b/awx/ui/static/js/lists/Projects.js index 30ed52b55e..a3d94a410d 100644 --- a/awx/ui/static/js/lists/Projects.js +++ b/awx/ui/static/js/lists/Projects.js @@ -60,7 +60,7 @@ angular.module('ProjectsListDefinition', []) ngClick: 'addProject()', awToolTip: 'Create a new project' }, - help: { + /*help: { awPopOver: "
\n
Updating
A source control update is in progress.
\n" + "
Never Updated
This project has not yet been updated from source control.
\n" + "
Failed
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",