import { Component, ViewEncapsulation, Injector, OnInit, DoCheck, ViewChild, Input } 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 } from "@shared/service-proxies/service-proxies"; import { MapFlyOutComponent } from "@app/shared/layout/flyout/map/map-flyout.component"; import { empty } from "rxjs"; declare var $: any; @Component({ templateUrl: './locator.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class LocatorComponent extends AppComponentBase implements OnInit{ todaysDate: Date; @Input() markers: marker[] = []; route: Array = []; active: number; locations: LocationListDto[] = []; filters: { locationFilter: number; statusFilter: number; typeFilter: number; startDate: Date; endDate: Date; } = {}; constructor( injector: Injector, private router: Router, private _locationServiceProxy: LocationServiceProxy, private activatedRoute: ActivatedRoute, ) { super(injector); this.todaysDate = new Date(Date.now()); this.filters.startDate = this.todaysDate; this.filters.endDate = this.todaysDate; } 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; }) let that = this; this.todaysDate = new Date(Date.now()); this.spinnerService.show(); this.getLocationsOnLoad().then(function(result){ if(that.route[0] != 0){ $('#map_datepicker .form-control').val( moment(that.filters.startDate).format('YYYY-MM-DD') + ' / ' + moment(that.filters.endDate).format('YYYY-MM-DD')); }else{ $('#map_datepicker .form-control').val( moment(that.todaysDate).format('YYYY-MM-DD') + ' / ' + moment(that.todaysDate).format('YYYY-MM-DD')); } $('#hiddenStartDateMap').val(that.filters.startDate); $('#hiddenEndDateMap').val(that.filters.endDate); that.spinnerService.hide(); }); $('#map_datepicker').daterangepicker({ buttonClasses: ' btn', applyClass: 'btn-primary', cancelClass: 'btn-secondary' }, function(start, end, label) { $('#map_datepicker .form-control').val( start.format('YYYY-MM-DD') + ' / ' + end.format('YYYY-MM-DD')); $('#hiddenStartDateMap').val(start.format('YYYY-MM-DD')); $('#hiddenEndDateMap').val(end.format('YYYY-MM-DD')); that.filters.startDate = $('#hiddenStartDateMap').val(); that.filters.endDate = $('#hiddenEndDateMap').val(); }); // $("#locationSelectInputMap").val(that.filters.locationFilter); $('#locationSelectInputMap').on('change', function(){ $("#locationSelectInputMap").val($(this).val()); that.filters.locationFilter = $("#locationSelectInputMap").val(); }); } getLocationsOnLoad() { let that = this; return new Promise(function(resolve, reject){ that._locationServiceProxy.getLocation(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); } } // 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; }