ARAI/arai-frontend/src/app/case-input/case-input.component.ts

50 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-03-09 13:08:35 +01:00
import { Component } from '@angular/core';
2024-03-09 14:05:08 +01:00
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
2024-03-09 13:08:35 +01:00
import { MatInputModule } from '@angular/material/input'
import { MatCheckboxModule } from '@angular/material/checkbox'
2024-03-09 14:05:08 +01:00
import { MatButtonModule } from '@angular/material/button'
import { BackendService } from '../backend.service';
2024-03-09 21:58:31 +01:00
import { GenericRequest, ReturnResponse, UserInputRequest, userInput } from '../requests-responses';
2024-03-09 21:09:32 +01:00
import { Router } from '@angular/router';
2024-03-09 21:58:31 +01:00
import { KosztaService } from '../koszta.service';
2024-03-09 13:08:35 +01:00
@Component({
selector: 'app-case-input',
standalone: true,
imports: [
MatInputModule,
MatCheckboxModule,
ReactiveFormsModule,
2024-03-09 14:05:08 +01:00
MatButtonModule
2024-03-09 13:08:35 +01:00
],
templateUrl: './case-input.component.html',
styleUrl: './case-input.component.scss'
})
export class CaseInputComponent {
2024-03-09 14:05:08 +01:00
userInputForm: FormGroup;
userInput: userInput | null = null;
2024-03-09 21:58:31 +01:00
constructor(private fb: FormBuilder, private readonly backendService: BackendService, private readonly router: Router, private readonly kosztaService: KosztaService) {
2024-03-09 14:05:08 +01:00
this.userInputForm = this.fb.group({
generic_input: [''],
2024-03-09 21:09:32 +01:00
trial_value: [],
2024-03-09 14:05:08 +01:00
location: [''],
experts_called: [false],
witnesses_called: [false]
});
}
async onSubmit() {
this.userInput = this.userInputForm.value;
2024-03-09 14:05:08 +01:00
if(this.userInput !== null) {
2024-03-09 21:58:31 +01:00
const result = await this.backendService.sendMessage(new UserInputRequest(this.userInput)) as ReturnResponse;
this.kosztaService.czas = String(result.response_data.first.time_of_trial);
this.kosztaService.koszta = String(result.response_data.first.cost_of_trial);
2024-03-09 21:09:32 +01:00
this.router.navigate(['koszt']);
} else {
console.error(`caseInputComponent, onSubmit, userInput is null!`)
2024-03-09 14:05:08 +01:00
}
}
2024-03-09 13:08:35 +01:00
}