2020-04-14 11:28:33 +02:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { ConfigService } from '../../../services/config.service';
|
|
|
|
import { mockPoll3 } from '../../../config/mocks/mock-poll3';
|
2019-08-21 14:28:50 +02:00
|
|
|
|
|
|
|
@Component({
|
2020-01-16 16:25:40 +01:00
|
|
|
selector: 'framadate-voting-summary',
|
|
|
|
templateUrl: './voting-summary.component.html',
|
2020-04-14 11:28:33 +02:00
|
|
|
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-01-22 11:18:55 +01:00
|
|
|
preferred: string = 'rien';
|
2020-01-30 12:55:40 +01:00
|
|
|
severalPreferred: boolean = false;
|
2020-01-16 16:25:40 +01:00
|
|
|
|
2020-01-22 11:18:55 +01:00
|
|
|
@Input() pollconfig = mockPoll3;
|
2020-01-16 16:25:40 +01:00
|
|
|
|
2020-04-14 11:28:33 +02:00
|
|
|
constructor(public config: ConfigService) {}
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2019-09-09 10:57:08 +02:00
|
|
|
ngOnInit() {
|
2020-01-16 16:25:40 +01:00
|
|
|
this.computePreferred();
|
2020-04-14 11:28:33 +02:00
|
|
|
}
|
2020-01-16 16:25:40 +01:00
|
|
|
|
2020-01-29 17:30:39 +01:00
|
|
|
getKeys(obj) {
|
2020-04-14 11:28:33 +02:00
|
|
|
return Object.keys(obj);
|
2020-01-29 17:30:39 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 16:25:40 +01:00
|
|
|
/**
|
|
|
|
* find the most "yes"
|
|
|
|
*/
|
|
|
|
computePreferred() {
|
2020-01-30 12:55:40 +01:00
|
|
|
let keys = Object.keys(this.pollconfig.choices_count.counts);
|
|
|
|
this.preferred = '';
|
|
|
|
this.severalPreferred = false;
|
|
|
|
let maxScore = this.pollconfig.choices_count.maxScore;
|
|
|
|
|
2020-04-14 11:28:33 +02:00
|
|
|
keys.forEach((item) => {
|
2020-01-30 12:55:40 +01:00
|
|
|
if (maxScore === this.pollconfig.choices_count.counts[item].score) {
|
|
|
|
if (this.preferred.length) {
|
2020-04-14 11:28:33 +02:00
|
|
|
this.preferred += ', ';
|
2020-01-30 12:55:40 +01:00
|
|
|
this.severalPreferred = true;
|
|
|
|
}
|
|
|
|
// find the favourite
|
|
|
|
this.preferred += this.pollconfig.choices_count.counts[item].choice_text;
|
|
|
|
}
|
2020-01-22 11:18:55 +01:00
|
|
|
});
|
2020-01-16 16:25:40 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 17:49:10 +02:00
|
|
|
showModalDialog() {
|
|
|
|
this.config.displayConfirmVoteModalAdmin = true;
|
|
|
|
}
|
2019-08-21 14:28:50 +02:00
|
|
|
}
|