From a5bb145f703b77adfd14c74f4e27f9752c2e2bdb Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Fri, 1 Nov 2013 23:34:24 +0000 Subject: [PATCH] Credential now working on Project detail and Group detail pages. --- awx/ui/static/js/controllers/Projects.js | 191 ++++++++++++++--------- awx/ui/static/js/forms/Projects.js | 89 ++--------- awx/ui/static/js/helpers/Groups.js | 8 + 3 files changed, 140 insertions(+), 148 deletions(-) diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index 8c942c616e..36fa64d5b7 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -230,7 +230,8 @@ ProjectsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routePar function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, ProjectsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, - GetBasePath, ReturnToCaller, GetProjectPath, LookUpInit, OrganizationList) + GetBasePath, ReturnToCaller, GetProjectPath, LookUpInit, OrganizationList, + CredentialList, GetChoices) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -248,21 +249,47 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam LoadBreadCrumbs(); GetProjectPath({ scope: scope, master: master }); - scope.scm_type = null; - master.scm_type = null; - scope.scm_type_options = [ - { label: 'Git', value: 'git' }, - { label: 'SVN', value: 'svn' }, - { label: 'Mercurial', value: 'hg'}]; + //scope.scm_type = null; + //master.scm_type = null; + + if (scope.removeChoicesReady) { + scope.removeChoicesReady(); + } + scope.removeChoicesReady = scope.$on('choicesReady', function() { + console.log('setting type'); + var found = false; + for (var i=0; i < scope.scm_type_options.length; i++) { + if (scope.scm_type_options[i].value == '') { + scope['scm_type'] = scope.scm_type_options[i]; + found = true; + break; + } + } + }); + + // Load the list of options for Kind + GetChoices({ + scope: scope, + url: defaultUrl, + field: 'scm_type', + variable: 'scm_type_options', + callback: 'choicesReady' + }); LookUpInit({ scope: scope, form: form, - current_item: null, list: OrganizationList, field: 'organization' }); + LookUpInit({ + scope: scope, + form: form, + list: CredentialList, + field: 'credential' + }); + // Save scope.formSave = function() { generator.clearApiErrors(); @@ -278,7 +305,7 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam data[fld] = scope[fld]; } } - } + } if (scope.scm_type) { data.scm_type = scope.scm_type.value; delete data.local_path; @@ -337,14 +364,14 @@ function ProjectsAdd ($scope, $rootScope, $compile, $location, $log, $routeParam ProjectsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', - 'ReturnToCaller', 'GetProjectPath', 'LookUpInit', 'OrganizationList' + 'ReturnToCaller', 'GetProjectPath', 'LookUpInit', 'OrganizationList', 'CredentialList', 'GetChoices' ]; function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, ProjectsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, Prompt, ClearScope, GetBasePath, ReturnToCaller, GetProjectPath, - Authorization) + Authorization, CredentialList, LookUpInit, GetChoices) { ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. @@ -361,11 +388,6 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara var id = $routeParams.id; var relatedSets = {}; - scope.scm_type_options = [ - { label: 'Git', value: 'git' }, - { label: 'SVN', value: 'svn' }, - { label: 'Mercurial', value: 'hg'}]; - scope.project_local_paths = []; scope.base_dir = ''; @@ -401,66 +423,95 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara scope.project_local_paths = opts; scope.base_dir = 'You do not have access to view this property'; } + + LookUpInit({ + scope: scope, + form: form, + list: CredentialList, + field: 'credential' + }); + scope.auth_required = (scope.scm_type && (scope.scm_username || scope.scm_password || scope.scm_key_data)) ? true : false; master.auth_required = scope.auth_required; }); - // Retrieve detail record and prepopulate the form - Rest.setUrl(defaultUrl); - Rest.get({ params: {id: id} }) - .success( function(data, status, headers, config) { - LoadBreadCrumbs({ path: '/projects/' + id, title: data.name }); - for (var fld in form.fields) { - if (form.fields[fld].type == 'checkbox_group') { - for (var i=0; i < form.fields[fld].fields.length; i++) { - scope[form.fields[fld].fields[i].name] = data[form.fields[fld].fields[i].name]; - master[form.fields[fld].fields[i].name] = data[form.fields[fld].fields[i].name]; - } - } - else { - if (data[fld]) { - scope[fld] = data[fld]; - master[fld] = data[fld]; - } - } - } - var related = data.related; - for (var set in form.related) { - if (related[set]) { - relatedSets[set] = { url: related[set], iterator: form.related[set].iterator }; - } - } - - if (data.scm_type !== "") { - for (var i=0; i < scope.scm_type_options.length; i++) { - if (scope.scm_type_options[i].value == data.scm_type) { - scope.scm_type = scope.scm_type_options[i]; - break; + if (scope.removeChoicesReady) { + scope.removeChoicesReady(); + } + scope.removeChoicesReady = scope.$on('choicesReady', function() { + // Retrieve detail record and prepopulate the form + Rest.setUrl(defaultUrl); + Rest.get({ params: {id: id} }) + .success( function(data, status, headers, config) { + LoadBreadCrumbs({ path: '/projects/' + id, title: data.name }); + for (var fld in form.fields) { + if (form.fields[fld].type == 'checkbox_group') { + for (var i=0; i < form.fields[fld].fields.length; i++) { + scope[form.fields[fld].fields[i].name] = data[form.fields[fld].fields[i].name]; + master[form.fields[fld].fields[i].name] = data[form.fields[fld].fields[i].name]; + } } - } - scope.pathRequired = false; - } - else { - scope.pathRequired = true; - } + else { + if (data[fld]) { + scope[fld] = data[fld]; + master[fld] = data[fld]; + } + } + if (fld !== 'organization' && form.fields[fld].sourceModel && + data.summary_fields && data.summary_fields[form.fields[fld].sourceModel]) { + scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + } + } + var related = data.related; + for (var set in form.related) { + if (related[set]) { + relatedSets[set] = { url: related[set], iterator: form.related[set].iterator }; + } + } + + if (data.scm_type !== "") { + for (var i=0; i < scope.scm_type_options.length; i++) { + if (scope.scm_type_options[i].value == data.scm_type) { + scope.scm_type = scope.scm_type_options[i]; + break; + } + } + scope.pathRequired = false; + } + else { + scope.pathRequired = true; + } + + master['scm_type'] = scope['scm_type']; + master['auth_required'] = scope['auth_required']; + + scope.scmBranchLabel = (scope.scm_type && scope.scm_type.value && scope.scm_type.value == 'svn') ? 'Revision #' : 'SCM Branch'; + setAskCheckboxes(); + + // Initialize related search functions. Doing it here to make sure relatedSets object is populated. + RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets }); + RelatedPaginateInit({ scope: scope, relatedSets: relatedSets }); + scope.$emit('projectLoaded'); + }) + .error( function(data, status, headers, config) { + ProcessErrors(scope, data, status, form, + { hdr: 'Error!', msg: 'Failed to retrieve project: ' + id + '. GET status: ' + status }); + }); + }); + + // Load the list of options for Kind + GetChoices({ + scope: scope, + url: defaultUrl, + field: 'scm_type', + variable: 'scm_type_options', + callback: 'choicesReady' + }); - master['scm_type'] = scope['scm_type']; - master['auth_required'] = scope['auth_required']; - scope.scmBranchLabel = (scope.scm_type && scope.scm_type.value && scope.scm_type.value == 'svn') ? 'Revision #' : 'SCM Branch'; - setAskCheckboxes(); - - // Initialize related search functions. Doing it here to make sure relatedSets object is populated. - RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets }); - RelatedPaginateInit({ scope: scope, relatedSets: relatedSets }); - scope.$emit('projectLoaded'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, form, - { hdr: 'Error!', msg: 'Failed to retrieve project: ' + id + '. GET status: ' + status }); - }); - - // Save changes to the parent scope.formSave = function() { generator.clearApiErrors(); @@ -590,5 +641,5 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara ProjectsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt', 'ClearScope', 'GetBasePath', 'ReturnToCaller', - 'GetProjectPath', 'Authorization' + 'GetProjectPath', 'Authorization', 'CredentialList', 'LookUpInit', 'GetChoices' ]; diff --git a/awx/ui/static/js/forms/Projects.js b/awx/ui/static/js/forms/Projects.js index 95ad9e1df7..255eb6d94f 100644 --- a/awx/ui/static/js/forms/Projects.js +++ b/awx/ui/static/js/forms/Projects.js @@ -52,9 +52,8 @@ angular.module('ProjectFormDefinition', []) type: 'select', ngOptions: 'type.label for type in scm_type_options', ngChange: 'scmChange()', - defaultOption: 'Manual', - addRequired: false, - editRequired: false + addRequired: true, + editRequired: true }, missing_path_alert: { type: 'alertblock', @@ -71,7 +70,7 @@ angular.module('ProjectFormDefinition', []) type: 'textarea', "class": 'col-lg-6', showonly: true, - ngShow: "scm_type == '' || scm_type == null", + ngShow: "scm_type.value == ''", awPopOver: '

Base path used for locating playbooks. Directories found inside this path will be listed in the playbook directory drop-down. ' + 'Together the base path and selected playbook directory provide the full path used to locate playbooks.

' + '

Use PROJECTS_ROOT in your environment settings file to determine the base path value.

', @@ -85,7 +84,7 @@ angular.module('ProjectFormDefinition', []) id: 'local-path-select', ngOptions: 'path for path in project_local_paths', awRequiredWhen: { variable: "pathRequired", init: "true" }, - ngShow: "scm_type == '' || scm_type == null", + ngShow: "scm_type.value == ''", awPopOver: '

Select from the list of directories found in the base path.' + 'Together the base path and the playbook directory provide the full path used to locate playbooks.

' + '

Use PROJECTS_ROOT in your environment settings file to determine the base path value.

', @@ -96,7 +95,7 @@ angular.module('ProjectFormDefinition', []) scm_url: { label: 'SCM URL', type: 'text', - ngShow: "scm_type !== '' && scm_type !== null", + ngShow: "scm_type.value !== ''", awRequiredWhen: { variable: "scm_type", init: "true" }, helpCollapse: [ { hdr: 'GIT URLs', @@ -124,86 +123,20 @@ angular.module('ProjectFormDefinition', []) scm_branch: { labelBind: "scmBranchLabel", type: 'text', - ngShow: "scm_type !== '' && scm_type !== null", + ngShow: "scm_type.value !== ''", addRequired: false, editRequired: false }, - credential: { // FIXME: Lookup doesn't work yet! + credential: { label: 'SCM Credential', type: 'lookup', + ngShow: "scm_type.value !== ''", sourceModel: 'credential', sourceField: 'name', ngClick: 'lookUpCredential()', addRequired: false, editRequired: false, }, - /*auth_required: { - label: 'Authorization required?', - type: 'checkbox', - ngShow: "scm_type !== '' && scm_type !== null", - addRequired: false, - editRequired: false, - ngChange: 'authChange()' - }, - scm_username: { - label: 'SCM Username', - type: 'text', - ngShow: "scm_type !== '' && scm_type !== null && auth_required", - addRequired: false, - editRequired: false - }, - "scm_password": { - label: 'SCM Password', - type: 'password', - ngShow: "scm_type !== '' && scm_type !== null && auth_required", - addRequired: false, - editRequired: false, - ngChange: "clearPWConfirm('scm_password_confirm')", - ask: true, - clear: true, - associated: 'scm_password_confirm', - autocomplete: false - }, - "scm_password_confirm": { - label: 'Confirm SCM Password', - type: 'password', - ngShow: "scm_type !== '' && scm_type !== null && auth_required", - addRequired: false, - editRequired: false, - awPassMatch: true, - associated: 'scm_password', - autocomplete: false - }, - "scm_key_data": { - label: 'SCM Private Key', - type: 'textarea', - ngShow: "scm_type !== '' && scm_type !== null && auth_required", - xtraWide: true, - addRequired: false, - editRequired: false, - 'class': 'ssh-key-field', - rows: 10 - }, - "scm_key_unlock": { - label: 'SCM Key Password', - type: 'password', - ngShow: "scm_type !== '' && scm_type !== null && scm_key_data && auth_required", - addRequired: false, - editRequired: false, - ngChange: "clearPWConfirm('scm_key_unlock_confirm')", - associated: 'scm_key_unlock_confirm', - ask: true, - clear: true - }, - "scm_key_unlock_confirm": { - label: 'Confirm SCM Key Password', - type: 'password', - ngShow: "scm_type !== '' && scm_type !== null && scm_key_data && auth_required", - addRequired: false, - editRequired: false, - awPassMatch: true, - associated: 'scm_key_unlock' - },*/ checkbox_group: { label: 'SCM Options', type: 'checkbox_group', @@ -214,7 +147,7 @@ angular.module('ProjectFormDefinition', []) name: 'scm_clean', label: 'Clean', type: 'checkbox', - ngShow: "scm_type !== '' && scm_type !== null", + ngShow: "scm_type.value !== ''", addRequired: false, editRequired: false, awPopOver: '

Remove any local modifications prior to performing an update.

', @@ -227,7 +160,7 @@ angular.module('ProjectFormDefinition', []) name: 'scm_delete_on_update', label: 'Delete on Update', type: 'checkbox', - ngShow: "scm_type !== '' && scm_type !== null", + ngShow: "scm_type.value !== ''", addRequired: false, editRequired: false, awPopOver: '

Delete the local repository in its entirety prior to performing an update.

Depending on the size of the ' + @@ -241,7 +174,7 @@ angular.module('ProjectFormDefinition', []) name: 'scm_update_on_launch', label: 'Update on Launch', type: 'checkbox', - ngShow: "scm_type !== '' && scm_type !== null", + ngShow: "scm_type.value !== ''", addRequired: false, editRequired: false, awPopOver: '

Each time a job runs using this project, perform an update to the local repository prior to starting the job.

', diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index 3a91f951f0..fd8c7b98fd 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -781,6 +781,14 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', ' scope[fld] = data[fld]; master[fld] = scope[fld]; } + + if (form.fields[fld].sourceModel && data.summary_fields && + data.summary_fields[form.fields[fld].sourceModel]) { + scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = + data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; + } } LookUpInit({