funky-framadate-front/src/app/features/old-stuff/pages/voting/voting-summary/voting-summary.component.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

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
})
export class VotingSummaryComponent implements OnInit {
public displayConfirmVoteModalAdmin = false;
public preferred = 'rien';
public severalPreferred = false;
2020-04-21 10:50:26 +02:00
@Input() pollconfig = mockPoll3;
constructor(public config: ConfigService) {}
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;
}
});
}
toggleModalDialogVisibility(): void {
this.displayConfirmVoteModalAdmin = !this.displayConfirmVoteModalAdmin;
2020-04-21 10:50:26 +02:00
}
2019-08-21 14:28:50 +02:00
}