Skip to content

Commit b75c524

Browse files
committed
Use existing server info to calculate total pages
1 parent 9959ba0 commit b75c524

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/controllers/group/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Pagination from 'ember-cli-jsonapi-pagination/mixins/controllers/jsonapi-
33

44
export default Ember.Controller.extend(Pagination, {
55
totalPages: Ember.computed('size', 'number', 'model.posts.[]', function() {
6-
return this.get('posts.meta.total-pages');
6+
const lastPage = new URL(this.get("posts.links.last"));
7+
return parseInt(lastPage.searchParams.get("page[number]"));
78
})
89
});

mirage/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ export default function() {
5959
const group = schema.groups.find(groupId);
6060
const postIds = group.posts.models.map(model => model.id);
6161
const offset = (pageNumber - 1) * pageSize;
62+
const lastPage = Math.ceil(group.posts.models.length / pageSize);
6263

6364
let json = this.serialize(schema.posts.find(postIds.slice(offset, offset + pageSize)));
64-
json.meta = { "total-pages": Math.ceil(group.posts.models.length / pageSize) };
65+
json.links = { "last": `http://example.com/api/v1/posts?page%5Bnumber%5D=${lastPage}` };
6566
return json;
6667
}
6768

0 commit comments

Comments
 (0)