funky-framadate-front/src/app/pages/voting/voting-summary/voting-summary.component.ts

65 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 {
private preferred: string = 'rien';
private counters: any = {};
@Input() private 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.map(stack => {
stack.votes.map(vote => {
let choice_id = vote.id;
let answer = vote.answer;
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('this.counters', this.counters);
let choiceTitleFound = this.pollconfig.choices.find(elem => {
return elem.id == choice_id_max
})
this.preferred = choiceTitleFound.name;
console.log('choiceTitleFound', choiceTitleFound)
}
}