2019-10-02 14:45:50 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
2019-10-01 18:32:24 +02:00
|
|
|
|
2019-10-02 14:45:50 +02:00
|
|
|
interface VoteChoice {
|
|
|
|
votesCount: {
|
|
|
|
yes: number
|
|
|
|
no: number
|
|
|
|
maybe: number
|
|
|
|
notAnswered: number
|
|
|
|
};
|
2019-10-03 11:27:25 +02:00
|
|
|
text?: string;
|
|
|
|
date?: Date;
|
2019-10-02 14:45:50 +02:00
|
|
|
answer: 'yes' | 'no' | 'maybe' | null;
|
|
|
|
simpleAnswer: boolean; // enable if we display only a togglable "yes"
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* each vote choice takes a configuration from the container of all choices.
|
|
|
|
* this component is used to select a date choice, or a text answer
|
|
|
|
*/
|
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 {
|
|
|
|
|
2019-10-03 11:27:25 +02:00
|
|
|
@Input() choice: VoteChoice = {
|
|
|
|
date: new Date(),
|
|
|
|
text: 'description ',
|
|
|
|
votesCount: {
|
|
|
|
yes: 0,
|
|
|
|
no: 0,
|
|
|
|
maybe: 0,
|
|
|
|
notAnswered: 0
|
|
|
|
},
|
|
|
|
simpleAnswer: false,
|
|
|
|
answer: null
|
|
|
|
};
|
2019-10-02 14:45:50 +02:00
|
|
|
|
|
|
|
constructor() {
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-10-01 18:32:24 +02:00
|
|
|
|
|
|
|
}
|