funky-framadate-front/src/app/features/participation/add-answer/add-answer.component.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-05-12 19:16:23 +02:00
import { Component, Input, OnInit } from '@angular/core';
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';
import { ModalService } from '../../../core/services/modal.service';
2020-05-12 19:16:23 +02:00
import { PollService } from '../../../core/services/poll.service';
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;
public answer: Answer;
2020-05-12 19:16:23 +02:00
constructor(private pollService: PollService, private modalService: ModalService) {}
2020-05-12 19:16:23 +02:00
ngOnInit(): void {}
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
}
}