funky-framadate-front/src/app/ui/vote-choice/vote-choice.component.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-01-15 17:55:22 +01:00
import {Component, ElementRef, Input} from '@angular/core';
2019-10-01 18:32:24 +02:00
interface VoteChoice {
2020-01-15 17:55:22 +01:00
votes?: {
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;
answer: 'yes' | 'no' | 'maybe' | null;
2020-01-15 17:55:22 +01:00
simpleAnswer?: boolean
false; // enable if we display only a togglable "yes"
}
/**
* 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-01 18:32:24 +02:00
@Component({
selector: 'framadate-vote-choice',
templateUrl: './vote-choice.component.html',
styleUrls: ['./vote-choice.component.scss']
2019-10-01 18:32:24 +02:00
})
export class VoteChoiceComponent {
2020-01-23 15:24:39 +01:00
public showChangeChoicebutton = false;
2020-01-21 12:04:14 +01:00
@Input() public choice: any;
2020-01-23 16:47:53 +01:00
@Input() public poll: any;
@Input() public simpleAnswer: boolean = true;
@Input() public pollIsSpecialDate: boolean = false;
2020-01-15 17:55:22 +01:00
constructor(private el: ElementRef) {
2019-10-03 11:27:25 +02:00
2020-01-23 16:47:53 +01:00
if (this.poll && this.poll.data && this.poll.data.allowedAnswers) {
this.simpleAnswer = this.poll.data.allowedAnswers.length == 1
}
}
2019-10-01 18:32:24 +02:00
setAnswserTo(newAnswer: 'yes' | 'no' | 'maybe' | null) {
if (this.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
} else {
this.choice.answer = newAnswer;
}
2020-01-15 17:55:22 +01:00
this.el.nativeElement.blur();
}
2019-10-01 18:32:24 +02:00
}