mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 08:48:46 -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:
@@ -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,
|
export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm, GenerateForm, Rest, Alert, ProcessErrors,
|
||||||
LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt, GetBasePath, CheckAccess,
|
LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt, GetBasePath, CheckAccess,
|
||||||
OrganizationList, Wait, Stream, permissionsChoices, permissionsLabel, permissionsSearchSelect) {
|
OrganizationList, Wait, Stream, fieldChoices, fieldLabels, permissionsSearchSelect) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -192,16 +192,17 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
$scope.permission_search_select = [];
|
$scope.permission_search_select = [];
|
||||||
|
|
||||||
// return a promise from the options request with the permission type choices (including adhoc) as a param
|
// 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,
|
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
|
// manipulate the choices from the options request to be set on
|
||||||
// scope and be usable by the list form
|
// scope and be usable by the list form
|
||||||
permissionsChoice.then(function (choices) {
|
permissionsChoice.then(function (choices) {
|
||||||
choices =
|
choices =
|
||||||
permissionsLabel({
|
fieldLabels({
|
||||||
choices: choices
|
choices: choices
|
||||||
});
|
});
|
||||||
_.map(choices, function(n, key) {
|
_.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',
|
TeamsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit',
|
'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,
|
export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm, GenerateForm, Rest, Alert,
|
||||||
ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, GetBasePath,
|
ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, GetBasePath,
|
||||||
Prompt, CheckAccess, ResetForm, Wait, Stream, permissionsChoices, permissionsLabel, permissionsSearchSelect) {
|
Prompt, CheckAccess, ResetForm, Wait, Stream, fieldChoices, fieldLabels, permissionsSearchSelect) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -224,16 +224,17 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
$scope.permission_search_select = [];
|
$scope.permission_search_select = [];
|
||||||
|
|
||||||
// return a promise from the options request with the permission type choices (including adhoc) as a param
|
// 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,
|
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
|
// manipulate the choices from the options request to be set on
|
||||||
// scope and be usable by the list form
|
// scope and be usable by the list form
|
||||||
permissionsChoice.then(function (choices) {
|
permissionsChoice.then(function (choices) {
|
||||||
choices =
|
choices =
|
||||||
permissionsLabel({
|
fieldLabels({
|
||||||
choices: choices
|
choices: choices
|
||||||
});
|
});
|
||||||
_.map(choices, function(n, key) {
|
_.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',
|
UsersEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'UserForm', 'GenerateForm',
|
||||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope',
|
'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
|
* @description This controller for permissions add
|
||||||
*/
|
*/
|
||||||
export default
|
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',
|
['$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, permissionsChoices, permissionsLabel) {
|
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();
|
ClearScope();
|
||||||
|
|
||||||
@@ -22,13 +22,14 @@ export default
|
|||||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||||
master = {};
|
master = {};
|
||||||
|
|
||||||
var permissionsChoice = permissionsChoices({
|
var permissionsChoice = fieldChoices({
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
url: 'api/v1/' + base + '/' + id + '/permissions/'
|
url: 'api/v1/' + base + '/' + id + '/permissions/',
|
||||||
|
field: 'permission_type'
|
||||||
});
|
});
|
||||||
|
|
||||||
permissionsChoice.then(function (choices) {
|
permissionsChoice.then(function (choices) {
|
||||||
return permissionsLabel({
|
return fieldLabels({
|
||||||
choices: choices
|
choices: choices
|
||||||
});
|
});
|
||||||
}).then(function (choices) {
|
}).then(function (choices) {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
* @description This controller for permissions edit
|
* @description This controller for permissions edit
|
||||||
*/
|
*/
|
||||||
export default
|
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',
|
['$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, 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, fieldChoices, fieldLabels) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -25,13 +25,14 @@ export default
|
|||||||
|
|
||||||
$scope.permission_label = {};
|
$scope.permission_label = {};
|
||||||
|
|
||||||
var permissionsChoice = permissionsChoices({
|
var permissionsChoice = fieldChoices({
|
||||||
scope: $scope,
|
scope: $scope,
|
||||||
url: 'api/v1/' + base + '/' + base_id + '/permissions/'
|
url: 'api/v1/' + base + '/' + base_id + '/permissions/',
|
||||||
|
field: 'permission_type'
|
||||||
});
|
});
|
||||||
|
|
||||||
permissionsChoice.then(function (choices) {
|
permissionsChoice.then(function (choices) {
|
||||||
return permissionsLabel({
|
return fieldLabels({
|
||||||
choices: choices
|
choices: choices
|
||||||
});
|
});
|
||||||
}).then(function (choices) {
|
}).then(function (choices) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
|
|
||||||
export default
|
export default
|
||||||
['$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, permissionsChoices, permissionsLabel, 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();
|
ClearScope();
|
||||||
|
|
||||||
@@ -27,16 +27,17 @@ export default
|
|||||||
$scope.permission_search_select = [];
|
$scope.permission_search_select = [];
|
||||||
|
|
||||||
// return a promise from the options request with the permission type choices (including adhoc) as a param
|
// 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,
|
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
|
// manipulate the choices from the options request to be set on
|
||||||
// scope and be usable by the list form
|
// scope and be usable by the list form
|
||||||
permissionsChoice.then(function (choices) {
|
permissionsChoice.then(function (choices) {
|
||||||
choices =
|
choices =
|
||||||
permissionsLabel({
|
fieldLabels({
|
||||||
choices: choices
|
choices: choices
|
||||||
});
|
});
|
||||||
_.map(choices, function(n, key) {
|
_.map(choices, function(n, key) {
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import list from './shared/permissions.list';
|
|||||||
import form from './shared/permissions.form';
|
import form from './shared/permissions.form';
|
||||||
|
|
||||||
import permissionsCategoryChange from './shared/category-change.factory';
|
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';
|
import permissionsSearchSelect from './shared/get-search-select.factory';
|
||||||
|
|
||||||
export default
|
export default
|
||||||
@@ -25,6 +23,4 @@ export default
|
|||||||
.factory('permissionsList', list)
|
.factory('permissionsList', list)
|
||||||
.factory('permissionsForm', form)
|
.factory('permissionsForm', form)
|
||||||
.factory('permissionsCategoryChange', permissionsCategoryChange)
|
.factory('permissionsCategoryChange', permissionsCategoryChange)
|
||||||
.factory('permissionsChoices', permissionsChoices)
|
|
||||||
.factory('permissionsLabel', permissionsLabel)
|
|
||||||
.factory('permissionsSearchSelect', permissionsSearchSelect);
|
.factory('permissionsSearchSelect', permissionsSearchSelect);
|
||||||
|
|||||||
@@ -16,24 +16,28 @@
|
|||||||
['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
|
['Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
|
||||||
return function (params) {
|
return function (params) {
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
url = params.url;
|
url = params.url,
|
||||||
|
field = params.field;
|
||||||
|
|
||||||
// Auto populate the field if there is only one result
|
// Auto populate the field if there is only one result
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
return Rest.options()
|
return Rest.options()
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
data = data.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
|
// manually add the adhoc label to the choices object if
|
||||||
|
// the permission_type field
|
||||||
|
if (field === "permission_type") {
|
||||||
choices.push(["adhoc",
|
choices.push(["adhoc",
|
||||||
data.actions.GET.run_ad_hoc_commands.help_text]);
|
data.actions.GET.run_ad_hoc_commands.help_text]);
|
||||||
|
}
|
||||||
|
|
||||||
return choices;
|
return choices;
|
||||||
})
|
})
|
||||||
.catch(function (data, status) {
|
.catch(function (data, status) {
|
||||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
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 restServicesFactory from './restServices.factory';
|
||||||
import interceptors from './interceptors.service';
|
import interceptors from './interceptors.service';
|
||||||
|
import fieldChoices from './get-choices.factory';
|
||||||
|
import fieldLabels from './get-labels.factory';
|
||||||
|
|
||||||
export default
|
export default
|
||||||
angular.module('RestServices', [])
|
angular.module('RestServices', [])
|
||||||
@@ -13,4 +15,6 @@ export default
|
|||||||
$httpProvider.interceptors.push('RestInterceptor');
|
$httpProvider.interceptors.push('RestInterceptor');
|
||||||
}])
|
}])
|
||||||
.factory('Rest', restServicesFactory)
|
.factory('Rest', restServicesFactory)
|
||||||
.service('RestInterceptor', interceptors);
|
.service('RestInterceptor', interceptors)
|
||||||
|
.factory('fieldChoices', fieldChoices)
|
||||||
|
.factory('fieldLabels', fieldLabels);
|
||||||
|
|||||||
Reference in New Issue
Block a user