funky-framadate-front/mocks/old-stuff/pages/voting/voting-summary/voting-summary.component.ts
2021-04-29 10:41:47 +02:00

52 lines
1.3 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { ConfigService } from '../../../services/config.service';
import { mockPoll3 } from '../../../mocks/mock-poll3';
@Component({
selector: 'app-voting-summary',
templateUrl: './voting-summary.component.html',
styleUrls: ['./voting-summary.component.scss'],
})
export class VotingSummaryComponent implements OnInit {
public displayConfirmVoteModalAdmin = false;
public preferred = 'rien';
public severalPreferred = false;
@Input() pollconfig = mockPoll3;
constructor(public config: ConfigService) {}
ngOnInit(): void {
this.computePreferred();
}
getKeys(obj) {
return Object.keys(obj);
}
/**
* find the most "yes"
*/
computePreferred() {
const keys = Object.keys(this.pollconfig.choices_count.counts);
this.preferred = '';
this.severalPreferred = false;
const 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;
}
});
}
toggleModalDialogVisibility(): void {
this.displayConfirmVoteModalAdmin = !this.displayConfirmVoteModalAdmin;
}
}