2020-01-16 16:25:40 +01:00
|
|
|
import {Component, Input, OnInit} from '@angular/core';
|
2020-01-16 10:20:15 +01:00
|
|
|
import {ConfigService} from "../../../services/config.service";
|
2020-01-20 14:36:26 +01:00
|
|
|
import {mockPoll3} from "../../../config/mocks/mock-poll3";
|
2019-08-21 14:28:50 +02:00
|
|
|
|
|
|
|
@Component({
|
2020-01-16 16:25:40 +01:00
|
|
|
selector: 'framadate-voting-summary',
|
|
|
|
templateUrl: './voting-summary.component.html',
|
|
|
|
styleUrls: ['./voting-summary.component.scss']
|
2019-08-21 14:28:50 +02:00
|
|
|
})
|
2020-01-16 16:25:40 +01:00
|
|
|
export class VotingSummaryComponent implements OnInit {
|
|
|
|
|
|
|
|
private preferred: string = 'rien';
|
|
|
|
private counters: any = {};
|
|
|
|
|
|
|
|
@Input() private pollconfig = mockPoll3;
|
|
|
|
|
|
|
|
constructor(private config: ConfigService) {
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2019-09-09 10:57:08 +02:00
|
|
|
}
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2019-09-09 10:57:08 +02:00
|
|
|
ngOnInit() {
|
2020-01-16 16:25:40 +01:00
|
|
|
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 => {
|
2020-01-16 16:46:19 +01:00
|
|
|
return elem.id == choice_id_max
|
2020-01-16 16:25:40 +01:00
|
|
|
})
|
|
|
|
this.preferred = choiceTitleFound.name;
|
|
|
|
console.log('choiceTitleFound', choiceTitleFound)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-21 14:28:50 +02:00
|
|
|
|
|
|
|
}
|