Commit a5a7b574 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Paginate group results

[ci skip]
parent a87d447c
<script> <script>
import TablePaginationComponent from '~/vue_shared/components/table_pagination';
export default { export default {
components: {
'gl-pagination': TablePaginationComponent,
},
props: { props: {
groups: { groups: {
type: Array, type: Array,
required: true, required: true,
}, },
pageInfo: {
type: Object,
required: true,
},
},
methods: {
change(pageNumber) {
const param = gl.utils.setParamInURL('page', pageNumber);
gl.utils.visitUrl(param);
return param;
},
}, },
}; };
</script> </script>
...@@ -12,5 +29,8 @@ export default { ...@@ -12,5 +29,8 @@ export default {
<template> <template>
<div> <div>
<group-folder :groups="groups" /> <group-folder :groups="groups" />
<gl-pagination
:change="change"
:pageInfo="pageInfo" />
</div> </div>
</template> </template>
...@@ -38,9 +38,12 @@ $(() => { ...@@ -38,9 +38,12 @@ $(() => {
parentId = parentGroup.id; parentId = parentGroup.id;
} }
service.getGroups(parentId) const page = gl.utils.getParameterByName('page');
service.getGroups(parentId, page)
.then((response) => { .then((response) => {
store.setGroups(response.json(), parentGroup); store.setGroups(response.json(), parentGroup);
store.storePagination(response.headers);
}) })
.catch(() => { .catch(() => {
// TODO: Handler error // TODO: Handler error
......
...@@ -8,13 +8,15 @@ export default class GroupsService { ...@@ -8,13 +8,15 @@ export default class GroupsService {
this.groups = Vue.resource(endpoint); this.groups = Vue.resource(endpoint);
} }
getGroups(parentId) { getGroups(parentId, page = 1) {
let data = {}; const data = {};
if (parentId) { if (parentId) {
data = { data.parent_id = parentId;
parent_id: parentId, }
};
if (page) {
data.page = page;
} }
return this.groups.get(data); return this.groups.get(data);
......
...@@ -2,6 +2,7 @@ export default class GroupsStore { ...@@ -2,6 +2,7 @@ export default class GroupsStore {
constructor() { constructor() {
this.state = {}; this.state = {};
this.state.groups = []; this.state.groups = [];
this.state.pageInfo = {};
return this; return this;
} }
...@@ -18,6 +19,19 @@ export default class GroupsStore { ...@@ -18,6 +19,19 @@ export default class GroupsStore {
return rawGroups; return rawGroups;
} }
storePagination(pagination = {}) {
let paginationInfo;
if (Object.keys(pagination).length) {
const normalizedHeaders = gl.utils.normalizeHeaders(pagination);
paginationInfo = gl.utils.parseIntPagination(normalizedHeaders);
} else {
paginationInfo = pagination;
}
this.state.pageInfo = paginationInfo;
}
decorateGroups(rawGroups) { decorateGroups(rawGroups) {
this.groups = rawGroups.map(GroupsStore.decorateGroup); this.groups = rawGroups.map(GroupsStore.decorateGroup);
return this.groups; return this.groups;
......
.js-groups-list-holder .js-groups-list-holder
#dashboard-group-app{ data: { endpoint: dashboard_groups_path(format: :json) } } #dashboard-group-app{ data: { endpoint: dashboard_groups_path(format: :json) } }
%groups-component{ ':groups' => 'state.groups' } %groups-component{ ':groups' => 'state.groups', ':page-info' => 'state.pageInfo' }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment