import { Component, ViewEncapsulation, Injector, OnInit, DoCheck, ViewChild, Input, AfterViewInit,ViewContainerRef } from "@angular/core"; import { appModuleAnimation } from "@shared/animations/routerTransition"; import { AppComponentBase } from "@shared/common/app-component-base"; import { Router, ActivatedRoute } from "@angular/router"; import * as moment from 'moment'; import { LocationServiceProxy, LocationListDto, LocatorServiceProxy,MoveOrder } from "@shared/service-proxies/service-proxies"; import { MapFlyOutComponent } from "@app/shared/layout/flyout/map/map-flyout.component"; import { empty } from "rxjs"; import { LaboratoryMapFlyOutComponent } from "@app/shared/layout/flyout/map/laboratory/laboratory-map-flyout.component"; import { finalize } from 'rxjs/operators'; declare var $: any; @Component({ templateUrl: './locator.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['./locator.component.less'] }) export class LocatorComponent extends AppComponentBase implements OnInit, AfterViewInit{ @Input() markers: marker[] = []; @Input() latestLog: marker[] = []; @Input() delmarkers: marker[] = []; @Input() driverP: marker[] = []; chosenDate: Date; locationId: number; locationName: string; reload = true; route: Array = []; routeIds: Array = []; routeSel: Array = []; active: number; activeF: number; activeD: number; locations: LocationListDto[] = []; filters: { locationFilter: number; statusFilter: number; typeFilter: number; startDate: Date; endDate: Date; } = {}; selection: Array = []; todaysDate = moment().format('MM/DD/YYYY'); zoom: number = 14; // initial center position for the map lat: number = 34.044971; lng: number = -118.291243; map: any; pin: { path: string; fillColor: string; fillOpacity: number; strokeColor: string; strokeWeight: number; scale: number; labelOrigin: { x: number; y: number; }; }; laboratoryMapFeatureEdition: boolean = false; move: MoveOrder = new MoveOrder(); @ViewChild('laboratoryMapFlyOutComponent', {static: false}) laboratoryMapFlyOutComponent: LaboratoryMapFlyOutComponent; @ViewChild('mapFlyOutComponent', {static: false}) mapFlyOutComponent: MapFlyOutComponent; orderId:number; locationFilter: number; noRouteId:string; saving = false; movetoRouteId:number; data: Array = []; ata: any[]; isShow = true; locatorDate: moment.Moment = moment(); constructor( injector: Injector, private router: Router, private _locationServiceProxy: LocationServiceProxy, private activatedRoute: ActivatedRoute, private _locatorAppService: LocatorServiceProxy, private viewContainerRef: ViewContainerRef ) { super(injector); this.laboratoryMapFeatureEdition = abp.features.isEnabled('App.LaboratoryMapFilter'); this.chosenDate = new Date(Date.now()); } getParentComponent() { return this.viewContainerRef[ '_data' ].componentView.component.viewContainerRef[ '_view' ].component } ngOnInit(): void { this.activatedRoute.paramMap.subscribe(params => { this.route = [+params.get("id")]; this.active = 1; this.activeD = 1; this.activeF = 1; this.routeIds = [+params.get('rid')]; this.routeSel = [+params.get('rid')]; }); if(localStorage.getItem('loadDate') == null) { $("#LocatorDate").val(moment(this.chosenDate).format('MM/DD/YYYY')); } else { $("#LocatorDate").val(moment(localStorage.getItem('loadDate')).format('MM/DD/YYYY')); } if(localStorage.getItem('operatingLocationId') != null) { this.locationId = parseInt(localStorage.getItem('operatingLocationId')); } let that = this; this.getLocationsOnLoad().then(function(result){ that.spinnerService.hide(); }); } ngAfterViewInit(): void { this.mapFlyOutComponent.routeClick(); // if(this.routeSel.length != 0){ // this.showFlyOut(1); // } } getLocationsOnLoad(id = undefined) { let that = this; return new Promise(function (resolve, reject) { that._locationServiceProxy.getLocation(id, undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { // that.filters.locationFilter = result.items["0"].id; that.locationName = result.items['0']['name']; resolve(result.items["0"].id); }); }); } // ngDoCheck() { // // ... // console.log(this.filters); // } onChange(event){ console.log(event); } // showFlyOut(clickby): void { // this.filters.startDate = moment(this.locatorDate).toDate(); // if(clickby == 1){ // console.log("test1") // $("#getting_started_toggle").click(); // if(this.laboratoryMapFeatureEdition){ // this.laboratoryMapFlyOutComponent.unselectAll(); // this.laboratoryMapFlyOutComponent.loadFlyOut(); // }else{ // this.mapFlyOutComponent.unselectAll(); // this.mapFlyOutComponent.loadFlyOut(); // } // }else{ // console.log("test2") // if(this.laboratoryMapFeatureEdition){ // this.laboratoryMapFlyOutComponent.loadFlyOut(); // }else{ // this.mapFlyOutComponent.loadFlyOut(); // } // } // } showFlyOut(): void { //this.filters.startDate = moment(this.locatorDate).toDate(); if(this.laboratoryMapFeatureEdition){ this.laboratoryMapFlyOutComponent.loadFlyOut(); }else{ this.mapFlyOutComponent.loadFlyOut(); } } mapReady(event?: any) { this.map = event; this.markers = []; this.latestLog = []; this.delmarkers = []; this.driverP = []; } clickedMarker(label: string, index: number) { } recenterMap(lt, lg){ this.lat = lt; this.lng = lg; this.zoom = 22; } getOption(orderId){ let x = 0; this._locatorAppService.getRouteListDetail(orderId, moment(this.filters.startDate), moment(this.filters.startDate), 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++; }); }); } save(): void { if(this.movetoRouteId !=null) { 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.getParentComponent().mapFlyOutComponent.plotRouteMarker(); }); } else{ this.notify.error(this.l('Please select Route Id first.'),('Move Order')); // this.isShow = !this.isShow; // this.noRouteId = "Please select Route Id first."; } } getLocation(Id){ this.locations.forEach((x) => { if (x.id == Id) { this.locationName = x.name; } }); } } // just an interface for type safety. 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; }