diff --git a/awx/ui/client/features/templates/routes/organizationsTemplatesList.route.js b/awx/ui/client/features/templates/routes/organizationsTemplatesList.route.js index 2232f22c9a..c0c7c3fdb7 100644 --- a/awx/ui/client/features/templates/routes/organizationsTemplatesList.route.js +++ b/awx/ui/client/features/templates/routes/organizationsTemplatesList.route.js @@ -21,7 +21,11 @@ export default { template_search: { dynamic: true, value: { - type: 'workflow_job_template,job_template', + type: 'job_template', + order_by: 'name', + page_size: '20', + or__jobtemplate__project__organization: null, + or__jobtemplate__inventory__organization: null }, } }, @@ -60,11 +64,11 @@ export default { ($stateParams, Wait, GetBasePath, qs) => { const searchPath = GetBasePath('unified_job_templates'); - const searchParam = _.assign($stateParams.template_search, { - or__project__organization: $stateParams.organization_id, - or__jobtemplate__inventory__organization: $stateParams.organization_id, - }); - + const searchParam = Object.assign( + $stateParams.template_search, { + or__jobtemplate__project__organization: $stateParams.organization_id, + or__jobtemplate__inventory__organization: $stateParams.organization_id} + ); Wait('start'); return qs.search(searchPath, searchParam) .finally(() => Wait('stop')); diff --git a/awx/ui/client/features/templates/routes/projectsTemplatesList.route.js b/awx/ui/client/features/templates/routes/projectsTemplatesList.route.js index f19a426a4b..be10a69b0d 100644 --- a/awx/ui/client/features/templates/routes/projectsTemplatesList.route.js +++ b/awx/ui/client/features/templates/routes/projectsTemplatesList.route.js @@ -6,11 +6,15 @@ const templatesListTemplate = require('~features/templates/templatesList.view.ht export default { url: "/templates", name: 'projects.edit.templates', + searchPrefix: 'template', params: { template_search: { dynamic: true, value: { - type: 'workflow_job_template,job_template', + type: 'job_template', + order_by: 'name', + page_size: '20', + jobtemplate__project: null }, } }, diff --git a/awx/ui/client/features/templates/routes/templatesList.route.js b/awx/ui/client/features/templates/routes/templatesList.route.js index 8a912776cc..63d58fb83d 100644 --- a/awx/ui/client/features/templates/routes/templatesList.route.js +++ b/awx/ui/client/features/templates/routes/templatesList.route.js @@ -25,6 +25,8 @@ export default { dynamic: true, value: { type: 'workflow_job_template,job_template', + order_by: 'name', + page_size: '20' }, } }, diff --git a/awx/ui/client/features/templates/templates.strings.js b/awx/ui/client/features/templates/templates.strings.js index d294988d01..b536f665b3 100644 --- a/awx/ui/client/features/templates/templates.strings.js +++ b/awx/ui/client/features/templates/templates.strings.js @@ -143,6 +143,11 @@ function TemplatesStrings (BaseString) { CANCEL: t.s('CANCEL'), SAVE_AND_EXIT: t.s('SAVE & EXIT') }; + + ns.sort = { + NAME_ASCENDING: t.s('Name (Ascending)'), + NAME_DESCENDING: t.s('Name (Descending)') + }; } TemplatesStrings.$inject = ['BaseStringService']; diff --git a/awx/ui/client/features/templates/templatesList.controller.js b/awx/ui/client/features/templates/templatesList.controller.js index d9846a2abf..b072029752 100644 --- a/awx/ui/client/features/templates/templatesList.controller.js +++ b/awx/ui/client/features/templates/templatesList.controller.js @@ -36,6 +36,7 @@ function ListTemplatesController( let refreshAfterLaunchClose = false; let pendingRefresh = false; let refreshTimerRunning = false; + let paginateQuerySet = {}; vm.strings = strings; vm.templateTypes = mapChoices(choices); @@ -61,6 +62,39 @@ function ListTemplatesController( }; vm.dataset = Dataset.data; vm.templates = Dataset.data.results; + vm.defaultParams = $state.params.template_search; + + const toolbarSortDefault = { + label: `${strings.get('sort.NAME_ASCENDING')}`, + value: 'name' + }; + + vm.toolbarSortOptions = [ + toolbarSortDefault, + { label: `${strings.get('sort.NAME_DESCENDING')}`, value: '-name' } + ]; + + vm.toolbarSortValue = toolbarSortDefault; + + $scope.$on('updateDataset', (event, dataset, queryset) => { + paginateQuerySet = queryset; + }); + + vm.onToolbarSort = (sort) => { + vm.toolbarSortValue = sort; + + const queryParams = Object.assign( + {}, + $state.params.template_search, + paginateQuerySet, + { order_by: sort.value } + ); + + // Update params + $state.go('.', { + template_search: queryParams + }, { notify: false, location: 'replace' }); + }; $scope.$watch('vm.dataset.count', () => { $scope.$emit('updateCount', vm.dataset.count, 'templates'); @@ -75,6 +109,7 @@ function ListTemplatesController( } else { vm.activeId = ""; } + setToolbarSort(); }, true); $scope.$on(`ws-jobs`, () => { @@ -203,15 +238,25 @@ function ListTemplatesController( } }; + function setToolbarSort () { + const orderByValue = _.get($state.params, 'template_search.order_by'); + const sortValue = _.find(vm.toolbarSortOptions, (option) => option.value === orderByValue); + if (sortValue) { + vm.toolbarSortValue = sortValue; + } else { + vm.toolbarSortValue = toolbarSortDefault; + } + } + function refreshTemplates() { Wait('start'); let path = GetBasePath('unified_job_templates'); qs.search(path, $state.params.template_search, { 'X-WS-Session-Quiet': true }) - .then(function(searchResponse) { - vm.dataset = searchResponse.data; - vm.templates = vm.dataset.results; - }) - .finally(() => Wait('stop')); + .then(function(searchResponse) { + vm.dataset = searchResponse.data; + vm.templates = vm.dataset.results; + }) + .finally(() => Wait('stop')); pendingRefresh = false; refreshTimerRunning = true; $timeout(() => { diff --git a/awx/ui/client/features/templates/templatesList.view.html b/awx/ui/client/features/templates/templatesList.view.html index 959dc3ba35..6ed2379d17 100644 --- a/awx/ui/client/features/templates/templatesList.view.html +++ b/awx/ui/client/features/templates/templatesList.view.html @@ -8,6 +8,7 @@ list="vm.list" collection="vm.templates" dataset="vm.dataset" + default-params="vm.defaultParams" search-tags="vm.searchTags" search-bar-full-width="vm.isPortalMode"> @@ -33,10 +34,13 @@ + on-collapse="vm.onCollapse" + is-collapsed="vm.isCollapsed" + sort-only="false" + sort-value="vm.toolbarSortValue" + sort-options="vm.toolbarSortOptions" + on-sort="vm.onToolbarSort"> + ui-sref="{{ link.sref }}" + ui-sref-opts="{{ link.srefOpts }}"> {{ link.name }}