1 | import {Component, OnInit} from '@angular/core';
|
---|
2 | import {ActivatedRoute, Router} from "@angular/router";
|
---|
3 | import {ControlsService} from "../../../services/controls/controls.service";
|
---|
4 | import {FineResponse} from "../../../model/responses/FineResponse";
|
---|
5 | import {MatInputModule} from '@angular/material/input';
|
---|
6 | import {MatFormFieldModule} from '@angular/material/form-field';
|
---|
7 | import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
|
---|
8 | import {MatOption} from "@angular/material/core";
|
---|
9 | import {MatSelect} from "@angular/material/select";
|
---|
10 | import {UserService} from "../../../services/user/user.service";
|
---|
11 | import {UserResponse} from "../../../model/responses/UserResponse";
|
---|
12 | import {MatButton} from "@angular/material/button";
|
---|
13 | import {MatCheckbox} from "@angular/material/checkbox";
|
---|
14 | import {FineRequest} from "../../../model/requests/FineRequest";
|
---|
15 | import {FineService} from "../../../services/fine/fine.service";
|
---|
16 | import {Subject, switchMap} from "rxjs";
|
---|
17 |
|
---|
18 | @Component({
|
---|
19 | selector: 'app-control',
|
---|
20 | standalone: true,
|
---|
21 | imports: [
|
---|
22 | FormsModule, MatFormFieldModule, MatInputModule, ReactiveFormsModule, MatOption, MatSelect, MatButton, MatCheckbox
|
---|
23 | ],
|
---|
24 | templateUrl: './control.component.html',
|
---|
25 | styleUrl: './control.component.css'
|
---|
26 | })
|
---|
27 | export class ControlComponent implements OnInit {
|
---|
28 | controlId: number = +this.route.snapshot.paramMap.get('id')!!;
|
---|
29 | fines: FineResponse[] = []
|
---|
30 | passengers: UserResponse[] = []
|
---|
31 |
|
---|
32 | fineForm: FormGroup = new FormGroup({
|
---|
33 | dokument: new FormControl(null, [Validators.required]),
|
---|
34 | plateno: new FormControl(null, [Validators.required]),
|
---|
35 | iznos: new FormControl(null, [Validators.required]),
|
---|
36 | patnikId: new FormControl(null, []),
|
---|
37 | telefon: new FormControl(null, []),
|
---|
38 | ime: new FormControl(null, []),
|
---|
39 | adresa: new FormControl(null, []),
|
---|
40 | kontrolaId: new FormControl(this.controlId, []),
|
---|
41 | })
|
---|
42 | private refreshFines$ = new Subject<void>();
|
---|
43 |
|
---|
44 | constructor(private route: ActivatedRoute, private router: Router,
|
---|
45 | private controlsService: ControlsService,
|
---|
46 | private userService: UserService,
|
---|
47 | private fineService: FineService) {
|
---|
48 | }
|
---|
49 |
|
---|
50 | ngOnInit(): void {
|
---|
51 | this.controlId = +this.route.snapshot.paramMap.get('id')!!
|
---|
52 | this.refreshFines$.pipe(
|
---|
53 | switchMap(() => this.controlsService.getControlInfo(this.controlId))
|
---|
54 | ).subscribe({
|
---|
55 | next: response => {
|
---|
56 | this.fines = response
|
---|
57 | }
|
---|
58 | })
|
---|
59 | this.refreshFines$.next()
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | onClick() {
|
---|
64 | this.userService.getAllPassengers().subscribe(
|
---|
65 | res => {
|
---|
66 | this.passengers = res;
|
---|
67 | }
|
---|
68 | )
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected readonly onsubmit = onsubmit;
|
---|
72 |
|
---|
73 | onSubmit($event: any) {
|
---|
74 | console.log($event)
|
---|
75 | console.log(this.fineForm.value)
|
---|
76 | this.fineService.createFine(this.fineForm.value as FineRequest).subscribe({
|
---|
77 | next: res => {
|
---|
78 | console.log(res)
|
---|
79 | this.refreshFines$.next()
|
---|
80 | }
|
---|
81 | })
|
---|
82 | }
|
---|
83 | }
|
---|