FEATURE: Allow poll results to be sorted.

This commit is contained in:
Guo Xiang Tan
2016-07-28 23:04:45 +08:00
parent 85a91c8b81
commit a7f2b2ded6
3 changed files with 56 additions and 6 deletions
@@ -7,7 +7,9 @@ export default Em.Component.extend({
@computed("poll.voters", "poll.type", "poll.options.[]")
options(voters, type) {
const options = this.get("poll.options");
const options = this.get("poll.options").slice(0).sort((a, b) => {
return a.get("votes") < b.get("votes") ? 1 : 0;
});
let percentages = voters === 0 ?
Array(options.length).fill(0) :
@@ -35,5 +37,4 @@ export default Em.Component.extend({
return options;
}
});
@@ -40,10 +40,8 @@ export default Ember.Component.extend({
didInsertElement() {
this._super();
Ember.run.schedule("afterRender", () => {
this.set("numOfVotersToShow", Math.round(this.$().width() / 25) * 2);
if (this.get("voterIds").length > 0) this._fetchUsers();
});
this.set("numOfVotersToShow", Math.round(this.$().width() / 25) * 2);
if (this.get("voterIds").length > 0) this._fetchUsers();
},
actions: {