import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Output, ViewChild, Input, ViewContainerRef } from '@angular/core'; import { AppConsts } from '@shared/AppConsts'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TagTypeServiceProxy, UpdateTagTypeInput, LocatorServiceProxy, MoveOrder} from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; import * as _ from 'lodash'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment'; import { MapFlyOutComponent } from '@app/shared/layout/flyout/map/map-flyout.component'; @Component({ selector: 'moveOrder', templateUrl: './move-order.component.html' }) export class MoveOrderModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', {static: false}) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); @ViewChild('mapFlyOutComponent', {static: false}) mapFlyOutComponent: MapFlyOutComponent; @Input() filters: { locationFilter: number; statusFilter: number; typeFilter: number; startDate: moment.Moment; endDate: moment.Moment; } = {}; @Input() markers: marker[] = []; @Input() selection: Array = []; orderId:number; active = false; saving = false; movetoRouteId:number; data: Array = []; move: MoveOrder = new MoveOrder(); // tagType: UpdateTagTypeInput = new UpdateTagTypeInput(); constructor( injector: Injector, private _locatorAppService: LocatorServiceProxy, private viewContainerRef: ViewContainerRef ) { super(injector); } getParentComponent() { return this.viewContainerRef[ '_data' ].componentView.component.viewContainerRef[ '_view' ].component } show(orderId): void { console.log(orderId); this.orderId = orderId; this.getOption(orderId); this.active = true; this.modal.show(); } getOption(orderId){ console.log(this.selection); let x = 0; this._locatorAppService.getRouteListDetail(orderId, moment(this.filters.startDate), moment(this.filters.endDate), this.filters.locationFilter) .subscribe(result=>{ this.data = []; result.items.forEach(item =>{ this.data.push(item); this.selection.forEach(marker=>{ if(item.routeId == marker.routeId){ this.data[x].color = marker.color; } }) x++; }); console.log(this.data); }); } onShown(): void { this.movetoRouteId = undefined; // document.getElementById('Code').focus(); } save(): void { this.saving = true; this.move.orderId = this.orderId; this.move.routeId = this.movetoRouteId; this._locatorAppService.moveOrder(this.move) .pipe(finalize(() => { this.saving = false; })) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); this.getParentComponent().mapFlyOutComponent.plotRouteMarker(); }); this.close(); } close(): void { this.active = false; this.modal.hide(); } } interface marker { lat: number; lng: number; label?: string; draggable: boolean; icon?: { path: string; fillColor: string; fillOpacity: number; strokeColor: string; strokeWeight: number; scale: number; labelOrigin: { x: number; y: number; } }; driverName: string; orderId:string; eta:string; color?:string; companyName?:string; geocode?:number; routeId?:number; }