1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

reduce options reqests and get requests further

This commit is contained in:
John Mitchell 2017-04-25 18:58:12 -04:00
parent 2b57027067
commit 3731c8b72f
6 changed files with 107 additions and 96 deletions

View File

@ -18,17 +18,17 @@ export default ['Rest', 'Wait',
function init() {
// Load the list of options for Kind
$scope.$parent.optionsDefer.promise
.then(function(options) {
GetChoices({
scope: $scope,
url: url,
field: 'kind',
variable: 'credential_kind_options'
variable: 'credential_kind_options',
options: options
});
Rest.setUrl(url);
Rest.options()
.success(function(data) {
if (!data.actions.POST) {
if (!options.actions.POST) {
$state.go("^");
Alert('Permission Error', 'You do not have permission to add a credential type.', 'alert-info');
}

View File

@ -6,14 +6,15 @@
export default ['Rest', 'Wait',
'CredentialTypesForm', 'ProcessErrors', 'GetBasePath',
'GenerateForm', 'credential_typeData',
'GenerateForm', 'resourceData',
'$scope', '$state', 'GetChoices', 'ParseTypeChange', 'ToJSON', 'ParseVariableString', 'CreateSelect2',
function(
Rest, Wait, CredentialTypesForm, ProcessErrors, GetBasePath,
GenerateForm, credential_typeData,
GenerateForm, resourceData,
$scope, $state, GetChoices, ParseTypeChange, ToJSON, ParseVariableString, CreateSelect2
) {
var generator = GenerateForm,
var credential_typeData = resourceData.data,
generator = GenerateForm,
data = credential_typeData,
id = credential_typeData.id,
form = CredentialTypesForm,
@ -24,13 +25,17 @@ export default ['Rest', 'Wait',
function init() {
// Load the list of options for Kind
$scope.$parent.optionsDefer.promise
.then(function(options) {
GetChoices({
scope: $scope,
url: url,
field: 'kind',
variable: 'credential_kind_options',
options: options,
callback: 'choicesReadyCredentialTypes'
});
});
}
if ($scope.removeChoicesReady) {
@ -38,6 +43,7 @@ export default ['Rest', 'Wait',
}
$scope.removeChoicesReady = $scope.$on('choicesReadyCredentialTypes',
function() {
$scope.credential_type = credential_typeData;
$scope.$watch('credential_type.summary_fields.user_capabilities.edit', function(val) {

View File

@ -5,10 +5,10 @@
*************************************************/
export default ['$rootScope', '$scope', 'Wait', 'CredentialTypesList',
'GetBasePath', 'Rest', 'ProcessErrors', 'Prompt', '$state', '$filter', 'Dataset', 'rbacUiControlService', 'Alert',
'GetBasePath', 'Rest', 'ProcessErrors', 'Prompt', '$state', '$filter', 'Dataset', 'rbacUiControlService', 'Alert', '$q',
function(
$rootScope, $scope, Wait, CredentialTypesList,
GetBasePath, Rest, ProcessErrors, Prompt, $state, $filter, Dataset, rbacUiControlService, Alert
GetBasePath, Rest, ProcessErrors, Prompt, $state, $filter, Dataset, rbacUiControlService, Alert, $q
) {
var defaultUrl = GetBasePath('credential_types'),
list = CredentialTypesList;
@ -16,6 +16,8 @@ export default ['$rootScope', '$scope', 'Wait', 'CredentialTypesList',
init();
function init() {
$scope.optionsDefer = $q.defer();
if (!($rootScope.user_is_superuser || $rootScope.user_is_system_auditor)) {
$state.go("setup");
Alert('Permission Error', 'You do not have permission to view, edit or create custom credential types.', 'alert-info');
@ -27,6 +29,7 @@ export default ['$rootScope', '$scope', 'Wait', 'CredentialTypesList',
.then(function(params) {
$scope.canAdd = params.canAdd;
$scope.options = params.options;
$scope.optionsDefer.resolve(params.options);
optionsRequestDataProcessing();
});

View File

@ -36,27 +36,6 @@ angular.module('credentialTypes', [
add: 'CredentialTypesAddController',
edit: 'CredentialTypesEditController'
},
resolve: {
edit: {
credential_typeData: ['$state', '$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors',
function($state, $stateParams, rest, getBasePath, ProcessErrors) {
var credentialTypeId = $stateParams.credential_type_id;
var url = getBasePath('credential_types') + credentialTypeId + '/';
rest.setUrl(url);
return rest.get()
.then(function(data) {
return data.data;
}).catch(function(response) {
ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!',
msg: 'Failed to get credential type info. GET returned status: ' +
response.status
});
});
}
]
}
},
data: {
activityStream: true,
activityStreamTarget: 'custom_inventory_script' // TODO: change to 'credential_type'...there's probably more work that needs to be done to hook up activity stream

View File

@ -17,8 +17,10 @@
return function (params) {
var scope = params.scope,
url = params.url,
field = params.field;
field = params.field,
options = params.options;
if (!options) {
// Auto populate the field if there is only one result
Rest.setUrl(url);
return Rest.options()
@ -39,5 +41,17 @@
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to get ' + field + ' labels. Options requrest returned status: ' + status });
});
} else {
var choices = options.actions.GET[field].choices;
// manually add the adhoc label to the choices object if
// the permission_type field
if (field === "permission_type") {
choices.push(["adhoc",
options.actions.GET.run_ad_hoc_commands.help_text]);
}
return choices;
}
};
}];

View File

@ -720,7 +720,8 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
field = params.field,
variable = params.variable,
callback = params.callback,
choice_name = params.choice_name;
choice_name = params.choice_name,
options = params.options
if (scope[variable]) {
scope[variable].length = 0;
@ -728,13 +729,11 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
scope[variable] = [];
}
Rest.setUrl(url);
Rest.options()
.success(function(data) {
var withOptions = function(options) {
var choices, defaultChoice;
choices = (choice_name) ? data.actions.GET[field][choice_name] : data.actions.GET[field].choices;
if (data && data.actions && data.actions.POST && data.actions.POST[field]) {
defaultChoice = data.actions.POST[field].default;
choices = (choice_name) ? options.actions.GET[field][choice_name] : options.actions.GET[field].choices;
if (options && options.actions && options.actions.POST && options.actions.POST[field]) {
defaultChoice = options.actions.POST[field].default;
}
if (choices) {
// including 'name' property so list can be used by search
@ -757,6 +756,13 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
if (callback) {
scope.$emit(callback);
}
}
if (!options) {
Rest.setUrl(url);
Rest.options()
.success(function(data) {
withOptions(data);
})
.error(function(data, status) {
ProcessErrors(scope, data, status, null, {
@ -764,6 +770,9 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
msg: 'Failed to get ' + url + '. GET status: ' + status
});
});
} else {
withOptions(options);
}
};
}
])