import { Component, ViewEncapsulation, Injector, OnInit, DoCheck, ViewChild, Input, AfterViewInit } 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 } 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"; 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[] = []; 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; @ViewChild('laboratoryMapFlyOutComponent', {static: false}) laboratoryMapFlyOutComponent: LaboratoryMapFlyOutComponent; @ViewChild('mapFlyOutComponent', {static: false}) mapFlyOutComponent: MapFlyOutComponent; data: any[]; locatorDate: moment.Moment = moment(); constructor( injector: Injector, private router: Router, private _locationServiceProxy: LocationServiceProxy, private activatedRoute: ActivatedRoute, private _locatorAppService: LocatorServiceProxy, ) { super(injector); this.laboratoryMapFeatureEdition = abp.features.isEnabled('App.LaboratoryMapFilter'); // this.todaysDate = moment(); } ngOnInit(): void { this.activatedRoute.paramMap.subscribe(params => { this.filters.locationFilter = +params.get("location"); this.filters.startDate = new Date(params.get("dateStart")); this.filters.endDate = new Date(params.get("dateEnd")); this.route = [+params.get("id")]; this.active = 1; this.activeD = 1; this.activeF = 1; this.routeIds = [+params.get('rid')]; this.routeSel = [+params.get('rid')]; console.log(params); }); let that = this; this.spinnerService.show(); if(that.route[0] != 0){ this.locatorDate = moment(this.filters.startDate); } this.getLocationsOnLoad().then(function(result){ that.spinnerService.hide(); }); $("#locationSelectInputMap").val(that.filters.locationFilter); $('#locationSelectInputMap').on('change', function(){ $("#locationSelectInputMap").val($(this).val()); that.filters.locationFilter = $("#locationSelectInputMap").val(); }); } ngAfterViewInit(): void { this.mapFlyOutComponent.routeClick(); } getLocationsOnLoad() { let that = this; return new Promise(function(resolve, reject){ that._locationServiceProxy.getLocation(undefined, undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { $('#locationSelectInputMap').select2(); that.locations = result.items; if(that.filters.locationFilter != 0){ $("#locationSelectInputMap").val(that.filters.locationFilter); }else{ that.filters.locationFilter = result.items[0].id; $("#locationSelectInputMap").val(result.items[0].id); 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){ $("#getting_started_toggle").click(); if(this.laboratoryMapFeatureEdition){ this.laboratoryMapFlyOutComponent.unselectAll(); this.laboratoryMapFlyOutComponent.loadFlyOut(); }else{ this.mapFlyOutComponent.unselectAll(); this.mapFlyOutComponent.loadFlyOut(); } }else{ 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; console.log('pasokpasok'); 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++; }); }); } } // 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; }