source: bus-n-go-pavel-216049/bus-n-go-frontend/src/app/components/controls/control/control.component.ts

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import {Component, OnInit} from '@angular/core';
2import {ActivatedRoute, Router} from "@angular/router";
3import {ControlsService} from "../../../services/controls/controls.service";
4import {FineResponse} from "../../../model/responses/FineResponse";
5import {MatInputModule} from '@angular/material/input';
6import {MatFormFieldModule} from '@angular/material/form-field';
7import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
8import {MatOption} from "@angular/material/core";
9import {MatSelect} from "@angular/material/select";
10import {UserService} from "../../../services/user/user.service";
11import {UserResponse} from "../../../model/responses/UserResponse";
12import {MatButton} from "@angular/material/button";
13import {MatCheckbox} from "@angular/material/checkbox";
14import {FineRequest} from "../../../model/requests/FineRequest";
15import {FineService} from "../../../services/fine/fine.service";
16import {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})
27export 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}
Note: See TracBrowser for help on using the repository browser.