Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Pagination in My Badges (#1151)
- Loading branch information
Showing
7 changed files
with
336 additions
and
310 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,48 @@ | ||
import Component from '@ember/component'; | ||
import Ember from 'ember'; | ||
|
||
const { inject } = Ember; | ||
|
||
export default Component.extend({ | ||
queryParams : ['page'], | ||
page : 1, | ||
notify : inject.service('notify'), | ||
actions : { | ||
nextPage() { | ||
let filter = {}; | ||
if (this.page > 1) { | ||
filter.page = this.page + 1; | ||
this.get('store').query('my-badges', filter) | ||
.then(records => { | ||
if (records.length > 0) { | ||
this.set('my-badges', records); | ||
this.set('page', this.page + 1); | ||
} else { | ||
this.notify.error('No More Badges found'); | ||
} | ||
}) | ||
.catch(err => { | ||
this.get('notify').error('Please try again!'); | ||
}); | ||
} else { | ||
this.notify.error('No More Badges Found'); | ||
} | ||
}, | ||
prevPage() { | ||
let filter = {}; | ||
if (this.page - 1 > 0) { | ||
filter.page = this.page - 1; | ||
this.get('store').query('my-badges', filter) | ||
.then(records => { | ||
this.set('my-badges', records); | ||
this.set('page', this.page - 1); | ||
}) | ||
.catch(err => { | ||
this.get('notify').error('Please try again!'); | ||
}); | ||
} else { | ||
this.notify.error('No More Badges Found'); | ||
} | ||
} | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Controller from '@ember/controller'; | ||
import Ember from 'ember'; | ||
|
||
const { inject } = Ember; | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
import Ember from 'ember'; | ||
|
||
const { set } = Ember; | ||
|
||
export default Route.extend({ | ||
model() { | ||
return this.get('store').findAll('my-badges'); | ||
beforeModel(transition) { | ||
this._super(...arguments); | ||
}, | ||
|
||
model(params) { | ||
let filter = {}; | ||
this.set('params', params); | ||
filter.state = 'all'; | ||
filter.page = params.page; | ||
return this.get('store').query('my-badges', filter); | ||
} | ||
}); |
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
Oops, something went wrong.