[04008ae] | 1 | import { Component, OnInit } from '@angular/core';
|
---|
| 2 | import { Router } from '@angular/router';
|
---|
| 3 | import { VehicleDetailsService } from 'src/app/VehicleDetailsEntity/vehicle-details.service';
|
---|
| 4 | import { VehicleService } from '../vehicle.service';
|
---|
| 5 | import { vehicleModelInitializer } from '../vehicleModelInitializer';
|
---|
| 6 | import { cloneDeep } from 'lodash';
|
---|
| 7 | import { Vehicle } from '../vehicleModelDefinition';
|
---|
| 8 | import { VehicleDetails } from 'src/app/VehicleDetailsEntity/VehicleDetailsModelDefinition';
|
---|
| 9 | import { ToastrService } from 'ngx-toastr';
|
---|
| 10 | import { 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 | })
|
---|
| 17 | export 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 | }
|
---|