mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
59 lines
1.8 KiB
TypeScript
59 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';
|
|
severalPreferred: boolean = false;
|
|
|
|
@Input() pollconfig = mockPoll3;
|
|
|
|
constructor(public config: ConfigService) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.computePreferred();
|
|
console.log(' this.pollconfig.choices', this.pollconfig.choices)
|
|
console.log(' this.pollconfig.choices_count', this.pollconfig.choices_count.counts)
|
|
console.log('this.pollconfig.choices_count.counts[10]', this.pollconfig.choices_count.counts[10])
|
|
console.log('this.pollconfig.choices[2].id', this.pollconfig.choices[2].id)
|
|
console.log('this.pollconfig.choices_count.counts[]', this.pollconfig.choices_count.counts[this.pollconfig.choices[2].id].score)
|
|
}
|
|
|
|
getKeys(obj) {
|
|
return Object.keys(obj)
|
|
}
|
|
|
|
/**
|
|
* find the most "yes"
|
|
*/
|
|
computePreferred() {
|
|
let keys = Object.keys(this.pollconfig.choices_count.counts);
|
|
this.preferred = '';
|
|
this.severalPreferred = false;
|
|
let maxScore = this.pollconfig.choices_count.maxScore;
|
|
|
|
keys.forEach(item => {
|
|
if (maxScore === this.pollconfig.choices_count.counts[item].score) {
|
|
if (this.preferred.length) {
|
|
this.preferred += ', '
|
|
this.severalPreferred = true;
|
|
}
|
|
// find the favourite
|
|
this.preferred += this.pollconfig.choices_count.counts[item].choice_text;
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
}
|