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:
parent
2b57027067
commit
3731c8b72f
@ -18,17 +18,17 @@ export default ['Rest', 'Wait',
|
||||
|
||||
function init() {
|
||||
// Load the list of options for Kind
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
url: url,
|
||||
field: 'kind',
|
||||
variable: 'credential_kind_options'
|
||||
});
|
||||
$scope.$parent.optionsDefer.promise
|
||||
.then(function(options) {
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
url: url,
|
||||
field: 'kind',
|
||||
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');
|
||||
}
|
||||
|
@ -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
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
url: url,
|
||||
field: 'kind',
|
||||
variable: 'credential_kind_options',
|
||||
callback: 'choicesReadyCredentialTypes'
|
||||
});
|
||||
$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) {
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
|
@ -17,27 +17,41 @@
|
||||
return function (params) {
|
||||
var scope = params.scope,
|
||||
url = params.url,
|
||||
field = params.field;
|
||||
field = params.field,
|
||||
options = params.options;
|
||||
|
||||
// Auto populate the field if there is only one result
|
||||
Rest.setUrl(url);
|
||||
return Rest.options()
|
||||
.then(function (data) {
|
||||
data = data.data;
|
||||
var choices = data.actions.GET[field].choices;
|
||||
if (!options) {
|
||||
// Auto populate the field if there is only one result
|
||||
Rest.setUrl(url);
|
||||
return Rest.options()
|
||||
.then(function (data) {
|
||||
data = data.data;
|
||||
var choices = data.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",
|
||||
data.actions.GET.run_ad_hoc_commands.help_text]);
|
||||
}
|
||||
// manually add the adhoc label to the choices object if
|
||||
// the permission_type field
|
||||
if (field === "permission_type") {
|
||||
choices.push(["adhoc",
|
||||
data.actions.GET.run_ad_hoc_commands.help_text]);
|
||||
}
|
||||
|
||||
return choices;
|
||||
})
|
||||
.catch(function (data, status) {
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
||||
msg: 'Failed to get ' + field + ' labels. Options requrest returned status: ' + status });
|
||||
});
|
||||
return choices;
|
||||
})
|
||||
.catch(function (data, status) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
}];
|
||||
|
@ -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,42 +729,50 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
||||
scope[variable] = [];
|
||||
}
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.options()
|
||||
.success(function(data) {
|
||||
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;
|
||||
}
|
||||
if (choices) {
|
||||
// including 'name' property so list can be used by search
|
||||
choices.forEach(function(choice) {
|
||||
scope[variable].push({
|
||||
label: choice[1],
|
||||
value: choice[0],
|
||||
name: choice[1]
|
||||
});
|
||||
var withOptions = function(options) {
|
||||
var choices, defaultChoice;
|
||||
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
|
||||
choices.forEach(function(choice) {
|
||||
scope[variable].push({
|
||||
label: choice[1],
|
||||
value: choice[0],
|
||||
name: choice[1]
|
||||
});
|
||||
}
|
||||
if (defaultChoice !== undefined) {
|
||||
var val;
|
||||
for (val in scope[variable]) {
|
||||
if (scope[variable][val].value === defaultChoice) {
|
||||
scope[variable][val].isDefault = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (defaultChoice !== undefined) {
|
||||
var val;
|
||||
for (val in scope[variable]) {
|
||||
if (scope[variable][val].value === defaultChoice) {
|
||||
scope[variable][val].isDefault = true;
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
scope.$emit(callback);
|
||||
}
|
||||
})
|
||||
.error(function(data, status) {
|
||||
ProcessErrors(scope, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: 'Failed to get ' + url + '. GET status: ' + status
|
||||
});
|
||||
});
|
||||
}
|
||||
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, {
|
||||
hdr: 'Error!',
|
||||
msg: 'Failed to get ' + url + '. GET status: ' + status
|
||||
});
|
||||
});
|
||||
} else {
|
||||
withOptions(options);
|
||||
}
|
||||
};
|
||||
}
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user