mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
Add sort toolbar to applications list
This commit is contained in:
@@ -38,6 +38,11 @@ function ApplicationsStrings (BaseString) {
|
|||||||
ns.inputs = {
|
ns.inputs = {
|
||||||
ORGANIZATION_PLACEHOLDER: t.s('SELECT AN ORGANIZATION')
|
ORGANIZATION_PLACEHOLDER: t.s('SELECT AN ORGANIZATION')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.sort = {
|
||||||
|
NAME_ASCENDING: t.s('Name (Ascending)'),
|
||||||
|
NAME_DESCENDING: t.s('Name (Descending)')
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationsStrings.$inject = ['BaseStringService'];
|
ApplicationsStrings.$inject = ['BaseStringService'];
|
||||||
|
|||||||
@@ -8,14 +8,17 @@ function ListApplicationsController (
|
|||||||
$scope,
|
$scope,
|
||||||
$state,
|
$state,
|
||||||
Dataset,
|
Dataset,
|
||||||
|
GetBasePath,
|
||||||
ProcessErrors,
|
ProcessErrors,
|
||||||
Prompt,
|
Prompt,
|
||||||
|
qs,
|
||||||
resolvedModels,
|
resolvedModels,
|
||||||
strings,
|
strings,
|
||||||
Wait,
|
Wait
|
||||||
) {
|
) {
|
||||||
const vm = this || {};
|
const vm = this || {};
|
||||||
const application = resolvedModels;
|
const application = resolvedModels;
|
||||||
|
let paginateQuerySet = {};
|
||||||
|
|
||||||
vm.strings = strings;
|
vm.strings = strings;
|
||||||
vm.activeId = $state.params.application_id;
|
vm.activeId = $state.params.application_id;
|
||||||
@@ -32,16 +35,62 @@ function ListApplicationsController (
|
|||||||
$scope[key] = Dataset.data;
|
$scope[key] = Dataset.data;
|
||||||
vm.applicationsCount = Dataset.data.count;
|
vm.applicationsCount = Dataset.data.count;
|
||||||
$scope[name] = Dataset.data.results;
|
$scope[name] = Dataset.data.results;
|
||||||
$scope.$on('updateDataset', (e, dataset) => {
|
|
||||||
|
$scope.$on('updateDataset', (e, dataset, queryset) => {
|
||||||
$scope[key] = dataset;
|
$scope[key] = dataset;
|
||||||
$scope[name] = dataset.results;
|
$scope[name] = dataset.results;
|
||||||
vm.applicationsCount = dataset.count;
|
vm.applicationsCount = dataset.count;
|
||||||
|
// Remove paginateQuerySet once the page and page_size params
|
||||||
|
// are represented in the url.
|
||||||
|
paginateQuerySet = queryset;
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.tooltips = {
|
vm.tooltips = {
|
||||||
add: strings.get('tooltips.ADD')
|
add: strings.get('tooltips.ADD')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toolbarSortDefault = {
|
||||||
|
label: `${strings.get('sort.NAME_ASCENDING')}`,
|
||||||
|
value: 'name'
|
||||||
|
};
|
||||||
|
|
||||||
|
vm.toolbarSortOptions = [
|
||||||
|
toolbarSortDefault,
|
||||||
|
{ label: `${strings.get('sort.NAME_DESCENDING')}`, value: '-name' }
|
||||||
|
];
|
||||||
|
|
||||||
|
vm.toolbarSortValue = toolbarSortDefault;
|
||||||
|
|
||||||
|
function setToolbarSort () {
|
||||||
|
const orderByValue = _.get($state.params, 'application_search.order_by');
|
||||||
|
const sortValue = _.find(vm.toolbarSortOptions, (option) => option.value === orderByValue);
|
||||||
|
if (sortValue) {
|
||||||
|
vm.toolbarSortValue = sortValue;
|
||||||
|
} else {
|
||||||
|
vm.toolbarSortValue = toolbarSortDefault;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.$watch('$state.params', () => {
|
||||||
|
setToolbarSort();
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
vm.onToolbarSort = (sort) => {
|
||||||
|
vm.toolbarSortValue = sort;
|
||||||
|
|
||||||
|
const queryParams = Object.assign(
|
||||||
|
{},
|
||||||
|
$state.params.application_search,
|
||||||
|
paginateQuerySet,
|
||||||
|
{ order_by: sort.value }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update URL with params
|
||||||
|
$state.go('.', {
|
||||||
|
application_search: queryParams
|
||||||
|
}, { notify: false, location: 'replace' });
|
||||||
|
};
|
||||||
|
|
||||||
vm.getModified = app => {
|
vm.getModified = app => {
|
||||||
const modified = _.get(app, 'modified');
|
const modified = _.get(app, 'modified');
|
||||||
|
|
||||||
@@ -111,8 +160,10 @@ ListApplicationsController.$inject = [
|
|||||||
'$scope',
|
'$scope',
|
||||||
'$state',
|
'$state',
|
||||||
'Dataset',
|
'Dataset',
|
||||||
|
'GetBasePath',
|
||||||
'ProcessErrors',
|
'ProcessErrors',
|
||||||
'Prompt',
|
'Prompt',
|
||||||
|
'QuerySet',
|
||||||
'resolvedModels',
|
'resolvedModels',
|
||||||
'ApplicationsStrings',
|
'ApplicationsStrings',
|
||||||
'Wait'
|
'Wait'
|
||||||
|
|||||||
@@ -30,7 +30,13 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<at-list-toolbar
|
||||||
|
ng-if="vm.applicationsCount > 0"
|
||||||
|
sort-only="true"
|
||||||
|
sort-value="vm.toolbarSortValue"
|
||||||
|
sort-options="vm.toolbarSortOptions"
|
||||||
|
on-sort="vm.onToolbarSort">
|
||||||
|
</at-list-toolbar>
|
||||||
<at-list results="applications">
|
<at-list results="applications">
|
||||||
<at-row ng-repeat="application in applications"
|
<at-row ng-repeat="application in applications"
|
||||||
ng-class="{'at-Row--active': (application.id === vm.activeId)}">
|
ng-class="{'at-Row--active': (application.id === vm.activeId)}">
|
||||||
@@ -61,7 +67,6 @@
|
|||||||
base-path="applications"
|
base-path="applications"
|
||||||
iterator="application"
|
iterator="application"
|
||||||
dataset="application_dataset"
|
dataset="application_dataset"
|
||||||
collection="applications"
|
collection="applications">
|
||||||
query-set="application_queryset">
|
|
||||||
</paginate>
|
</paginate>
|
||||||
</at-panel>
|
</at-panel>
|
||||||
|
|||||||
Reference in New Issue
Block a user