2020-05-12 19:16:23 +02:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2020-06-16 18:40:48 +02:00
|
|
|
import { MatDialogConfig } from '@angular/material/dialog';
|
2020-06-12 19:17:39 +02:00
|
|
|
import { Answer } from 'src/app/core/enums/answer.enum';
|
2020-05-12 19:16:23 +02:00
|
|
|
|
|
|
|
import { Choice } from '../../../core/models/choice.model';
|
|
|
|
import { Poll } from '../../../core/models/poll.model';
|
|
|
|
import { User } from '../../../core/models/user.model';
|
2020-06-16 18:40:48 +02:00
|
|
|
import { ModalService } from '../../../core/services/modal.service';
|
2020-05-12 19:16:23 +02:00
|
|
|
import { PollService } from '../../../core/services/poll.service';
|
2020-06-16 18:40:48 +02:00
|
|
|
import { ChoiceDetailsComponent } from '../../../shared/components/choice-details/choice-details.component';
|
2020-05-12 19:16:23 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-add-answer',
|
|
|
|
templateUrl: './add-answer.component.html',
|
|
|
|
styleUrls: ['./add-answer.component.scss'],
|
|
|
|
})
|
|
|
|
export class AddAnswerComponent implements OnInit {
|
|
|
|
@Input() user: User;
|
|
|
|
@Input() poll: Poll;
|
|
|
|
@Input() choice: Choice;
|
2020-06-12 19:17:39 +02:00
|
|
|
public answerEnum = Answer;
|
2020-06-16 18:40:48 +02:00
|
|
|
public answer: Answer;
|
2020-05-12 19:16:23 +02:00
|
|
|
|
2020-06-16 18:40:48 +02:00
|
|
|
constructor(private pollService: PollService, private modalService: ModalService) {}
|
2020-05-12 19:16:23 +02:00
|
|
|
|
|
|
|
ngOnInit(): void {}
|
|
|
|
|
2020-06-16 18:40:48 +02:00
|
|
|
public openModal(choice: Choice): void {
|
|
|
|
const config: MatDialogConfig<Choice> = { data: choice };
|
|
|
|
this.modalService.openModal<ChoiceDetailsComponent, Choice>(ChoiceDetailsComponent, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
public vote(answer: string): void {
|
|
|
|
this.answer = answer as Answer;
|
|
|
|
this.pollService.saveParticipation(this.choice, this.user, this.answer);
|
2020-05-12 19:16:23 +02:00
|
|
|
}
|
|
|
|
}
|