mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -03:30
Revamp options request helper to work for other choice fields
This moves the get-choices and get-labels services to the rest module The get-choices service is also revamped so that a field name can be passed to check the options request json All uses of get choices were revamped to utilize the new naming convention
This commit is contained in:
parent
152ddc4f4f
commit
8dfc9e482e
@ -176,7 +176,7 @@ TeamsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$r
|
||||
|
||||
export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm, GenerateForm, Rest, Alert, ProcessErrors,
|
||||
LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt, GetBasePath, CheckAccess,
|
||||
OrganizationList, Wait, Stream, permissionsChoices, permissionsLabel, permissionsSearchSelect) {
|
||||
OrganizationList, Wait, Stream, fieldChoices, fieldLabels, permissionsSearchSelect) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
@ -192,16 +192,17 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
$scope.permission_search_select = [];
|
||||
|
||||
// return a promise from the options request with the permission type choices (including adhoc) as a param
|
||||
var permissionsChoice = permissionsChoices({
|
||||
var permissionsChoice = fieldChoices({
|
||||
scope: $scope,
|
||||
url: 'api/v1/' + base + '/' + id + '/permissions/'
|
||||
url: 'api/v1/' + base + '/' + id + '/permissions/',
|
||||
field: 'permission_type'
|
||||
});
|
||||
|
||||
// manipulate the choices from the options request to be set on
|
||||
// scope and be usable by the list form
|
||||
permissionsChoice.then(function (choices) {
|
||||
choices =
|
||||
permissionsLabel({
|
||||
fieldLabels({
|
||||
choices: choices
|
||||
});
|
||||
_.map(choices, function(n, key) {
|
||||
@ -431,5 +432,5 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
|
||||
TeamsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit',
|
||||
'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt', 'GetBasePath', 'CheckAccess', 'OrganizationList', 'Wait', 'Stream', 'permissionsChoices', 'permissionsLabel', 'permissionsSearchSelect'
|
||||
'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt', 'GetBasePath', 'CheckAccess', 'OrganizationList', 'Wait', 'Stream', 'fieldChoices', 'fieldLabels', 'permissionsSearchSelect'
|
||||
];
|
||||
|
||||
@ -208,7 +208,7 @@ UsersAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$r
|
||||
|
||||
export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm, GenerateForm, Rest, Alert,
|
||||
ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, GetBasePath,
|
||||
Prompt, CheckAccess, ResetForm, Wait, Stream, permissionsChoices, permissionsLabel, permissionsSearchSelect) {
|
||||
Prompt, CheckAccess, ResetForm, Wait, Stream, fieldChoices, fieldLabels, permissionsSearchSelect) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
@ -224,16 +224,17 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
$scope.permission_search_select = [];
|
||||
|
||||
// return a promise from the options request with the permission type choices (including adhoc) as a param
|
||||
var permissionsChoice = permissionsChoices({
|
||||
var permissionsChoice = fieldChoices({
|
||||
scope: $scope,
|
||||
url: 'api/v1/' + base + '/' + id + '/permissions/'
|
||||
url: 'api/v1/' + base + '/' + id + '/permissions/',
|
||||
field: 'permission_type'
|
||||
});
|
||||
|
||||
// manipulate the choices from the options request to be set on
|
||||
// scope and be usable by the list form
|
||||
permissionsChoice.then(function (choices) {
|
||||
choices =
|
||||
permissionsLabel({
|
||||
fieldLabels({
|
||||
choices: choices
|
||||
});
|
||||
_.map(choices, function(n, key) {
|
||||
@ -519,5 +520,5 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
|
||||
UsersEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope',
|
||||
'GetBasePath', 'Prompt', 'CheckAccess', 'ResetForm', 'Wait', 'Stream', 'permissionsChoices', 'permissionsLabel', 'permissionsSearchSelect'
|
||||
'GetBasePath', 'Prompt', 'CheckAccess', 'ResetForm', 'Wait', 'Stream', 'fieldChoices', 'fieldLabels', 'permissionsSearchSelect'
|
||||
];
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
* @description This controller for permissions add
|
||||
*/
|
||||
export default
|
||||
['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'permissionsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', 'Wait', 'permissionsCategoryChange', 'permissionsChoices', 'permissionsLabel',
|
||||
function($scope, $rootScope, $compile, $location, $log, $routeParams, permissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath, ReturnToCaller, InventoryList, ProjectList, LookUpInit, CheckAccess, Wait, permissionsCategoryChange, permissionsChoices, permissionsLabel) {
|
||||
['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'permissionsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', 'Wait', 'permissionsCategoryChange', 'fieldChoices', 'fieldLabels',
|
||||
function($scope, $rootScope, $compile, $location, $log, $routeParams, permissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath, ReturnToCaller, InventoryList, ProjectList, LookUpInit, CheckAccess, Wait, permissionsCategoryChange, fieldChoices, fieldLabels) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
@ -22,13 +22,14 @@ export default
|
||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||
master = {};
|
||||
|
||||
var permissionsChoice = permissionsChoices({
|
||||
var permissionsChoice = fieldChoices({
|
||||
scope: $scope,
|
||||
url: 'api/v1/' + base + '/' + id + '/permissions/'
|
||||
url: 'api/v1/' + base + '/' + id + '/permissions/',
|
||||
field: 'permission_type'
|
||||
});
|
||||
|
||||
permissionsChoice.then(function (choices) {
|
||||
return permissionsLabel({
|
||||
return fieldLabels({
|
||||
choices: choices
|
||||
});
|
||||
}).then(function (choices) {
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
* @description This controller for permissions edit
|
||||
*/
|
||||
export default
|
||||
['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'permissionsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'Prompt', 'GetBasePath', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', 'Wait', 'permissionsCategoryChange', 'permissionsChoices', 'permissionsLabel',
|
||||
function($scope, $rootScope, $compile, $location, $log, $routeParams, permissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, Prompt, GetBasePath, InventoryList, ProjectList, LookUpInit, CheckAccess, Wait, permissionsCategoryChange, permissionsChoices, permissionsLabel) {
|
||||
['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'permissionsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'Prompt', 'GetBasePath', 'InventoryList', 'ProjectList', 'LookUpInit', 'CheckAccess', 'Wait', 'permissionsCategoryChange', 'fieldChoices', 'fieldLabels',
|
||||
function($scope, $rootScope, $compile, $location, $log, $routeParams, permissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, Prompt, GetBasePath, InventoryList, ProjectList, LookUpInit, CheckAccess, Wait, permissionsCategoryChange, fieldChoices, fieldLabels) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
@ -25,13 +25,14 @@ export default
|
||||
|
||||
$scope.permission_label = {};
|
||||
|
||||
var permissionsChoice = permissionsChoices({
|
||||
var permissionsChoice = fieldChoices({
|
||||
scope: $scope,
|
||||
url: 'api/v1/' + base + '/' + base_id + '/permissions/'
|
||||
url: 'api/v1/' + base + '/' + base_id + '/permissions/',
|
||||
field: 'permission_type'
|
||||
});
|
||||
|
||||
permissionsChoice.then(function (choices) {
|
||||
return permissionsLabel({
|
||||
return fieldLabels({
|
||||
choices: choices
|
||||
});
|
||||
}).then(function (choices) {
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
|
||||
|
||||
export default
|
||||
['$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'permissionsList', 'generateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors', 'GetBasePath', 'CheckAccess', 'Wait', 'permissionsChoices', 'permissionsLabel', 'permissionsSearchSelect',
|
||||
function ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, permissionsList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, CheckAccess, Wait, permissionsChoices, permissionsLabel, permissionsSearchSelect) {
|
||||
['$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'permissionsList', 'generateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors', 'GetBasePath', 'CheckAccess', 'Wait', 'fieldChoices', 'fieldLabels', 'permissionsSearchSelect',
|
||||
function ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, permissionsList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, CheckAccess, Wait, fieldChoices, fieldLabels, permissionsSearchSelect) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
@ -27,16 +27,17 @@ export default
|
||||
$scope.permission_search_select = [];
|
||||
|
||||
// return a promise from the options request with the permission type choices (including adhoc) as a param
|
||||
var permissionsChoice = permissionsChoices({
|
||||
var permissionsChoice = fieldChoices({
|
||||
scope: $scope,
|
||||
url: 'api/v1/' + base + '/' + base_id + '/permissions/'
|
||||
url: 'api/v1/' + base + '/' + base_id + '/permissions/',
|
||||
field: 'permission_type'
|
||||
});
|
||||
|
||||
// manipulate the choices from the options request to be set on
|
||||
// scope and be usable by the list form
|
||||
permissionsChoice.then(function (choices) {
|
||||
choices =
|
||||
permissionsLabel({
|
||||
fieldLabels({
|
||||
choices: choices
|
||||
});
|
||||
_.map(choices, function(n, key) {
|
||||
|
||||
@ -12,8 +12,6 @@ import list from './shared/permissions.list';
|
||||
import form from './shared/permissions.form';
|
||||
|
||||
import permissionsCategoryChange from './shared/category-change.factory';
|
||||
import permissionsChoices from './shared/get-choices.factory';
|
||||
import permissionsLabel from './shared/get-labels.factory';
|
||||
import permissionsSearchSelect from './shared/get-search-select.factory';
|
||||
|
||||
export default
|
||||
@ -25,6 +23,4 @@ export default
|
||||
.factory('permissionsList', list)
|
||||
.factory('permissionsForm', form)
|
||||
.factory('permissionsCategoryChange', permissionsCategoryChange)
|
||||
.factory('permissionsChoices', permissionsChoices)
|
||||
.factory('permissionsLabel', permissionsLabel)
|
||||
.factory('permissionsSearchSelect', permissionsSearchSelect);
|
||||
|
||||
@ -16,24 +16,28 @@
|
||||
['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
|
||||
return function (params) {
|
||||
var scope = params.scope,
|
||||
url = params.url;
|
||||
url = params.url,
|
||||
field = params.field;
|
||||
|
||||
// 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.permission_type.choices;
|
||||
var choices = data.actions.GET[field].choices;
|
||||
|
||||
// manually add the adhoc label to the choices object
|
||||
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 permission type labels. Options requrest returned status: ' + status });
|
||||
msg: 'Failed to get ' + field + ' labels. Options requrest returned status: ' + status });
|
||||
});
|
||||
};
|
||||
}];
|
||||
@ -6,6 +6,8 @@
|
||||
|
||||
import restServicesFactory from './restServices.factory';
|
||||
import interceptors from './interceptors.service';
|
||||
import fieldChoices from './get-choices.factory';
|
||||
import fieldLabels from './get-labels.factory';
|
||||
|
||||
export default
|
||||
angular.module('RestServices', [])
|
||||
@ -13,4 +15,6 @@ export default
|
||||
$httpProvider.interceptors.push('RestInterceptor');
|
||||
}])
|
||||
.factory('Rest', restServicesFactory)
|
||||
.service('RestInterceptor', interceptors);
|
||||
.service('RestInterceptor', interceptors)
|
||||
.factory('fieldChoices', fieldChoices)
|
||||
.factory('fieldLabels', fieldLabels);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user