2020-04-14 11:28:33 +02:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { ConfigService } from '../../../services/config.service';
|
2020-05-12 19:16:23 +02:00
|
|
|
import { mockPoll3 } from '../../../mocks/mock-poll3';
|
2019-08-21 14:28:50 +02:00
|
|
|
|
|
|
|
@Component({
|
2020-04-22 12:56:18 +02:00
|
|
|
selector: 'app-voting-summary',
|
2020-04-21 10:50:26 +02:00
|
|
|
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 {
|
2020-04-21 17:26:25 +02:00
|
|
|
public displayConfirmVoteModalAdmin = false;
|
|
|
|
public preferred = 'rien';
|
|
|
|
public severalPreferred = false;
|
2020-04-21 10:50:26 +02:00
|
|
|
|
|
|
|
@Input() pollconfig = mockPoll3;
|
|
|
|
|
|
|
|
constructor(public config: ConfigService) {}
|
|
|
|
|
2020-04-21 17:26:25 +02:00
|
|
|
ngOnInit(): void {
|
2020-04-21 10:50:26 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:26:25 +02:00
|
|
|
toggleModalDialogVisibility(): void {
|
|
|
|
this.displayConfirmVoteModalAdmin = !this.displayConfirmVoteModalAdmin;
|
2020-04-21 10:50:26 +02:00
|
|
|
}
|
2019-08-21 14:28:50 +02:00
|
|
|
}
|