From 8100fc1cfb2b9d926f24ae7608de76471a4c6e5c Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Mon, 4 Mar 2019 11:27:16 -0500 Subject: [PATCH] Add toolbar sort configuration to project list --- .../features/projects/projects.strings.js | 5 +++ .../projects/projectsList.controller.js | 32 +++++++++++++++++++ .../features/projects/projectsList.view.html | 30 +++++++++-------- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/awx/ui/client/features/projects/projects.strings.js b/awx/ui/client/features/projects/projects.strings.js index c09f3104d9..7512f0f339 100644 --- a/awx/ui/client/features/projects/projects.strings.js +++ b/awx/ui/client/features/projects/projects.strings.js @@ -46,6 +46,11 @@ function ProjectsStrings (BaseString) { HEADER: this.error.HEADER, CALL: this.error.CALL, }; + + ns.sort = { + NAME_ASCENDING: t.s('Name (Ascending)'), + NAME_DESCENDING: t.s('Name (Descending)') + }; } ProjectsStrings.$inject = ['BaseStringService']; diff --git a/awx/ui/client/features/projects/projectsList.controller.js b/awx/ui/client/features/projects/projectsList.controller.js index 59fffee931..690018f3fe 100644 --- a/awx/ui/client/features/projects/projectsList.controller.js +++ b/awx/ui/client/features/projects/projectsList.controller.js @@ -27,6 +27,8 @@ function projectsListController ( }; vm.dataset = Dataset.data; vm.projects = Dataset.data.results; + vm.querySet = $state.params.project_search; + $scope.$watch('vm.dataset.count', () => { $scope.$emit('updateCount', vm.dataset.count, 'projects'); }); @@ -48,6 +50,36 @@ function projectsListController ( } }, true); + const toolbarSortDefault = { + label: `${strings.get('sort.NAME_ASCENDING')}`, + value: 'name' + }; + + vm.toolbarSortOptions = [ + toolbarSortDefault, + { + label: `${strings.get('sort.NAME_DESCENDING')}`, + value: '-name' + } + ]; + + vm.toolbarSortValue = toolbarSortDefault; + + vm.onToolbarSort = (sort) => { + vm.toolbarSortValue = sort; + + const queryParams = Object.assign( + vm.querySet, + { order_by: sort.value } + ); + + qs.search(GetBasePath(vm.list.basePath), queryParams) + .then(({ data }) => { + vm.dataset = data; + vm.projects = vm.dataset.results; + }); + }; + $scope.$on('ws-jobs', (e, data) => { $log.debug(data); if (vm.projects) { diff --git a/awx/ui/client/features/projects/projectsList.view.html b/awx/ui/client/features/projects/projectsList.view.html index 7949234ddc..d3693e2234 100644 --- a/awx/ui/client/features/projects/projectsList.view.html +++ b/awx/ui/client/features/projects/projectsList.view.html @@ -21,10 +21,13 @@ + on-collapse="vm.onCollapse" + is-collapsed="vm.isCollapsed" + sort-only="false" + sort-value="vm.toolbarSortValue" + sort-options="vm.toolbarSortOptions" + on-sort="vm.onToolbarSort"> -
@@ -56,16 +59,16 @@
@@ -77,7 +80,7 @@ - @@ -98,6 +101,7 @@ collection="vm.projects" dataset="vm.dataset" iterator="project" - base-path="projects"> + base-path="projects" + query-set="vm.querySet"> \ No newline at end of file