From 18fffdcf1834f6c78b526135c2161b524353e3ae Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Mon, 25 Jan 2016 12:01:32 -0500 Subject: [PATCH] fixed user and team edit/add indicator and auto-pagination --- awx/ui/client/src/controllers/Teams.js | 24 ++++++++++++++++--- awx/ui/client/src/controllers/Users.js | 24 ++++++++++++++++--- .../shared/pagination/pagination.service.js | 2 +- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/awx/ui/client/src/controllers/Teams.js b/awx/ui/client/src/controllers/Teams.js index 2880e0289a..74e19f1b7d 100644 --- a/awx/ui/client/src/controllers/Teams.js +++ b/awx/ui/client/src/controllers/Teams.js @@ -14,7 +14,7 @@ export function TeamsList($scope, $rootScope, $location, $log, $stateParams, Rest, Alert, TeamList, GenerateList, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, SetTeamListeners, GetBasePath, - SelectionInit, Wait, Stream, $state) { + SelectionInit, Wait, Stream, $state, Refresh) { ClearScope(); @@ -25,7 +25,22 @@ export function TeamsList($scope, $rootScope, $location, $log, $stateParams, mode = (paths[0] === 'teams') ? 'edit' : 'select', url; - generator.inject(list, { mode: mode, scope: $scope }); + var injectForm = function() { + generator.inject(list, { mode: mode, scope: $scope }); + }; + + injectForm(); + + $scope.$on("RefreshTeamsList", function() { + injectForm(); + Refresh({ + scope: $scope, + set: 'teams', + iterator: 'team', + url: GetBasePath('teams') + "?order_by=name&page_size=" + $scope.team_page_size + }); + }); + $scope.selected = []; url = GetBasePath('base') + $location.path() + '/'; @@ -111,7 +126,7 @@ TeamsList.$inject = ['$scope', '$rootScope', '$location', '$log', '$stateParams', 'Rest', 'Alert', 'TeamList', 'generateList', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors', 'SetTeamListeners', 'GetBasePath', 'SelectionInit', 'Wait', - 'Stream', '$state' + 'Stream', '$state', 'Refresh' ]; @@ -154,6 +169,7 @@ export function TeamsAdd($scope, $rootScope, $compile, $location, $log, .success(function (data) { Wait('stop'); $rootScope.flashMessage = "New team successfully created!"; + $rootScope.$broadcast("EditIndicatorChange", "users", data.id); $location.path('/teams/' + data.id); }) .error(function (data, status) { @@ -195,6 +211,8 @@ export function TeamsEdit($scope, $rootScope, $compile, $location, $log, $scope.permission_label = {}; $scope.permission_search_select = []; + $scope.$emit("RefreshTeamsList"); + // return a promise from the options request with the permission type choices (including adhoc) as a param var permissionsChoice = fieldChoices({ scope: $scope, diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index b57ec32124..ee5cc02773 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -14,7 +14,7 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams, Rest, Alert, UserList, GenerateList, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, SelectionInit, - Wait, Stream, $state) { + Wait, Stream, $state, Refresh) { ClearScope(); @@ -26,7 +26,21 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams, url = (base === 'organizations') ? GetBasePath('organizations') + $stateParams.organization_id + '/users/' : GetBasePath('teams') + $stateParams.team_id + '/users/'; - generator.inject(UserList, { mode: mode, scope: $scope }); + var injectForm = function() { + generator.inject(UserList, { mode: mode, scope: $scope }); + }; + + injectForm(); + + $scope.$on("RefreshUsersList", function() { + injectForm(); + Refresh({ + scope: $scope, + set: 'users', + iterator: 'user', + url: GetBasePath('users') + "?order_by=username&page_size=" + $scope.user_page_size + }); + }); $scope.selected = []; @@ -101,7 +115,8 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams, UsersList.$inject = ['$scope', '$rootScope', '$location', '$log', '$stateParams', 'Rest', 'Alert', 'UserList', 'generateList', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', - 'ProcessErrors', 'GetBasePath', 'SelectionInit', 'Wait', 'Stream', '$state' + 'ProcessErrors', 'GetBasePath', 'SelectionInit', 'Wait', 'Stream', '$state', + 'Refresh' ]; @@ -173,6 +188,7 @@ export function UsersAdd($scope, $rootScope, $compile, $location, $log, var base = $location.path().replace(/^\//, '').split('/')[0]; if (base === 'users') { $rootScope.flashMessage = 'New user successfully created!'; + $rootScope.$broadcast("EditIndicatorChange", "users", data.id); $location.path('/users/' + data.id); } else { @@ -226,6 +242,8 @@ export function UsersEdit($scope, $rootScope, $compile, $location, $log, $scope.permission_label = {}; $scope.permission_search_select = []; + $scope.$emit("RefreshUsersList"); + // return a promise from the options request with the permission type choices (including adhoc) as a param var permissionsChoice = fieldChoices({ scope: $scope, diff --git a/awx/ui/client/src/shared/pagination/pagination.service.js b/awx/ui/client/src/shared/pagination/pagination.service.js index 76261566d0..673e93432f 100644 --- a/awx/ui/client/src/shared/pagination/pagination.service.js +++ b/awx/ui/client/src/shared/pagination/pagination.service.js @@ -25,7 +25,7 @@ export default ['$http', function($http) { // divide by the page size to get what // page the data should be on var count = data.data.count; - return Math.ceil(count/pageSize); + return Math.ceil(count/parseInt(pageSize)); }); }); }