source: WineTrackerFinal/WineTrackerUI/WineTracker/src/app/VehicleEntity/vehicle-create/vehicle-create.component.ts@ 04008ae

main
Last change on this file since 04008ae was 04008ae, checked in by Nikola Mishevski <Nikola.Mishevski@…>, 6 days ago

WineTracker UI Added to Git

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { Router } from '@angular/router';
3import { VehicleDetailsService } from 'src/app/VehicleDetailsEntity/vehicle-details.service';
4import { VehicleService } from '../vehicle.service';
5import { vehicleModelInitializer } from '../vehicleModelInitializer';
6import { cloneDeep } from 'lodash';
7import { Vehicle } from '../vehicleModelDefinition';
8import { VehicleDetails } from 'src/app/VehicleDetailsEntity/VehicleDetailsModelDefinition';
9import { ToastrService } from 'ngx-toastr';
10import { ShowErrorToaster, ShowSuccessToaster } from 'src/assets/ErrorHandler';
11
12@Component({
13 selector: 'app-vehicle-create',
14 templateUrl: './vehicle-create.component.html',
15 styleUrls: ['./vehicle-create.component.scss']
16})
17export class VehicleCreateComponent implements OnInit {
18 constructor(private vehicleService: VehicleService, private vehicleDetailsService: VehicleDetailsService, private router: Router, private toastr: ToastrService) { }
19
20 disableVehicle: boolean = true;
21 vehicle: Vehicle = cloneDeep(vehicleModelInitializer.createVehicle)
22 vehicleDetails: VehicleDetails[] = [];
23
24 ngOnInit(): void {
25 this.getVehicleDetails();
26 }
27
28 insertVehicle(event: string): void{
29 event != "" ? this.disableVehicle = false : this.disableVehicle = true
30 }
31
32 createVehicle(): void{
33 this.vehicleService.createVehicle(this.vehicle).subscribe({
34 next: (createdVehicle) => {
35 this.router.navigate(['/vehicle'])
36 ShowSuccessToaster(this.toastr)
37 },
38 error: (response) => ShowErrorToaster(this.toastr, response)
39 });
40 }
41
42 getVehicleDetails(){
43 this.vehicleDetailsService.getAllVehicleDetails().subscribe({
44 next: (vehicleDetails) => this.vehicleDetails = vehicleDetails,
45 error: (response) => ShowErrorToaster(this.toastr, response)
46 });
47 }
48}
Note: See TracBrowser for help on using the repository browser.