Created
August 22, 2018 05:25
-
-
Save kevinkucharczyk/0c8a5fbfda0ba678d73f20f4f3a1097a to your computer and use it in GitHub Desktop.
Pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ActiveModelAdapter from 'active-model-adapter'; | |
export default ActiveModelAdapter.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function() { | |
window.server = this; | |
this.get('/posts', function(schema, request){ | |
let { page } = request.queryParams; | |
if (page) { | |
page = parseInt(page); | |
} else { | |
page = 1; | |
} | |
let posts = [ | |
{ id: 1, author: 'Jane Eyre' }, | |
{ id: 2, author: 'Emily Dickinson' }, | |
{ id: 3, author: 'Mark Twain' }, | |
{ id: 4, author: 'J.K. Rowling' }, | |
{ id: 5, author: 'Maya Angelou' }, | |
{ id: 6, author: 'Stephen King' }, | |
{ id: 7, author: 'C.S. Lewis' }, | |
{ id: 8, author: 'J.R.R. Tolkein' } | |
]; | |
if (page > 4) { | |
throw("There are not more than 4 pages"); | |
} else { | |
let arrays = [], size = 2; | |
while (posts.length > 0) | |
arrays.push(posts.splice(0, size)); | |
return { posts: arrays[page - 1], meta: {total: 4, page: page} } | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
author: attr('string') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.store.query('post', { page: 1 }); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export { ActiveModelSerializer as default } from 'active-model-adapter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.0", | |
"ENV": { | |
"ember-cli-mirage": { | |
"enabled": true | |
} | |
}, | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"active-model-adapter": "2.2.0", | |
"ember-cli-mirage": "0.4.9", | |
"ember-data": "3.2.0", | |
"ember-truth-helpers": "2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment