mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-04 12:51:41 -05:00
31 lines
968 B
JavaScript
31 lines
968 B
JavaScript
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);
|
|
}
|
|
});
|