diff --git a/awx/ui/client/src/inventories/insights/insights.controller.js b/awx/ui/client/src/inventories/insights/insights.controller.js index 74bd1a7652..69cc50e7ed 100644 --- a/awx/ui/client/src/inventories/insights/insights.controller.js +++ b/awx/ui/client/src/inventories/insights/insights.controller.js @@ -4,8 +4,8 @@ * All Rights Reserved *************************************************/ -export default [ 'InsightsData', '$scope', 'moment', '$state', -function (data, $scope, moment, $state) { +export default [ 'InsightsData', '$scope', 'moment', '$state', 'resourceData', +function (data, $scope, moment, $state, resourceData) { function init() { @@ -20,6 +20,8 @@ function (data, $scope, moment, $state) { $scope.low_count = _.filter($scope.reports_dataset.reports, (report) => {return report.rule.severity === "INFO"; }).length; let a = moment(), b = moment($scope.reports_dataset.last_check_in); $scope.last_check_in = a.diff(b, 'hours'); + $scope.inventory = resourceData.data; + $scope.insights_credential = resourceData.data.summary_fields.insights_credential.id; } init(); @@ -75,8 +77,8 @@ function (data, $scope, moment, $state) { $scope.viewDataInInsights = function(){ window.open(`https://access.redhat.com/insights/inventory?machine=${$scope.$parent.host.insights_system_id}`, '_blank'); }; - $scope.remediateInventory = function(){ - $state.go('templates.addJobTemplate'); + $scope.remediateInventory = function(inv_id, inv_name, insights_credential){ + $state.go('templates.addJobTemplate', {inventory_id: inv_id, inventory_name:inv_name, credential_id: insights_credential}); }; $scope.formCancel = function(){ $state.go('inventories', null, {reload: true}); diff --git a/awx/ui/client/src/inventories/insights/insights.partial.html b/awx/ui/client/src/inventories/insights/insights.partial.html index 201f30171c..c161c49fea 100644 --- a/awx/ui/client/src/inventories/insights/insights.partial.html +++ b/awx/ui/client/src/inventories/insights/insights.partial.html @@ -76,6 +76,6 @@
diff --git a/awx/ui/client/src/inventories/standard/edit/inventory-edit.controller.js b/awx/ui/client/src/inventories/standard/edit/inventory-edit.controller.js index 5b9d0e69bc..70500bac10 100644 --- a/awx/ui/client/src/inventories/standard/edit/inventory-edit.controller.js +++ b/awx/ui/client/src/inventories/standard/edit/inventory-edit.controller.js @@ -91,8 +91,8 @@ function InventoriesEdit($scope, $location, $state.go('inventories'); }; - $scope.remediateInventory = function(){ - $state.go('templates.addJobTemplate'); + $scope.remediateInventory = function(inv_id, inv_name, insights_credential){ + $state.go('templates.addJobTemplate', {inventory_id: inv_id, inventory_name:inv_name, credential_id: insights_credential}); }; } diff --git a/awx/ui/client/src/inventories/standard/inventory.form.js b/awx/ui/client/src/inventories/standard/inventory.form.js index ee31503dfc..468ab1112f 100644 --- a/awx/ui/client/src/inventories/standard/inventory.form.js +++ b/awx/ui/client/src/inventories/standard/inventory.form.js @@ -191,7 +191,7 @@ function(i18n, InventoryCompletedJobsList) { }, relatedButtons: { remediate_inventory: { - ngClick: 'remediateInventory()', + ngClick: 'remediateInventory(id, name, insights_credential)', ngShow: 'insights_credential!==null', label: i18n._('Remediate Inventory'), class: 'Form-primaryButton' diff --git a/awx/ui/client/src/projects/add/projects-add.controller.js b/awx/ui/client/src/projects/add/projects-add.controller.js index 2c90d6448e..7f2e4c7abc 100644 --- a/awx/ui/client/src/projects/add/projects-add.controller.js +++ b/awx/ui/client/src/projects/add/projects-add.controller.js @@ -121,6 +121,7 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm', if ($scope.scm_type.value) { switch ($scope.scm_type.value) { case 'git': + $scope.credentialLabel = "SCM Credential"; $scope.urlPopover = '' + i18n._('Example URLs for GIT SCM include:') + '
' + i18n._('Example URLs for Subversion SCM include:') + '
' + '' + i18n._('Example URLs for Mercurial SCM include:') + '
' + '' + i18n._('URL popover text'); } } @@ -151,5 +161,15 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm', $scope.formCancel = function() { $state.go('projects'); }; + $scope.lookupCredential = function(){ + let credType = ($scope.scm_type.value === "insights") ? 13 : 2; //insights cred type is 13, SCM is 2 + $state.go('.credential', { + credential_search: { + credential_type: credType, + page_size: '5', + page: '1' + } + }); + }; } ]; diff --git a/awx/ui/client/src/projects/edit/projects-edit.controller.js b/awx/ui/client/src/projects/edit/projects-edit.controller.js index 4cb088a638..ea5b9f9cd3 100644 --- a/awx/ui/client/src/projects/edit/projects-edit.controller.js +++ b/awx/ui/client/src/projects/edit/projects-edit.controller.js @@ -254,6 +254,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest', if ($scope.scm_type.value) { switch ($scope.scm_type.value) { case 'git': + $scope.credentialLabel = "SCM Credential"; $scope.urlPopover = '
' + i18n._('Example URLs for GIT SCM include:') + '
' + i18n.sprintf(i18n._('%sNote:%s When using SSH protocol for GitHub or Bitbucket, enter an SSH key only, ' + @@ -261,11 +262,13 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest', 'SSH. GIT read only protocol (git://) does not use username or password information.'), '', ''); break; case 'svn': + $scope.credentialLabel = "SCM Credential"; $scope.urlPopover = '
' + i18n._('Example URLs for Subversion SCM include:') + '
' + '' + i18n._('Example URLs for Mercurial SCM include:') + '
' + '' + i18n._('URL popover text'); } } }; + $scope.lookupCredential = function(){ + let credType = ($scope.scm_type.value === "insights") ? 13 : 2; //insights cred type is 13, SCM is 2 + $state.go('.credential', { + credential_search: { + credential_type: credType, + page_size: '5', + page: '1' + } + }); + }; + $scope.SCMUpdate = function() { if ($scope.project_obj.scm_type === "Manual" || Empty($scope.project_obj.scm_type)) { // ignore diff --git a/awx/ui/client/src/projects/projects.form.js b/awx/ui/client/src/projects/projects.form.js index 8297213be7..7399546d68 100644 --- a/awx/ui/client/src/projects/projects.form.js +++ b/awx/ui/client/src/projects/projects.form.js @@ -131,9 +131,10 @@ export default ['i18n', 'NotificationsList', function(i18n, NotificationsList) { basePath: 'credentials', list: 'CredentialList', // apply a default search filter to show only scm credentials - search: { - kind: 'scm' - }, + // search: { + // kind: 'scm' + // }, + ngClick: 'lookupCredential()', autopopulateLookup: false, awRequiredWhen: { reqExpression: "credRequired", diff --git a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js index f819b14b5f..14041b1a85 100644 --- a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js +++ b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js @@ -9,13 +9,13 @@ '$stateParams', 'JobTemplateForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'ClearScope', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'GetChoices', '$state', - 'CreateSelect2', '$q', 'i18n', + 'CreateSelect2', '$q', 'i18n', 'Inventory', 'Project', function( $filter, $scope, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, ClearScope, GetBasePath, md5Setup, ParseTypeChange, Wait, Empty, ToJSON, CallbackHelpInit, GetChoices, - $state, CreateSelect2, $q, i18n + $state, CreateSelect2, $q, i18n, Inventory, Project ) { Rest.setUrl(GetBasePath('job_templates')); @@ -80,24 +80,6 @@ } $scope.job_type = $scope.job_type_options[form.fields.job_type.default]; - // if you're getting to the form from the scan job section on inventories, - // set the job type select to be scan - if ($stateParams.inventory_id) { - // This means that the job template form was accessed via inventory prop's - // This also means the job is a scan job. - $scope.job_type.value = 'scan'; - $scope.jobTypeChange(); - $scope.inventory = $stateParams.inventory_id; - Rest.setUrl(GetBasePath('inventory') + $stateParams.inventory_id + '/'); - Rest.get() - .success(function (data) { - $scope.inventory_name = data.name; - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, form, { hdr: 'Error!', - msg: 'Failed to lookup inventory: ' + data.id + '. GET returned status: ' + status }); - }); - } CreateSelect2({ element:'#job_template_job_type', multiple: false @@ -254,6 +236,17 @@ } }; + if(Inventory){ + $scope.inventory = Inventory.inventory_id; + $scope.inventory_name = Inventory.inventory_name; + } + if(Project){ + $scope.project = Project.id; + $scope.project_name = Project.name; + selectPlaybook('force_load'); + checkSCMStatus(); + } + // Register a watcher on project_name if ($scope.selectPlaybookUnregister) { $scope.selectPlaybookUnregister(); diff --git a/awx/ui/client/src/templates/main.js b/awx/ui/client/src/templates/main.js index c733507f05..717b8ec2c3 100644 --- a/awx/ui/client/src/templates/main.js +++ b/awx/ui/client/src/templates/main.js @@ -52,11 +52,41 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplatesA addJobTemplate = stateDefinitions.generateTree({ name: 'templates.addJobTemplate', - url: '/add_job_template', + url: '/add_job_template?inventory_id&inventory_name&credential_id', modes: ['add'], form: 'JobTemplateForm', controllers: { add: 'JobTemplateAdd' + }, + resolve: { + add: { + Inventory: ['$stateParams', + function($stateParams){ + if($stateParams.inventory_id){ + let obj = {}; + obj.inventory_id = Number($stateParams.inventory_id); + obj.inventory_name = $stateParams.inventory_name; + return obj; + } + }], + Project: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', + function($stateParams, Rest, GetBasePath, ProcessErrors){ + if($stateParams.credential_id){ + let path = `${GetBasePath('projects')}?credential__id=${Number($stateParams.credential_id)}`; + Rest.setUrl(path); + return Rest.get(). + then(function(data){ + return data.data.results[0]; + }).catch(function(response) { + ProcessErrors(null, response.data, response.status, null, { + hdr: 'Error!', + msg: 'Failed to get project info. GET returned status: ' + + response.status + }); + }); + } + }] + } } });