import { Component, ViewChild, Injector, ElementRef, Output, EventEmitter } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { VehicleLocationServiceProxy, UpdateVehicleLocationInput, VehicleLocationListDto, VehicleServiceProxy, VehicleListDto } from '@shared/service-proxies/service-proxies'; import { LocationListDto, LocationServiceProxy } from '@shared/service-proxies/service-proxies'; import * as _ from 'lodash'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import * as jquery from 'jquery'; @Component({ selector: 'editVehicleLocationModal', templateUrl: './edit-vehicle-location-modal.component.html' }) export class EditVehicleLocationModalComponent extends AppComponentBase { @Output() modalSave: EventEmitter = new EventEmitter(); @ViewChild('modal', { static: false }) modal: ModalDirective; @ViewChild('nameInput', { static: false }) nameInput: ElementRef; vehicleLocation: UpdateVehicleLocationInput = new UpdateVehicleLocationInput(); locations: LocationListDto[] = []; vehicles: VehicleListDto[] = []; locationInput: { id: number; name: string; }; txtLocation: any; locationId: number; vehicleId: number; active: boolean = false; saving: boolean = false; constructor( injector: Injector, private _vehicleLocationService: VehicleLocationServiceProxy, private _locationService: LocationServiceProxy, private _vehicleService: VehicleServiceProxy ) { super(injector); } show(vehicleLocationId: any, vehicleId: any): void { this.active = true; this._vehicleLocationService.getVehicleLocation(vehicleLocationId, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined).subscribe((result) => { this.vehicleLocation.id = result.items[0]['id']; this.vehicleId = result.items[0].vehicle.id; this.locationId = result.items[0].location.id; // this._locationService.getLocation(result.items[0]['locationId'], undefined, undefined, undefined, undefined, undefined, undefined).subscribe((resultLocations) => { // this.txtLocation = resultLocations.items[0]; // this.vehicleLocation.locationId = resultLocations.items[0]['id']; // this.vehicleLocation.vehicleId = vehicleId; // console.log(this.vehicleLocation); // }); this.modal.show(); }); } ngOnInit(){ } onShown(): void { // this.nameInput.nativeElement.focus(); let maxcount = 1000; this.showAllLocation(maxcount); this.showAllVehicle(maxcount); $('.kt-select2').select2(); } showAllLocation(maxcount): void { this.active = true; this._locationService.getLocation(undefined, undefined, undefined, undefined, undefined, maxcount, undefined).subscribe((result) => { this.locations = result.items; }); } showAllVehicle(maxcount): void { this.active = true; this._vehicleService.getVehiclePaged(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, maxcount, undefined).subscribe((result) => { this.vehicles = result.items; }); } save(): void { this.saving = true; //this.vehicleLocation.locationId = this.txtLocation.id; this.vehicleLocation.locationId = Number((document.getElementById('txtLocation')).value); this.vehicleLocation.vehicleId = Number((document.getElementById('txtVehicle')).value); this._vehicleLocationService.updateVehicleLocation(this.vehicleLocation) .subscribe(() => { //console.log(this.vehicleLocation); this.notify.info(this.l('SavedSuccessfully')); console.log(this.vehicleLocation); this.close(); this.modalSave.emit(this.vehicleLocation); }); this.saving = false; } close(): void { this.modal.hide(); this.active = false; } }