mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
52 lines
1.3 KiB
TypeScript
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;
|
|
}
|
|
}
|