From c67a9031cacd7407c32cd492ddaacf7e3a3a8757 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Thu, 20 Aug 2015 11:37:00 -0400 Subject: [PATCH] revamp services for pulling in the search options --- awx/ui/client/src/controllers/Teams.js | 33 +++++++++++++++---- awx/ui/client/src/controllers/Users.js | 32 ++++++++++++++---- awx/ui/client/src/forms/Teams.js | 11 +------ awx/ui/client/src/forms/Users.js | 11 +------ .../src/permissions/add/add.controller.js | 14 +++++--- .../src/permissions/edit/edit.controller.js | 14 +++++--- .../src/permissions/list/list.controller.js | 30 ++++++++++++++--- .../shared/get-search-select.factory.js | 15 ++++----- .../permissions/shared/permissions.list.js | 11 +------ 9 files changed, 106 insertions(+), 65 deletions(-) diff --git a/awx/ui/client/src/controllers/Teams.js b/awx/ui/client/src/controllers/Teams.js index 910b1bbec2..ab5dc9298f 100644 --- a/awx/ui/client/src/controllers/Teams.js +++ b/awx/ui/client/src/controllers/Teams.js @@ -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, permissionsLabel) { + OrganizationList, Wait, Stream, permissionsChoices, permissionsLabel, permissionsSearchSelect) { ClearScope(); @@ -188,12 +188,22 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP id = $routeParams.team_id, relatedSets = {}; - $scope.permission_label = {}; + $scope.permission_label = {}; + $scope.permission_search_select = []; - permissionsLabel({ + // return a promise from the options request with the permission type choices (including adhoc) as a param + var permissionsChoice = permissionsChoices({ scope: $scope, url: 'api/v1/' + base + '/' + id + '/permissions/' - }).then(function(choices) { + }); + + // 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({ + choices: choices + }); _.map(choices, function(n, key) { $scope.permission_label[key] = n; }); @@ -201,8 +211,17 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeP $scope.team_id = id; - generator.inject(form, { mode: 'edit', related: true, scope: $scope }); - generator.reset(); + // manipulate the choices from the options request to be usable + // by the search option for permission_type, you can't inject the + // list until this is done! + permissionsChoice.then(function (choices) { + form.related.permissions.fields.permission_type.searchOptions = + permissionsSearchSelect({ + choices: choices + }); + generator.inject(form, { mode: 'edit', related: true, scope: $scope }); + generator.reset(); + }); $scope.PermissionAddAllowed = false; @@ -412,5 +431,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', 'permissionsLabel' + 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt', 'GetBasePath', 'CheckAccess', 'OrganizationList', 'Wait', 'Stream', 'permissionsChoices', 'permissionsLabel', 'permissionsSearchSelect' ]; diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index ca0c2141e7..2a37115a16 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -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, permissionsLabel) { + Prompt, CheckAccess, ResetForm, Wait, Stream, permissionsChoices, permissionsLabel, permissionsSearchSelect) { ClearScope(); @@ -221,11 +221,21 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP relatedSets = {}; $scope.permission_label = {}; + $scope.permission_search_select = []; - permissionsLabel({ + // return a promise from the options request with the permission type choices (including adhoc) as a param + var permissionsChoice = permissionsChoices({ scope: $scope, url: 'api/v1/' + base + '/' + id + '/permissions/' - }).then(function(choices) { + }); + + // 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({ + choices: choices + }); _.map(choices, function(n, key) { $scope.permission_label[key] = n; }); @@ -235,9 +245,17 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeP $scope.removeFormReady(); } $scope.removeFormReady = $scope.$on('formReady', function () { - - generator.inject(form, { mode: 'edit', related: true, scope: $scope }); - generator.reset(); + // manipulate the choices from the options request to be usable + // by the search option for permission_type, you can't inject the + // list until this is done! + permissionsChoice.then(function (choices) { + form.related.permissions.fields.permission_type.searchOptions = + permissionsSearchSelect({ + choices: choices + }); + generator.inject(form, { mode: 'edit', related: true, scope: $scope }); + generator.reset(); + }); if ($scope.removePostRefresh) { $scope.removePostRefresh(); @@ -501,5 +519,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', 'permissionsLabel' + 'GetBasePath', 'Prompt', 'CheckAccess', 'ResetForm', 'Wait', 'Stream', 'permissionsChoices', 'permissionsLabel', 'permissionsSearchSelect' ]; diff --git a/awx/ui/client/src/forms/Teams.js b/awx/ui/client/src/forms/Teams.js index 73aa5358c0..195f783ede 100644 --- a/awx/ui/client/src/forms/Teams.js +++ b/awx/ui/client/src/forms/Teams.js @@ -158,16 +158,7 @@ export default permission_type: { label: 'Permission', ngBind: 'getPermissionText()', - searchType: 'select', - searchOptions: [ - { name: "Read Inventory", value: "read" }, - { name: "Edit Inventory", value: "write" }, - { name: "Administrate Inventory", value: "admin" }, - { name: "Deploy to Inventory", value: "run" }, - { name: "Deploy to Inventory (Dry Run)", value: "check" }, - { name: "Scan an Inventory", value: "scan" }, - { name: "Create a Job Template", value: "create" } - ] + searchType: 'select' } }, diff --git a/awx/ui/client/src/forms/Users.js b/awx/ui/client/src/forms/Users.js index 79a58fd0c3..1f2ebef3aa 100644 --- a/awx/ui/client/src/forms/Users.js +++ b/awx/ui/client/src/forms/Users.js @@ -213,16 +213,7 @@ export default permission_type: { label: 'Permission', ngBind: 'getPermissionText()', - searchType: 'select', - searchOptions: [ - { name: "Read Inventory", value: "read" }, - { name: "Edit Inventory", value: "write" }, - { name: "Administrate Inventory", value: "admin" }, - { name: "Deploy to Inventory", value: "run" }, - { name: "Deploy to Inventory (Dry Run)", value: "check" }, - { name: "Scan an Inventory", value: "scan" }, - { name: "Create a Job Template", value: "create" } - ] + searchType: 'select' } }, diff --git a/awx/ui/client/src/permissions/add/add.controller.js b/awx/ui/client/src/permissions/add/add.controller.js index 7bc075357d..0dad88f9db 100644 --- a/awx/ui/client/src/permissions/add/add.controller.js +++ b/awx/ui/client/src/permissions/add/add.controller.js @@ -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', 'permissionsLabel', - function($scope, $rootScope, $compile, $location, $log, $routeParams, permissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath, ReturnToCaller, InventoryList, ProjectList, LookUpInit, CheckAccess, Wait, permissionsCategoryChange, permissionsLabel) { + ['$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) { ClearScope(); @@ -22,10 +22,16 @@ export default base = $location.path().replace(/^\//, '').split('/')[0], master = {}; - permissionsLabel({ + var permissionsChoice = permissionsChoices({ scope: $scope, url: 'api/v1/' + base + '/' + id + '/permissions/' - }).then(function(choices) { + }); + + permissionsChoice.then(function (choices) { + return permissionsLabel({ + choices: choices + }); + }).then(function (choices) { _.map(choices, function(n, key) { $scope.permission_label[key] = n; }); diff --git a/awx/ui/client/src/permissions/edit/edit.controller.js b/awx/ui/client/src/permissions/edit/edit.controller.js index b0a9b0dd08..1b1c6a552b 100644 --- a/awx/ui/client/src/permissions/edit/edit.controller.js +++ b/awx/ui/client/src/permissions/edit/edit.controller.js @@ -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', 'permissionsLabel', - function($scope, $rootScope, $compile, $location, $log, $routeParams, permissionsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, Prompt, GetBasePath, InventoryList, ProjectList, LookUpInit, CheckAccess, Wait, permissionsCategoryChange, permissionsLabel) { + ['$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) { ClearScope(); @@ -25,10 +25,16 @@ export default $scope.permission_label = {}; - permissionsLabel({ + var permissionsChoice = permissionsChoices({ scope: $scope, url: 'api/v1/' + base + '/' + base_id + '/permissions/' - }).then(function(choices) { + }); + + permissionsChoice.then(function (choices) { + return permissionsLabel({ + choices: choices + }); + }).then(function (choices) { _.map(choices, function(n, key) { $scope.permission_label[key] = n; }); diff --git a/awx/ui/client/src/permissions/list/list.controller.js b/awx/ui/client/src/permissions/list/list.controller.js index a3249f18a9..4e9ea4c716 100644 --- a/awx/ui/client/src/permissions/list/list.controller.js +++ b/awx/ui/client/src/permissions/list/list.controller.js @@ -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', 'permissionsLabel', - function ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, permissionsList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, CheckAccess, Wait, permissionsLabel) { + ['$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) { ClearScope(); @@ -24,17 +24,37 @@ export default generator = GenerateList; $scope.permission_label = {}; + $scope.permission_search_select = []; - permissionsLabel({ + // return a promise from the options request with the permission type choices (including adhoc) as a param + var permissionsChoice = permissionsChoices({ scope: $scope, url: 'api/v1/' + base + '/' + base_id + '/permissions/' - }).then(function(choices) { + }); + + // 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({ + choices: choices + }); _.map(choices, function(n, key) { $scope.permission_label[key] = n; }); }); - generator.inject(list, { mode: 'edit', scope: $scope, breadCrumbs: true }); + // manipulate the choices from the options request to be usable + // by the search option for permission_type, you can't inject the + // list until this is done! + permissionsChoice.then(function (choices) { + list.fields.permission_type.searchOptions = + permissionsSearchSelect({ + choices: choices + }); + generator.inject(list, { mode: 'edit', scope: $scope, breadCrumbs: true }); + }); + defaultUrl += ($routeParams.user_id !== undefined) ? $routeParams.user_id : $routeParams.team_id; defaultUrl += '/permissions/'; diff --git a/awx/ui/client/src/permissions/shared/get-search-select.factory.js b/awx/ui/client/src/permissions/shared/get-search-select.factory.js index ca2e459c14..110663cd7b 100644 --- a/awx/ui/client/src/permissions/shared/get-search-select.factory.js +++ b/awx/ui/client/src/permissions/shared/get-search-select.factory.js @@ -17,14 +17,13 @@ return function (params) { // convert the choices from the API from the format // [["read", "Read Inventory"], ...] to - // {name: "read", value: "Read Inventory", ...} - return params.choices.reduce(function(obj, kvp) { - // for now, remove adhoc from those choices - if (kvp[0] !== adhoc) { - return {name: kvp[0], value: kvp[1]}; - } else { - return null; + // [{name: "read", value: "Read Inventory"}, ...] + return params.choices.filter(function (kvp) { + return (kvp[0] !== "adhoc"); + }).map(function (kvp) { + if (kvp[0] !== "adhoc") { + return {name: kvp[1], value: kvp[0]}; } - }, {}); + }); }; }]; diff --git a/awx/ui/client/src/permissions/shared/permissions.list.js b/awx/ui/client/src/permissions/shared/permissions.list.js index cd92a5f0f1..f9c50c7818 100644 --- a/awx/ui/client/src/permissions/shared/permissions.list.js +++ b/awx/ui/client/src/permissions/shared/permissions.list.js @@ -38,16 +38,7 @@ permission_type: { label: 'Permission', ngBind: 'getPermissionText()', - searchType: 'select', - searchOptions: [ - { name: "Read Inventory", value: "read" }, - { name: "Edit Inventory", value: "write" }, - { name: "Administrate Inventory", value: "admin" }, - { name: "Deploy to Inventory", value: "run" }, - { name: "Deploy to Inventory (Dry Run)", value: "check" }, - { name: "Scan an Inventory", value: "scan" }, - { name: "Create a Job Template", value: "create" } - ] + searchType: 'select' } },