67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import {Component, Input, OnInit} from '@angular/core';
|
|
import {ConfigService} from "../../../services/config.service";
|
|
import {mockPoll3} from "../../../config/mocks/mock-poll3";
|
|
|
|
@Component({
|
|
selector: 'framadate-voting-summary',
|
|
templateUrl: './voting-summary.component.html',
|
|
styleUrls: ['./voting-summary.component.scss']
|
|
})
|
|
export class VotingSummaryComponent implements OnInit {
|
|
|
|
preferred: string = 'rien';
|
|
counters: any = {};
|
|
|
|
@Input() pollconfig = mockPoll3;
|
|
|
|
constructor(private config: ConfigService) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.computePreferred();
|
|
}
|
|
|
|
/**
|
|
* find the most "yes"
|
|
*/
|
|
computePreferred() {
|
|
|
|
let maximumYesCount = 0;
|
|
let choice_id_max = 0;
|
|
let winners_id = [];
|
|
this.pollconfig.stacks.forEach(stack => {
|
|
|
|
stack.votes.map(vote => {
|
|
let choice_id = vote.choice_id;
|
|
let answer = vote.text;
|
|
if (!this.counters["choice_" + choice_id]) {
|
|
this.counters["choice_" + choice_id] = {
|
|
yes: 0,
|
|
maybe: 0,
|
|
no: 0,
|
|
}
|
|
}
|
|
this.counters["choice_" + choice_id][answer]++;
|
|
if (this.counters["choice_" + choice_id]['yes'] > maximumYesCount) {
|
|
choice_id_max = choice_id;
|
|
}
|
|
})
|
|
|
|
|
|
// find the favourite
|
|
});
|
|
console.log('choice_id_max', choice_id_max);
|
|
console.log(' this.pollconfig.choices', this.pollconfig.choices);
|
|
let choiceTitleFound = this.pollconfig.choices.find(elem => {
|
|
console.log('elem', elem);
|
|
return elem.id == choice_id_max
|
|
});
|
|
this.preferred = choiceTitleFound.text;
|
|
console.log('choiceTitleFound', choiceTitleFound)
|
|
|
|
}
|
|
|
|
|
|
}
|