mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-04 21:01:27 -05:00
32 lines
968 B
Text
32 lines
968 B
Text
|
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);
|
||
|
}
|
||
|
});
|