discourse/plugins/poll/assets/javascripts/components/poll-results-number-voters.js.es6

32 lines
968 B
Text
Raw Normal View History

2016-06-07 06:55:01 -04:00
import computed from 'ember-addons/ember-computed-decorators';
import User from 'discourse/models/user';
import PollVoters from 'discourse/plugins/poll/components/poll-voters';
export default PollVoters.extend({
@computed("pollsVoters", "poll.options", "showMore", "isExpanded", "numOfVotersToShow")
users(pollsVoters, options, showMore, isExpanded, numOfVotersToShow) {
var users = [];
var voterIds = [];
const shouldLimit = showMore && !isExpanded;
options.forEach(option => {
option.voter_ids.forEach(voterId => {
if (shouldLimit) {
if (!(users.length > numOfVotersToShow - 1)) {
users.push(pollsVoters[voterId]);
}
} else {
users.push(pollsVoters[voterId]);
}
})
});
return users;
},
@computed("pollsVoters", "numOfVotersToShow")
showMore(pollsVoters, numOfVotersToShow) {
return !(Object.keys(pollsVoters).length < numOfVotersToShow);
}
});