Pre-populate organization galaxy credential field with the default galaxy credential

This commit is contained in:
mabashian 2020-08-05 16:06:33 -04:00 committed by Ryan Petrello
parent a30ca9c19c
commit 895010c675
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
3 changed files with 37 additions and 13 deletions

View File

@ -6,10 +6,10 @@
export default ['$scope', '$rootScope', '$location', '$stateParams', 'OrganizationForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'GetBasePath', 'Wait', 'CreateSelect2',
'$state','InstanceGroupsService', 'ConfigData', 'MultiCredentialService',
'$state','InstanceGroupsService', 'ConfigData', 'MultiCredentialService', 'defaultGalaxyCredential',
function($scope, $rootScope, $location, $stateParams, OrganizationForm,
GenerateForm, Rest, Alert, ProcessErrors, GetBasePath, Wait, CreateSelect2,
$state, InstanceGroupsService, ConfigData, MultiCredentialService) {
$state, InstanceGroupsService, ConfigData, MultiCredentialService, defaultGalaxyCredential) {
Rest.setUrl(GetBasePath('organizations'));
Rest.options()
@ -38,6 +38,8 @@ export default ['$scope', '$rootScope', '$location', '$stateParams', 'Organizati
// apply form definition's default field values
GenerateForm.applyDefaults(form, $scope);
$scope.credentials = defaultGalaxyCredential || [];
}
// Save

View File

@ -49,7 +49,7 @@ export default ['templateUrl', '$window', function(templateUrl, $window) {
credentialList.well = false;
credentialList.multiSelect = true;
credentialList.multiSelectPreview = {
selectedRows: 'igTags',
selectedRows: 'credTags',
availableRows: 'credentials'
};
credentialList.fields.name.ngClick = "linkoutCredential(credential)";
@ -70,10 +70,10 @@ export default ['templateUrl', '$window', function(templateUrl, $window) {
if ($scope.galaxyCredentials) {
$scope.galaxyCredentials = $scope.galaxyCredentials.map( (item) => {
item.isSelected = true;
if (!$scope.igTags) {
$scope.igTags = [];
if (!$scope.credTags) {
$scope.credTags = [];
}
$scope.igTags.push(item);
$scope.credTags.push(item);
return item;
});
}
@ -83,7 +83,7 @@ export default ['templateUrl', '$window', function(templateUrl, $window) {
$scope.$watch('credentials', function(){
angular.forEach($scope.credentials, function(credentialRow) {
angular.forEach($scope.igTags, function(selectedCredential){
angular.forEach($scope.credTags, function(selectedCredential){
if(selectedCredential.id === credentialRow.id) {
credentialRow.isSelected = true;
}
@ -97,12 +97,12 @@ export default ['templateUrl', '$window', function(templateUrl, $window) {
$scope.$on("selectedOrDeselected", function(e, value) {
let item = value.value;
if (value.isSelected) {
if(!$scope.igTags) {
$scope.igTags = [];
if(!$scope.credTags) {
$scope.credTags = [];
}
$scope.igTags.push(item);
$scope.credTags.push(item);
} else {
_.remove($scope.igTags, { id: item.id });
_.remove($scope.credTags, { id: item.id });
}
});
@ -115,7 +115,7 @@ export default ['templateUrl', '$window', function(templateUrl, $window) {
};
$scope.saveForm = function() {
$scope.galaxyCredentials = $scope.igTags;
$scope.galaxyCredentials = $scope.credTags;
$scope.destroyModal();
};
}]

View File

@ -71,7 +71,29 @@ angular.module('Organizations', [
});
});
}]
}],
defaultGalaxyCredential: ['Rest', 'GetBasePath', 'ProcessErrors',
function(Rest, GetBasePath, ProcessErrors){
Rest.setUrl(GetBasePath('credentials'));
return Rest.get({
params: {
credential_type__kind: 'galaxy',
managed_by_tower: true
}
})
.then(({data}) => {
if (data.results.length > 0) {
return data.results;
}
})
.catch(({data, status}) => {
ProcessErrors(null, data, status, null, {
hdr: 'Error!',
msg: 'Failed to get default Galaxy credential. GET returned ' +
'status: ' + status
});
});
}],
},
edit: {
ConfigData: ['ConfigService', 'ProcessErrors', (ConfigService, ProcessErrors) => {