source: src/Clients/Angular/finki-chattery/src/app/modules/questioning/components/ask-question/ask-question.component.ts@ c205cc4

dev
Last change on this file since c205cc4 was c205cc4, checked in by Стојков Марко <mst@…>, 3 years ago

Ask question finishing touches

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { FormControl, FormGroup, Validators } from '@angular/forms';
3import { Router } from '@angular/router';
4
5import { CategoryFacadeService } from 'src/app/core/state/category-facade.service';
6import { ButtonType } from 'src/app/shared-app/components/generic/button/button.models';
7import { AskQuestionRequest } from '../../models/questioning-request.models';
8import { QuestioningApiService } from '../../services/questioning-api.service';
9
10@Component({
11 selector: 'app-ask-question',
12 templateUrl: './ask-question.component.html',
13 styleUrls: ['./ask-question.component.scss']
14})
15export class AskQuestionComponent implements OnInit {
16 public titleForm = new FormControl('', [Validators.required, Validators.maxLength(500)]);
17 public textForm = new FormControl('', [Validators.required, Validators.maxLength(4000)]);
18 public categoriesForm = new FormControl([]);
19 public questionFormGroup: FormGroup;
20 public ButtonType = ButtonType;
21 public categoriesList$ = this.categoriesFacade.getCategories();
22
23 constructor(private api: QuestioningApiService, private categoriesFacade: CategoryFacadeService, private router: Router) {
24 this.questionFormGroup = new FormGroup({
25 title: this.titleForm,
26 text: this.textForm,
27 categories: this.categoriesForm
28 });
29 }
30
31 ngOnInit(): void {}
32
33 public askQuestion(): void {
34 const body = new AskQuestionRequest(this.titleForm.value, this.textForm.value, this.categoriesForm.value);
35 this.api.askQuestion(body).subscribe((questionUid) => {
36 this.router.navigateByUrl(`questioning/${questionUid}`);
37 });
38 }
39}
Note: See TracBrowser for help on using the repository browser.