1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Merge pull request #3440 from marshmalien/feat-toolbar-sort-instances-list

Add sort and pagination to instances list

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
softwarefactory-project-zuul[bot] 2019-03-21 16:19:50 +00:00 committed by GitHub
commit 9aa9524257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 11 deletions

View File

@ -16,7 +16,7 @@
iterator="instance"
list="vm.list"
collection="vm.instances"
dataset="vm.dataset"
dataset="vm.instance_dataset"
search-tags="vm.searchTags">
</smart-search>
@ -34,6 +34,13 @@
<div ui-view="modal"></div>
</div>
</div>
<at-list-toolbar
ng-if="vm.instances.length > 0"
sort-only="true"
sort-value="vm.toolbarSortValue"
sort-options="vm.toolbarSortOptions"
on-sort="vm.onToolbarSort">
</at-list-toolbar>
<at-list results='vm.instances'>
<at-row ng-repeat="instance in vm.instances"
ng-class="{'at-Row--active': (instance.id === vm.activeId)}">
@ -84,4 +91,10 @@
</at-row>
</at-list>
</at-panel-body>
<paginate
collection="vm.instances"
dataset="vm.instance_dataset"
iterator="instance"
base-path="{{vm.list.basePath}}">
</paginate>
</at-panel>

View File

@ -1,25 +1,64 @@
function InstancesController ($scope, $state, $http, models, strings, Dataset, ProcessErrors) {
const { instanceGroup } = models;
const vm = this || {};
let paginateQuerySet = {};
vm.strings = strings;
vm.panelTitle = instanceGroup.get('name');
vm.instance_group_id = instanceGroup.get('id');
vm.policy_instance_list = instanceGroup.get('policy_instance_list');
vm.isSuperuser = $scope.$root.user_is_superuser;
init();
function init() {
vm.list = {
name: 'instances',
iterator: 'instance',
basePath: `/api/v2/instance_groups/${vm.instance_group_id}/instances/`
};
vm.instance_dataset = Dataset.data;
vm.instances = Dataset.data.results;
vm.dataset = Dataset.data;
vm.instances = instanceGroup.get('related.instances.results');
const toolbarSortDefault = {
label: `${strings.get('sort.NAME_ASCENDING')}`,
value: 'hostname'
};
vm.toolbarSortOptions = [
toolbarSortDefault,
{
label: `${strings.get('sort.NAME_DESCENDING')}`,
value: '-hostname'
}
];
vm.toolbarSortValue = toolbarSortDefault;
$scope.$watchCollection('$state.params', () => {
setToolbarSort();
});
function setToolbarSort () {
const orderByValue = _.get($state.params, 'instance_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.instance_search,
paginateQuerySet,
{ order_by: sort.value }
);
$state.go('.', {
instance_search: queryParams
}, { notify: false, location: 'replace' });
};
vm.tab = {
details: {
@ -84,6 +123,12 @@ function InstancesController ($scope, $state, $http, models, strings, Dataset, P
let selected = parseInt($state.params.instance_id);
return id === selected;
};
$scope.$on('updateDataset', (e, dataset, queryset) => {
vm.instances = dataset.results;
vm.instance_dataset = dataset;
paginateQuerySet = queryset;
});
}
InstancesController.$inject = [

View File

@ -190,7 +190,8 @@ function InstanceGroupsRun ($stateExtender, strings) {
params: {
instance_search: {
value: {
order_by: 'hostname'
order_by: 'hostname',
page_size: '10'
},
dynamic: true
}