2020-01-15 17:55:22 +01:00
|
|
|
import {Component, ElementRef, Input} from '@angular/core';
|
2019-10-01 18:32:24 +02:00
|
|
|
|
2019-10-02 14:45:50 +02:00
|
|
|
interface VoteChoice {
|
2020-01-15 17:55:22 +01:00
|
|
|
votes?: {
|
2019-10-02 14:45:50 +02:00
|
|
|
yes: number
|
|
|
|
no: number
|
|
|
|
maybe: number
|
|
|
|
notAnswered: number
|
|
|
|
};
|
2020-01-15 17:55:22 +01:00
|
|
|
name?: string;
|
2019-10-03 11:27:25 +02:00
|
|
|
date?: Date;
|
2019-10-02 14:45:50 +02:00
|
|
|
answer: 'yes' | 'no' | 'maybe' | null;
|
2020-01-15 17:55:22 +01:00
|
|
|
simpleAnswer?: boolean
|
|
|
|
false; // enable if we display only a togglable "yes"
|
2019-10-02 14:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* each vote choice takes a configuration from the container of all choices.
|
2020-01-15 17:55:22 +01:00
|
|
|
* this component is used to select a date choice, or a name answer
|
2019-10-02 14:45:50 +02:00
|
|
|
*/
|
2019-10-01 18:32:24 +02:00
|
|
|
@Component({
|
2019-10-02 14:45:50 +02:00
|
|
|
selector: 'framadate-vote-choice',
|
|
|
|
templateUrl: './vote-choice.component.html',
|
|
|
|
styleUrls: ['./vote-choice.component.scss']
|
2019-10-01 18:32:24 +02:00
|
|
|
})
|
2019-10-02 14:45:50 +02:00
|
|
|
export class VoteChoiceComponent {
|
|
|
|
|
2020-01-21 12:04:14 +01:00
|
|
|
@Input() public choice: any;
|
2019-10-02 14:45:50 +02:00
|
|
|
|
2020-01-15 17:55:22 +01:00
|
|
|
constructor(private el: ElementRef) {
|
2019-10-03 11:27:25 +02:00
|
|
|
|
2019-10-02 14:45:50 +02:00
|
|
|
}
|
2019-10-01 18:32:24 +02:00
|
|
|
|
2019-10-02 14:45:50 +02:00
|
|
|
setAnswserTo(newAnswer: 'yes' | 'no' | 'maybe' | null) {
|
|
|
|
if (this.choice.simpleAnswer) {
|
|
|
|
// only toggle yes to no
|
|
|
|
if (this.choice.answer && this.choice.answer === 'yes') {
|
|
|
|
this.choice.answer = 'no';
|
|
|
|
} else {
|
|
|
|
this.choice.answer = 'yes';
|
|
|
|
}
|
2019-10-01 18:32:24 +02:00
|
|
|
|
2019-10-02 14:45:50 +02:00
|
|
|
} else {
|
|
|
|
this.choice.answer = newAnswer;
|
|
|
|
}
|
2020-01-15 17:55:22 +01:00
|
|
|
this.el.nativeElement.blur();
|
2019-10-02 14:45:50 +02:00
|
|
|
}
|
2019-10-01 18:32:24 +02:00
|
|
|
|
|
|
|
}
|