Show:
  1. /**
  2. @module mixins
  3. @submodule pagination
  4. */
  5.  
  6. import Mixin from '@ember/object/mixin';
  7.  
  8. var paginationController = Mixin.create({
  9. queryParams: ['skip'],
  10. skip: 0,
  11. limit: 20,
  12. actions: {
  13. prevPage: function () {
  14. var prevSkip = this.skip - this.limit;
  15. if (prevSkip < 0) {
  16. prevSkip = 0;
  17. }
  18. this.set('skip', prevSkip);
  19. this.transitionToRoute({
  20. queryParams: {
  21. skip: prevSkip,
  22. },
  23. });
  24. },
  25. nextPage: function () {
  26. var nextSkip = this.skip + this.limit;
  27. // if have next page
  28. if (this.model.length % this.limit !== 0) {
  29. return;
  30. }
  31.  
  32. this.transitionToRoute({
  33. queryParams: {
  34. skip: nextSkip,
  35. },
  36. });
  37. },
  38. },
  39. });
  40.  
  41. var paginationRoute = Mixin.create({
  42. queryParams: {
  43. skip: {
  44. refreshModel: true,
  45. },
  46. },
  47. });
  48.  
  49. export { paginationRoute, paginationController };
  50.