From de9c8a258cee3a4d9adafe904d3abb73dfa2d60d Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Tue, 10 Sep 2013 02:39:58 -0400 Subject: [PATCH] AC-423, AC-424, AC-425, AC-426 resolved issues. --- awx/ui/static/js/controllers/JobTemplates.js | 72 ++++++++++++++++++- awx/ui/static/js/controllers/Projects.js | 25 ++++--- awx/ui/static/js/forms/JobTemplates.js | 6 -- awx/ui/static/js/helpers/JobSubmission.js | 56 ++++++++++++--- awx/ui/static/js/helpers/Lookup.js | 13 +++- awx/ui/static/js/helpers/Projects.js | 11 +-- awx/ui/static/js/lists/Projects.js | 2 +- awx/ui/static/less/ansible-ui.less | 4 ++ awx/ui/static/lib/ansible/directives.js | 2 - awx/ui/static/lib/ansible/form-generator.js | 3 + .../static/lib/ansible/generator-helpers.js | 4 +- awx/ui/templates/ui/index.html | 7 +- 12 files changed, 163 insertions(+), 42 deletions(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index c748d339fa..1878c2d9b9 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -144,12 +144,48 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP } } }; + + // Detect and alert user to potential SCM status issues + var checkSCMStatus = function(oldValue, newValue) { + if (oldValue !== newValue) { + Rest.setUrl(GetBasePath('projects') + scope.project + '/'); + Rest.get() + .success( function(data, status, headers, config) { + var msg; + switch(data.status) { + case 'failed': + msg = "The selected project has a failed status. Review the project's SCM settings" + + " and run an update before adding it to a template."; + break; + case 'never updated': + msg = 'The selected project has a never updated status. You will need to run a successful' + + ' update in order to selected a playbook. Without a valid playbook you will not be able ' + + ' to save this template.'; + break; + case 'missing': + msg = 'The selected project has a status of missing. Please check the server and make sure ' + + ' the directory exists and file permissions are set correctly.'; + break; + } + if (msg) { + Alert('Waning', msg, 'alert-info'); + } + }) + .error( function(data, status, headers, config) { + ProcessErrors(scope, data, status, form, + { hdr: 'Error!', msg: 'Failed to get project ' + scope.project +'. GET returned status: ' + status }); + }); + } + } // Register a watcher on project_name if (scope.selectPlaybookUnregister) { scope.selectPlaybookUnregister(); } - scope.selectPlaybookUnregister = scope.$watch('project_name', selectPlaybook); + scope.selectPlaybookUnregister = scope.$watch('project_name', function(oldval, newval) { + selectPlaybook(oldval, newval); + checkSCMStatus(oldval, newval); + }); LookUpInit({ scope: scope, @@ -272,6 +308,39 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route }); } } + + // Detect and alert user to potential SCM status issues + var checkSCMStatus = function() { + Rest.setUrl(GetBasePath('projects') + scope.project + '/'); + Rest.get() + .success( function(data, status, headers, config) { + var msg; + switch(data.status) { + case 'failed': + msg = "The selected project has a failed status. Review the project's SCM settings" + + " and run an update before adding it to a template."; + break; + case 'never updated': + msg = 'The selected project has a never updated status. You will need to run a successful' + + ' update in order to selected a playbook. Without a valid playbook you will not be able ' + + ' to save this template.'; + break; + case 'missing': + msg = 'The selected project has a status of missing. Please check the server and make sure ' + + ' the directory exists and file permissions are set correctly.'; + break; + } + + if (msg) { + Alert('Waning', msg, 'alert-info'); + } + }) + .error( function(data, status, headers, config) { + ProcessErrors(scope, data, status, form, + { hdr: 'Error!', msg: 'Failed to get project ' + scope.project +'. GET returned status: ' + status }); + }); + } + // Register a watcher on project_name. Refresh the playbook list on change. if (scope.selectPlaybookUnregister) { @@ -281,6 +350,7 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route if (oldValue !== newValue && newValue !== '' && newValue !== null && newValue !== undefined) { scope.playbook = null; getPlaybooks(scope.project); + checkSCMStatus(); } }); diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index fa45ebd3ba..5d6dd99eeb 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -13,7 +13,7 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, ProjectList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, SelectionInit, ProjectUpdate, ProjectStatus, - FormatDate) + FormatDate) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -34,11 +34,17 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, } scope.projectsPostRefresh = scope.$on('PostRefresh', function() { for (var i=0; i < scope.projects.length; i++) { - if (scope.projects[i].scm_type == null) { - // override the last_update_failed on manual projects- it should be false so we get a - // green badge. if projet scm_type changed from something to manual, last_update_failed - // will contain status of last update, which is not what we want. - scope.projects[i].last_update_failed = false; + switch(scope.projects[i].status) { + case 'updating': + case 'successful': + case 'ok': + scope.projects[i].badge = 'false'; + break; + case 'never updated': + case 'failed': + case 'missing': + scope.projects[i].badge = 'true'; + break; } scope.projects[i].last_updated = (scope.projects[i].last_updated !== null) ? FormatDate(new Date(scope.projects[i].last_updated)) : null; @@ -89,7 +95,7 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, statusCheckRemove(); }); - // Refresh the project list so we're looking at the latest data + // Refresh the project list so we're looking at the latest data scope.search(list.iterator); } @@ -124,7 +130,7 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, scope.SCMUpdate = function(project_id) { for (var i=0; i < scope.projects.length; i++) { if (scope.projects[i].id == project_id) { - if (scope.projects[i].scm_type == "") { + if (scope.projects[i].scm_type == "" || scope.projects[i].scm_type == null ) { Alert('Missing SCM Setup', 'Before running an SCM update, edit the project and provide the SCM access information.', 'alert-info'); } else if (scope.projects[i].status == 'updating') { @@ -140,7 +146,7 @@ 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']; + 'GetBasePath', 'SelectionInit', 'ProjectUpdate', 'ProjectStatus', 'FormatDate' ]; function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, ProjectsForm, @@ -162,7 +168,6 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam generator.reset(); LoadBreadCrumbs(); GetProjectPath({ scope: scope, master: master }); - //console.log(scope.) scope.scm_type = null; master.scm_type = null; diff --git a/awx/ui/static/js/forms/JobTemplates.js b/awx/ui/static/js/forms/JobTemplates.js index eab5635b21..b5e0c3363b 100644 --- a/awx/ui/static/js/forms/JobTemplates.js +++ b/awx/ui/static/js/forms/JobTemplates.js @@ -51,8 +51,6 @@ angular.module('JobTemplateFormDefinition', []) type: 'lookup', sourceModel: 'inventory', sourceField: 'name', - addRequired: true, - editRequired: true, ngClick: 'lookUpInventory()', awRequiredWhen: {variable: "inventoryrequired", init: "true" }, column: 1 @@ -62,8 +60,6 @@ angular.module('JobTemplateFormDefinition', []) type: 'lookup', sourceModel: 'project', sourceField: 'name', - addRequired: true, - editRequired: true, ngClick: 'lookUpProject()', awRequiredWhen: {variable: "projectrequired", init: "true" }, column: 1 @@ -73,8 +69,6 @@ angular.module('JobTemplateFormDefinition', []) type:'select', ngOptions: 'book for book in playbook_options', id: 'playbook-select', - addRequired: true, - editRequired: true, awRequiredWhen: {variable: "playbookrequired", init: "true" }, column: 1 }, diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js index e3adeb26f7..653b0574c7 100644 --- a/awx/ui/static/js/helpers/JobSubmission.js +++ b/awx/ui/static/js/helpers/JobSubmission.js @@ -19,7 +19,8 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential var html = ''; var field, element, dialogScope, fld; var base = $location.path().replace(/^\//,'').split('/')[0]; - + var extra_html = params.extra_html; + function navigate(canceled) { //Decide where to send the user once the modal dialog closes if (!canceled) { @@ -31,7 +32,6 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential } } else { - console.log('navigating to: ' + base); $location.path('/' + base); } } @@ -58,6 +58,9 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential if (form.name == 'credential') { cancel(); } + else { + scope.$emit('UpdateSubmitted'); + } } scope.startJob = function() { @@ -96,14 +99,15 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential if (passwords.length > 0) { // We need to prompt for passwords - html += html += "
\n"; + html += "\n"; + html += (extra_html) ? extra_html : ""; for (var i=0; i < passwords.length; i++) { // Add the password field field = (form.fields[passwords[i]]) ? form.fields[passwords[i]] : ProjectsForm.fields[passwords[i]]; fld = passwords[i]; scope[fld] = ''; html += "
\n"; - html += "' + "\n"; + html += "' + "\n"; html += "
\n"; html += "\n"; - html += "' + "\n"; + html += "' + "\n"; html += "
\n"; html += "\n"; + extra_html += "\n"; + extra_html += "
\n"; + extra_html += "\n"; + extra_html += "\n"; + extra_html += "
\n"; + extra_html += "" : ""; // Badge - if (field.badgeIcon && field.badgePlacement && field.badgePlacement == 'left') { + if (options.mode !== 'lookup' && field.badgeIcon && field.badgePlacement && field.badgePlacement == 'left') { html += Badge(field); } @@ -262,7 +262,7 @@ angular.module('GeneratorHelpers', ['GeneratorHelpers']) ">
\n" : ""; // Badge - if (field.badgeIcon && field.badgePlacement && field.badgePlacement !== 'left') { + if (options.mode !== 'lookup' && field.badgeIcon && field.badgePlacement && field.badgePlacement !== 'left') { html += Badge(field); } } diff --git a/awx/ui/templates/ui/index.html b/awx/ui/templates/ui/index.html index a9e7123245..c2291bba4e 100644 --- a/awx/ui/templates/ui/index.html +++ b/awx/ui/templates/ui/index.html @@ -202,12 +202,11 @@