fix polls count
This commit is contained in:
parent
28065912b2
commit
03bcc95d65
@ -25,7 +25,7 @@
|
|||||||
<button href *ngIf="!poll.voted && !poll.expired && !pollLocked" class="btn btn-sm btn-custom-primary poll__btn-vote"
|
<button href *ngIf="!poll.voted && !poll.expired && !pollLocked" class="btn btn-sm btn-custom-primary poll__btn-vote"
|
||||||
title="don't boo, vote!" (click)="vote()">Vote</button>
|
title="don't boo, vote!" (click)="vote()">Vote</button>
|
||||||
<a href class="poll__refresh" *ngIf="(poll.voted || poll.expired) && !pollLocked" title="refresh poll" (click)="refresh()">refresh</a>
|
<a href class="poll__refresh" *ngIf="(poll.voted || poll.expired) && !pollLocked" title="refresh poll" (click)="refresh()">refresh</a>
|
||||||
<div class="poll__statistics"><span *ngIf="(poll.voted || poll.expired) && !pollLocked" class="poll__separator">·</span>{{poll.votes_count}} votes<span *ngIf="!poll.expired" class="poll__separator" title="{{ poll.expires_at | timeLeft | async }}">· {{ poll.expires_at | timeLeft | async }}</span></div>
|
<div class="poll__statistics"><span *ngIf="(poll.voted || poll.expired) && !pollLocked" class="poll__separator">·</span>{{poll.votes_count}} votes<span *ngIf="poll.voters_count > 0" class="poll__separator">·</span><span *ngIf="poll.voters_count > 0">{{poll.voters_count}} people</span><span *ngIf="!poll.expired" class="poll__separator" title="{{ poll.expires_at | timeLeft | async }}">· {{ poll.expires_at | timeLeft | async }}</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="poll__error" *ngIf="errorOccuredWhenRetrievingPoll">
|
<div class="poll__error" *ngIf="errorOccuredWhenRetrievingPoll">
|
||||||
Error occured when retrieving the poll
|
Error occured when retrieving the poll
|
||||||
|
@ -48,7 +48,7 @@ export class PollComponent implements OnInit {
|
|||||||
const maxVotes = Math.max(...this.poll.options.map(x => x.votes_count));
|
const maxVotes = Math.max(...this.poll.options.map(x => x.votes_count));
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (let opt of this.poll.options) {
|
for (let opt of this.poll.options) {
|
||||||
let optWrapper = new PollOptionWrapper(i, opt, this.poll.votes_count, opt.votes_count === maxVotes);
|
let optWrapper = new PollOptionWrapper(i, opt, this.poll.votes_count, this.poll.voters_count, opt.votes_count === maxVotes);
|
||||||
this.options.push(optWrapper);
|
this.options.push(optWrapper);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -183,14 +183,19 @@ export class PollComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PollOptionWrapper implements PollOption {
|
class PollOptionWrapper implements PollOption {
|
||||||
constructor(index: number, option: PollOption, totalVotes: number, isMax: boolean) {
|
constructor(index: number, option: PollOption, totalVotes: number, totalVoters: number, isMax: boolean) {
|
||||||
|
let votesDivider = totalVotes;
|
||||||
|
if(totalVoters && totalVoters > 0){
|
||||||
|
votesDivider = totalVoters;
|
||||||
|
}
|
||||||
|
|
||||||
this.id = index;
|
this.id = index;
|
||||||
this.title = option.title;
|
this.title = option.title;
|
||||||
this.votes_count = option.votes_count;
|
this.votes_count = option.votes_count;
|
||||||
if (totalVotes === 0) {
|
if (totalVotes === 0) {
|
||||||
this.percentage = '0';
|
this.percentage = '0';
|
||||||
} else {
|
} else {
|
||||||
this.percentage = ((this.votes_count / totalVotes) * 100).toFixed(0);
|
this.percentage = ((this.votes_count / votesDivider) * 100).toFixed(0);
|
||||||
}
|
}
|
||||||
this.isMax = isMax;
|
this.isMax = isMax;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +223,7 @@ export interface Poll {
|
|||||||
expired: boolean;
|
expired: boolean;
|
||||||
multiple: boolean;
|
multiple: boolean;
|
||||||
votes_count: number;
|
votes_count: number;
|
||||||
|
voters_count: number;
|
||||||
options: PollOption[];
|
options: PollOption[];
|
||||||
voted: boolean;
|
voted: boolean;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user