diff --git a/awx/ui/client/features/applications/index.js b/awx/ui/client/features/applications/index.js index 5465547409..9c12d2a3a2 100644 --- a/awx/ui/client/features/applications/index.js +++ b/awx/ui/client/features/applications/index.js @@ -91,15 +91,15 @@ function ApplicationsRun ($stateExtender, strings) { controllerAs: 'vm' } }, + searchPrefix: 'application', params: { application_search: { value: { - order_by: 'name', - page_size: 10 - }, + page_size: 10, + order_by: 'name' + } } }, - searchPrefix: 'application', resolve: { resolvedModels: [ 'ApplicationModel', diff --git a/awx/ui/client/features/users/tokens/tokens.strings.js b/awx/ui/client/features/users/tokens/tokens.strings.js index 2f84642eae..13487e9ede 100644 --- a/awx/ui/client/features/users/tokens/tokens.strings.js +++ b/awx/ui/client/features/users/tokens/tokens.strings.js @@ -41,6 +41,11 @@ function TokensStrings (BaseString) { PERSONAL_ACCESS_TOKEN: t.s('Personal Access Token'), HEADER: appName => t.s('{{ appName }} Token', { appName }), }; + + ns.sort = { + NAME_ASCENDING: t.s('Name (Ascending)'), + NAME_DESCENDING: t.s('Name (Descending)') + }; } TokensStrings.$inject = ['BaseStringService']; diff --git a/awx/ui/client/features/users/tokens/users-tokens-list.controller.js b/awx/ui/client/features/users/tokens/users-tokens-list.controller.js index 4dde61c441..aedac69bcb 100644 --- a/awx/ui/client/features/users/tokens/users-tokens-list.controller.js +++ b/awx/ui/client/features/users/tokens/users-tokens-list.controller.js @@ -16,7 +16,6 @@ function ListTokensController ( models ) { const vm = this || {}; - const { token } = models; vm.strings = strings; @@ -27,19 +26,61 @@ function ListTokensController ( // smart-search const name = 'tokens'; const iterator = 'token'; - const key = 'token_dataset'; + let paginateQuerySet = {}; - $scope.list = { iterator, name, basePath: 'tokens' }; - $scope.collection = { iterator }; - $scope[key] = Dataset.data; - vm.tokensCount = Dataset.data.count; - $scope[name] = Dataset.data.results; - $scope.$on('updateDataset', (e, dataset) => { - $scope[key] = dataset; - $scope[name] = dataset.results; - vm.tokensCount = dataset.count; + vm.token_dataset = Dataset.data; + vm.tokens = Dataset.data.results; + vm.list = { iterator, name, basePath: 'tokens' }; + vm.basePath = `${GetBasePath('users')}${$state.params.user_id}/tokens`; + + $scope.$on('updateDataset', (e, dataset, queryset) => { + vm.token_dataset = dataset; + vm.tokens = dataset.results; + paginateQuerySet = queryset; }); + $scope.$watchCollection('$state.params', () => { + setToolbarSort(); + }); + + const toolbarSortDefault = { + label: `${strings.get('sort.NAME_ASCENDING')}`, + value: 'application__name' + }; + + vm.toolbarSortOptions = [ + toolbarSortDefault, + { + label: `${strings.get('sort.NAME_DESCENDING')}`, + value: '-application__name' + } + ]; + + function setToolbarSort () { + const orderByValue = _.get($state.params, 'token_search.order_by'); + const sortValue = _.find(vm.toolbarSortOptions, (option) => option.value === orderByValue); + if (sortValue) { + vm.toolbarSortValue = sortValue; + } else { + vm.toolbarSortValue = toolbarSortDefault; + } + } + + vm.onToolbarSort = (sort) => { + vm.toolbarSortValue = sort; + const queryParams = Object.assign( + {}, + $state.params.token_search, + paginateQuerySet, + { order_by: sort.value } + ); + + // Update URL with params + $state.go('.', { + token_search: queryParams + }, { notify: false, location: 'replace' }); + }; + vm.getScopeString = str => { if (str === 'Read') { return vm.strings.get('add.SCOPE_READ_LABEL'); diff --git a/awx/ui/client/features/users/tokens/users-tokens-list.partial.html b/awx/ui/client/features/users/tokens/users-tokens-list.partial.html index 336fb70557..3b15855bd7 100644 --- a/awx/ui/client/features/users/tokens/users-tokens-list.partial.html +++ b/awx/ui/client/features/users/tokens/users-tokens-list.partial.html @@ -2,11 +2,11 @@
@@ -20,9 +20,15 @@
- - - + + + +
+ base-path="{{ vm.basePath }}"> \ No newline at end of file diff --git a/awx/ui/client/features/users/tokens/users-tokens-list.route.js b/awx/ui/client/features/users/tokens/users-tokens-list.route.js index d6473c646d..e370f6fb24 100644 --- a/awx/ui/client/features/users/tokens/users-tokens-list.route.js +++ b/awx/ui/client/features/users/tokens/users-tokens-list.route.js @@ -39,8 +39,8 @@ export default { params: { token_search: { value: { - page_size: 5, - order_by: 'application' + page_size: 10, + order_by: 'application__name' } } },