Insights Cred on Project form, for insights project

This commit is contained in:
Jared Tabor
2017-06-02 10:38:53 -07:00
parent bf52141f4f
commit 38ce6c7226
9 changed files with 99 additions and 32 deletions

View File

@@ -4,8 +4,8 @@
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
export default [ 'InsightsData', '$scope', 'moment', '$state', export default [ 'InsightsData', '$scope', 'moment', '$state', 'resourceData',
function (data, $scope, moment, $state) { function (data, $scope, moment, $state, resourceData) {
function init() { 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; $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); let a = moment(), b = moment($scope.reports_dataset.last_check_in);
$scope.last_check_in = a.diff(b, 'hours'); $scope.last_check_in = a.diff(b, 'hours');
$scope.inventory = resourceData.data;
$scope.insights_credential = resourceData.data.summary_fields.insights_credential.id;
} }
init(); init();
@@ -75,8 +77,8 @@ function (data, $scope, moment, $state) {
$scope.viewDataInInsights = function(){ $scope.viewDataInInsights = function(){
window.open(`https://access.redhat.com/insights/inventory?machine=${$scope.$parent.host.insights_system_id}`, '_blank'); window.open(`https://access.redhat.com/insights/inventory?machine=${$scope.$parent.host.insights_system_id}`, '_blank');
}; };
$scope.remediateInventory = function(){ $scope.remediateInventory = function(inv_id, inv_name, insights_credential){
$state.go('templates.addJobTemplate'); $state.go('templates.addJobTemplate', {inventory_id: inv_id, inventory_name:inv_name, credential_id: insights_credential});
}; };
$scope.formCancel = function(){ $scope.formCancel = function(){
$state.go('inventories', null, {reload: true}); $state.go('inventories', null, {reload: true});

View File

@@ -76,6 +76,6 @@
<div class="buttons Form-buttons"> <div class="buttons Form-buttons">
<button type="button" class="btn btn-sm Form-primaryButton" ng-click="viewDataInInsights()"> <i class="fa fa-sign-out"></i> VIEW DATA IN INSIGHTS</button> <button type="button" class="btn btn-sm Form-primaryButton" ng-click="viewDataInInsights()"> <i class="fa fa-sign-out"></i> VIEW DATA IN INSIGHTS</button>
<button type="button" class="btn btn-sm Form-primaryButton" ng-click="remediateInventory()"> REMEDIATE INVENTORY</button> <button type="button" class="btn btn-sm Form-primaryButton" ng-click="remediateInventory(inventory.id, inventory.name, insights_credential)"> REMEDIATE INVENTORY</button>
<button type="button" class="btn btn-sm Form-cancelButton" ng-click="formCancel()"> Close</button> <button type="button" class="btn btn-sm Form-cancelButton" ng-click="formCancel()"> Close</button>
</div> </div>

View File

@@ -91,8 +91,8 @@ function InventoriesEdit($scope, $location,
$state.go('inventories'); $state.go('inventories');
}; };
$scope.remediateInventory = function(){ $scope.remediateInventory = function(inv_id, inv_name, insights_credential){
$state.go('templates.addJobTemplate'); $state.go('templates.addJobTemplate', {inventory_id: inv_id, inventory_name:inv_name, credential_id: insights_credential});
}; };
} }

View File

@@ -191,7 +191,7 @@ function(i18n, InventoryCompletedJobsList) {
}, },
relatedButtons: { relatedButtons: {
remediate_inventory: { remediate_inventory: {
ngClick: 'remediateInventory()', ngClick: 'remediateInventory(id, name, insights_credential)',
ngShow: 'insights_credential!==null', ngShow: 'insights_credential!==null',
label: i18n._('Remediate Inventory'), label: i18n._('Remediate Inventory'),
class: 'Form-primaryButton' class: 'Form-primaryButton'

View File

@@ -121,6 +121,7 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
if ($scope.scm_type.value) { if ($scope.scm_type.value) {
switch ($scope.scm_type.value) { switch ($scope.scm_type.value) {
case 'git': case 'git':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + $scope.urlPopover = '<p>' +
i18n._('Example URLs for GIT SCM include:') + i18n._('Example URLs for GIT SCM include:') +
'</p><ul class=\"no-bullets\"><li>https://github.com/ansible/ansible.git</li>' + '</p><ul class=\"no-bullets\"><li>https://github.com/ansible/ansible.git</li>' +
@@ -130,11 +131,13 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
'SSH. GIT read only protocol (git://) does not use username or password information.'), '<strong>', '</strong>'); 'SSH. GIT read only protocol (git://) does not use username or password information.'), '<strong>', '</strong>');
break; break;
case 'svn': case 'svn':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for Subversion SCM include:') + '</p>' + $scope.urlPopover = '<p>' + i18n._('Example URLs for Subversion SCM include:') + '</p>' +
'<ul class=\"no-bullets\"><li>https://github.com/ansible/ansible</li><li>svn://servername.example.com/path</li>' + '<ul class=\"no-bullets\"><li>https://github.com/ansible/ansible</li><li>svn://servername.example.com/path</li>' +
'<li>svn+ssh://servername.example.com/path</li></ul>'; '<li>svn+ssh://servername.example.com/path</li></ul>';
break; break;
case 'hg': case 'hg':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for Mercurial SCM include:') + '</p>' + $scope.urlPopover = '<p>' + i18n._('Example URLs for Mercurial SCM include:') + '</p>' +
'<ul class=\"no-bullets\"><li>https://bitbucket.org/username/project</li><li>ssh://hg@bitbucket.org/username/project</li>' + '<ul class=\"no-bullets\"><li>https://bitbucket.org/username/project</li><li>ssh://hg@bitbucket.org/username/project</li>' +
'<li>ssh://server.example.com/path</li></ul>' + '<li>ssh://server.example.com/path</li></ul>' +
@@ -142,7 +145,14 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
'Do not put the username and key in the URL. ' + 'Do not put the username and key in the URL. ' +
'If using Bitbucket and SSH, do not supply your Bitbucket username.'), '<strong>', '</strong>'); 'If using Bitbucket and SSH, do not supply your Bitbucket username.'), '<strong>', '</strong>');
break; break;
case 'insights':
$scope.pathRequired = false;
$scope.scmRequired = false;
$scope.credRequired = true;
$scope.credentialLabel = "Credential";
break;
default: default:
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p> ' + i18n._('URL popover text'); $scope.urlPopover = '<p> ' + i18n._('URL popover text');
} }
} }
@@ -151,5 +161,15 @@ export default ['$scope', '$location', '$stateParams', 'GenerateForm',
$scope.formCancel = function() { $scope.formCancel = function() {
$state.go('projects'); $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'
}
});
};
} }
]; ];

View File

@@ -254,6 +254,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
if ($scope.scm_type.value) { if ($scope.scm_type.value) {
switch ($scope.scm_type.value) { switch ($scope.scm_type.value) {
case 'git': case 'git':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for GIT SCM include:') + '</p><ul class=\"no-bullets\"><li>https://github.com/ansible/ansible.git</li>' + $scope.urlPopover = '<p>' + i18n._('Example URLs for GIT SCM include:') + '</p><ul class=\"no-bullets\"><li>https://github.com/ansible/ansible.git</li>' +
'<li>git@github.com:ansible/ansible.git</li><li>git://servername.example.com/ansible.git</li></ul>' + '<li>git@github.com:ansible/ansible.git</li><li>git://servername.example.com/ansible.git</li></ul>' +
'<p>' + i18n.sprintf(i18n._('%sNote:%s When using SSH protocol for GitHub or Bitbucket, enter an SSH key only, ' + '<p>' + 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.'), '<strong>', '</strong>'); 'SSH. GIT read only protocol (git://) does not use username or password information.'), '<strong>', '</strong>');
break; break;
case 'svn': case 'svn':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for Subversion SCM include:') + '</p>' + $scope.urlPopover = '<p>' + i18n._('Example URLs for Subversion SCM include:') + '</p>' +
'<ul class=\"no-bullets\"><li>https://github.com/ansible/ansible</li><li>svn://servername.example.com/path</li>' + '<ul class=\"no-bullets\"><li>https://github.com/ansible/ansible</li><li>svn://servername.example.com/path</li>' +
'<li>svn+ssh://servername.example.com/path</li></ul>'; '<li>svn+ssh://servername.example.com/path</li></ul>';
break; break;
case 'hg': case 'hg':
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p>' + i18n._('Example URLs for Mercurial SCM include:') + '</p>' + $scope.urlPopover = '<p>' + i18n._('Example URLs for Mercurial SCM include:') + '</p>' +
'<ul class=\"no-bullets\"><li>https://bitbucket.org/username/project</li><li>ssh://hg@bitbucket.org/username/project</li>' + '<ul class=\"no-bullets\"><li>https://bitbucket.org/username/project</li><li>ssh://hg@bitbucket.org/username/project</li>' +
'<li>ssh://server.example.com/path</li></ul>' + '<li>ssh://server.example.com/path</li></ul>' +
@@ -273,12 +276,30 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
'Do not put the username and key in the URL. ' + 'Do not put the username and key in the URL. ' +
'If using Bitbucket and SSH, do not supply your Bitbucket username.'), '<strong>', '</strong>'); 'If using Bitbucket and SSH, do not supply your Bitbucket username.'), '<strong>', '</strong>');
break; break;
case 'insights':
$scope.pathRequired = false;
$scope.scmRequired = false;
$scope.credRequired = true;
$scope.credentialLabel = "Credential";
break;
default: default:
$scope.credentialLabel = "SCM Credential";
$scope.urlPopover = '<p> ' + i18n._('URL popover text'); $scope.urlPopover = '<p> ' + 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() { $scope.SCMUpdate = function() {
if ($scope.project_obj.scm_type === "Manual" || Empty($scope.project_obj.scm_type)) { if ($scope.project_obj.scm_type === "Manual" || Empty($scope.project_obj.scm_type)) {
// ignore // ignore

View File

@@ -131,9 +131,10 @@ export default ['i18n', 'NotificationsList', function(i18n, NotificationsList) {
basePath: 'credentials', basePath: 'credentials',
list: 'CredentialList', list: 'CredentialList',
// apply a default search filter to show only scm credentials // apply a default search filter to show only scm credentials
search: { // search: {
kind: 'scm' // kind: 'scm'
}, // },
ngClick: 'lookupCredential()',
autopopulateLookup: false, autopopulateLookup: false,
awRequiredWhen: { awRequiredWhen: {
reqExpression: "credRequired", reqExpression: "credRequired",

View File

@@ -9,13 +9,13 @@
'$stateParams', 'JobTemplateForm', 'GenerateForm', 'Rest', 'Alert', '$stateParams', 'JobTemplateForm', 'GenerateForm', 'Rest', 'Alert',
'ProcessErrors', 'ClearScope', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'Wait', 'ProcessErrors', 'ClearScope', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'Wait',
'Empty', 'ToJSON', 'CallbackHelpInit', 'GetChoices', '$state', 'Empty', 'ToJSON', 'CallbackHelpInit', 'GetChoices', '$state',
'CreateSelect2', '$q', 'i18n', 'CreateSelect2', '$q', 'i18n', 'Inventory', 'Project',
function( function(
$filter, $scope, $filter, $scope,
$stateParams, JobTemplateForm, GenerateForm, Rest, Alert, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert,
ProcessErrors, ClearScope, GetBasePath, md5Setup, ParseTypeChange, Wait, ProcessErrors, ClearScope, GetBasePath, md5Setup, ParseTypeChange, Wait,
Empty, ToJSON, CallbackHelpInit, GetChoices, Empty, ToJSON, CallbackHelpInit, GetChoices,
$state, CreateSelect2, $q, i18n $state, CreateSelect2, $q, i18n, Inventory, Project
) { ) {
Rest.setUrl(GetBasePath('job_templates')); Rest.setUrl(GetBasePath('job_templates'));
@@ -80,24 +80,6 @@
} }
$scope.job_type = $scope.job_type_options[form.fields.job_type.default]; $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({ CreateSelect2({
element:'#job_template_job_type', element:'#job_template_job_type',
multiple: false 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 // Register a watcher on project_name
if ($scope.selectPlaybookUnregister) { if ($scope.selectPlaybookUnregister) {
$scope.selectPlaybookUnregister(); $scope.selectPlaybookUnregister();

View File

@@ -52,11 +52,41 @@ angular.module('templates', [surveyMaker.name, templatesList.name, jobTemplatesA
addJobTemplate = stateDefinitions.generateTree({ addJobTemplate = stateDefinitions.generateTree({
name: 'templates.addJobTemplate', name: 'templates.addJobTemplate',
url: '/add_job_template', url: '/add_job_template?inventory_id&inventory_name&credential_id',
modes: ['add'], modes: ['add'],
form: 'JobTemplateForm', form: 'JobTemplateForm',
controllers: { controllers: {
add: 'JobTemplateAdd' 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
});
});
}
}]
}
} }
}); });