import { Component, Injector, OnInit, OnDestroy, ViewChild, AfterViewChecked, AfterViewInit, AfterContentInit, ViewEncapsulation, ElementRef, Directive, Input, EventEmitter, Output } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TenantDashboardServiceProxy, GetLocationDataOutput, GetRouteTypeDataOutput, GetLocationRouteDataCompletedOutput, LocationServiceProxy, LocationListDto, LocationNameDto } from '@shared/service-proxies/service-proxies'; import { WidgetComponentBase } from '../widget-component-base'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { ModalDirective } from 'ngx-bootstrap'; import { ActivatedRoute, Router } from '@angular/router'; import * as jquery from 'jquery'; declare var $: any; @Component({ selector: 'app-widget-route-location', templateUrl: './widget-route-location.component.html', animations: [appModuleAnimation()], styleUrls: ['./widget-route-location.component.css'] }) export class WidgetRouteLocationComponent extends WidgetComponentBase implements OnInit, OnDestroy { @ViewChild('fullScreen', { static: false }) divRef; locationResponse: any; routeCompleted: any[] = []; locationRouteResponse: GetLocationDataOutput = new GetLocationDataOutput(); locationRouteResponseCompleted: any; routeTypes: any; locationTime: any; locaitonAmPm: any; lastSchedAmPm: any; lastSched: any; lastschedTime: any; nextArrivalTime: any; nextArrivalTimeAmPm: any; nextArrivalSample: any; isHidden = true; nextArrivalTimeDef: any; nextArrivalTimeAmPmDef: any; initialVal: any; initialDate = ""; isfullscreen = false; routeTypeId = undefined; routeTypeIds: any; routeTypeName: any; interval: any; completion: any; completedRoutes = 0; routesPending: any; timerId: 300000; minutesFilter = 0; refrehText = '5 mins'; refreshDefaultVal = 0; RouteDate = new Date(); showSettings = true; showTypes = false; cfHeight: any; dateInput: any; loading = false; locations: LocationNameDto[] = []; txtLocation: any; laboratories: any; txtLaboratory: any; labTxt: any; labId: any; actionType: any; actionTxt: any; hideType = true; showAfter = false; showAfterLastSched = false; totalOnRoute = 0; totalCompleted = 0; constructor(injector: Injector, private _tenantDashboardService: TenantDashboardServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _router: Router, private route: ActivatedRoute ) { super(injector); /* this.route.params.subscribe(params => { });*/ //this.openFullscreen(); /* var canvas = document.getElementById("signature"); var signaturePad = new SignaturePad(canvas); $('#clear-signature').on('click', function(){ signaturePad.clear(); });*/ $('nav').attr('style', 'display: none !important'); $( "#fs" ).hide(); document.addEventListener('fullscreenchange', exitHandler); function exitHandler() { if (!document.fullscreenElement) { ///fire your event this.cfHeight = { 'padding-top': '20px' }; this.showTypes = false; this.isfullscreen = false; this.isHidden = true; this.locationResponse = null; this.locationRouteResponseCompleted = null; this.nextArrivalTime = null; this.nextArrivalTimeAmPm = null; this.nextArrivalSample = null; clearInterval(this.interval); $( "#fs" ).hide(); this.showAfter = false; this.showAfterLastSched = false; } } } /*$(document).ready(function($){ var canvas = document.getElementById("signature"); var signaturePad = new SignaturePad(canvas); $('#clear-signature').on('click', function(){ signaturePad.clear(); });*/ onShown(): void{ $('.kt-select2').select2(); } ngOnInit(): void { $('nav').attr('style', 'display: flex !important'); $( "#fs" ).hide(); //this.openFullscreen(); //this.subLocationFilter(); //this.subDateFilter(); if(this.routeTypeId == undefined) { this.routeTypeId = 0 } if(this.initialVal == undefined) { if(localStorage.getItem('operatingLocationId')!=undefined){ if (localStorage.getItem('operatingLocationId').search(',') > 0){ var array = localStorage.getItem('operatingLocationId').split(','); this.initialVal = array[0]; }else{ this.initialVal = localStorage.getItem('operatingLocationId'); } }else{ } } if(this.routeTypeName == undefined) { this.routeTypeName = "All"; } this.getLocations(); this.getRouteTypes(); this.getLaboratories(this.initialVal); $('.kt-select2').select2(); } showSetting() { this.showSettings = true; } showRouteTypes() { this.showTypes = true; this.cfHeight = { 'padding-top': '20px', }; } hideRouteTypes() { this.cfHeight = { 'padding-top': '20px' }; this.showTypes = false; } hideSetting() { this.showSettings = false; } setDate(newDate) { //console.log(newDate); this.dateInput = newDate; } getLocations() { //var result = document.getElementsByClassName("bs-datepicker-container"); //console.log(result); let defaultLoc = localStorage.getItem('operatingLocationId'); let that = this; this._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined) .subscribe( //function(response) { console.log("Success Response" + response)}, //function(error) { console.log("Error happened" + error)}, result => { that.locations = result; if(result!=null){ if(this.txtLocation == undefined) { if(localStorage.getItem('operatingLocationId')!=undefined){ if (localStorage.getItem('operatingLocationId').search(',') > 0){ var array = localStorage.getItem('operatingLocationId').split(','); this.initialVal = array[0]; }else{ this.initialVal = localStorage.getItem('operatingLocationId'); } }else{ this.txtLocation = result[0].id.toString(); } } } }); } getLaboratories(locationId: any) : void { this._tenantDashboardService.getLaboratoryData(locationId) .subscribe((data) => { this.laboratories = data; if(this.txtLaboratory == undefined) { if(data.length != 0) { this.txtLaboratory = data[0].contactId; } } }); } onOptionsSelected(value:string){ let locId = Number(value) this.getLaboratories(locId); } onOptionsSelectType(value:string){ let typeId = Number(value) if(typeId != 0) { this.hideType = false; } else { this.hideType = true; } } getRouteTypes(): void { this._tenantDashboardService .getRouteTypeData() .subscribe((data) => { this.routeTypes = data; }); } openFullscreen(): void { //this.showFullScreen = true; // Use this.divRef.nativeElement here to request fullscreen const elem = this.divRef.nativeElement; //var result = document.getElementsByClassName("bs-datepicker-container"); if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); } else if (elem.mozRequestFullScreen) { elem.mozRequestFullScreen(); } else if (elem.webkitRequestFullscreen) { elem.webkitRequestFullscreen(); } this.isfullscreen = true; } closeFullscreen() : void { const docWithBrowsersExitFunctions = document as Document & { mozCancelFullScreen(): Promise; webkitExitFullscreen(): Promise; msExitFullscreen(): Promise; }; if (docWithBrowsersExitFunctions.exitFullscreen) { docWithBrowsersExitFunctions.exitFullscreen(); } else if (docWithBrowsersExitFunctions.mozCancelFullScreen) { /* Firefox */ docWithBrowsersExitFunctions.mozCancelFullScreen(); } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */ docWithBrowsersExitFunctions.webkitExitFullscreen(); } else if (docWithBrowsersExitFunctions.msExitFullscreen) { /* IE/Edge */ docWithBrowsersExitFunctions.msExitFullscreen(); } this.cfHeight = { 'padding-top': '20px' }; this.showTypes = false; this.locationResponse = null; this.nextArrivalTime = null; this.nextArrivalTimeAmPm = null; this.nextArrivalSample = null; this.isfullscreen = false; this.isHidden = true; $( "#fs" ).hide(); this.showAfter = false; this.showAfterLastSched = false; } ngAfterViewInit(){ //this.openFullscreen(); $('.kt-select2').select2(); $('nav').attr('style', 'display: flex !important'); } getLocation = (id: any, typeId: any, date: any, contactId: any, actionType: any) => { this.interval; this.completedRoutes = 0; this.routeCompleted = []; this.locationResponse = null; this.locationRouteResponseCompleted = null; this.showAfter = false; this.showAfterLastSched = false; //console.log(this.initialDate); //this.spinnerService.show(); this.loading = true; this._tenantDashboardService .getLocationRouteData(id, typeId, date, contactId, actionType) .subscribe((data) => { if(data) { this.hideloaderGrid(); } this.locationResponse = data; //console.log(this.locationResponse.length); this.lastSched = 0 this.lastschedTime = 'TBD'; this.lastSchedAmPm = '' //this.nextArrivalTime = '12:00'; //this.nextArrivalTimeAmPm = 'AM'; let total = this.locationResponse.length; this.totalOnRoute = this.locationResponse.length; if(this.locationResponse.length != 0) { let last:any = this.locationResponse[this.locationResponse.length-1]; //let first:any = this.locationResponse[0]; this.lastSched = last.samples; //this.lastschedTime = last.target; var splitted = last.target.split(" ", 2); this.lastschedTime = splitted[0]; this.lastSchedAmPm = splitted[1]; for (let i = 0; i < this.locationResponse.length; i++) { if(this.locationResponse[i].samples != 0) { if(this.locationResponse[i].samples == this.locationResponse[i].samplesPickedUp) { this.locationResponse[i].sampleTextColor = '#48eb9a'; } } if(this.locationResponse[i].completionMinutes != 0) { let diffCompletionEta = this.locationResponse[i].completionMinutes - this.locationResponse[i].etaMinutes; let diffEtaCompletion = this.locationResponse[i].etaMinutes - this.locationResponse[i].completionMinutes; if(diffCompletionEta <= 15) { this.locationResponse[i].gridFillColor = 'rgba(72,235,154,0.5)'; } else if(diffCompletionEta > 15) { this.locationResponse[i].gridFillColor = 'rgba(249,102,121,0.7)'; this.locationResponse[i].gridTextColor = '#f96679'; this.locationResponse[i].sampleTextColor = '#f96679'; } } else { let diffLiveCurrent = this.locationResponse[i].liveEtaMinutes - this.locationResponse[i].currentTimeMinutes; let diffCurrentLive = this.locationResponse[i].currentTimeMinutes - this.locationResponse[i].liveEtaMinutes; if(!this.locationResponse[i].tommorow) { if(diffCurrentLive > 0) { if(diffCurrentLive <= 3) { this.locationResponse[i].gridFillColor = 'rgba(250,205,138,0.7)'; } else if(diffCurrentLive > 3 && diffCurrentLive <= 15) { this.locationResponse[i].gridFillColor = 'rgba(255,250,158,0.7)'; } } if(this.locationResponse[i].liveEtaMinutes < this.locationResponse[i].currentTimeMinutes) { this.locationResponse[i].gridTextColor = '#f96679'; } } } } } this._tenantDashboardService.getLocationRouteDataCompleted(id, typeId, date, contactId, actionType) .subscribe((a) => { this.locationRouteResponseCompleted = a; this.totalCompleted = this.locationRouteResponseCompleted.length; if(this.locationRouteResponseCompleted.length != 0) { for (let i = 0; i < this.locationRouteResponseCompleted.length; i++) { if(this.locationRouteResponseCompleted[i].samples != 0) { if(this.locationRouteResponseCompleted[i].samples == this.locationRouteResponseCompleted[i].samplesPickedUp) { this.locationRouteResponseCompleted[i].sampleTextColor = '#48eb9a'; } } if(this.locationRouteResponseCompleted[i].completionMinutes != 0) { let diffCompletionEta = this.locationRouteResponseCompleted[i].completionMinutes - this.locationRouteResponseCompleted[i].etaMinutes; let diffEtaCompletion = this.locationRouteResponseCompleted[i].etaMinutes - this.locationRouteResponseCompleted[i].completionMinutes; if(diffCompletionEta <= 15) { this.locationRouteResponseCompleted[i].gridFillColor = 'rgba(72,235,154,0.5)'; } else if(diffCompletionEta > 15) { this.locationRouteResponseCompleted[i].gridFillColor = 'rgba(249,102,121,0.7)'; this.locationRouteResponseCompleted[i].gridTextColor = '#fff'; this.locationRouteResponseCompleted[i].sampleTextColor = '#fff'; } } else { let diffLiveCurrent = this.locationRouteResponseCompleted[i].liveEtaMinutes - this.locationRouteResponseCompleted[i].currentTimeMinutes; let diffCurrentLive = this.locationRouteResponseCompleted[i].currentTimeMinutes - this.locationRouteResponseCompleted[i].liveEtaMinutes; if(!this.locationRouteResponseCompleted[i].tommorow) { if(diffCurrentLive > 0) { if(diffCurrentLive <= 3) { this.locationRouteResponseCompleted[i].gridFillColor = 'rgba(250,205,138,0.7)'; } else if(diffCurrentLive > 3 && diffCurrentLive <= 15) { this.locationRouteResponseCompleted[i].gridFillColor = 'rgba(255,250,158,0.7)'; } } if(this.locationRouteResponseCompleted[i].liveEtaMinutes < this.locationRouteResponseCompleted[i].currentTimeMinutes) { this.locationRouteResponseCompleted[i].gridTextColor = '#f96679'; } } } } } //Percentage let get = this; /*get.locationResponse.forEach(function(v, i) { if (v.completionMinutes != 0) {//test to see if the id is 3 get.completedRoutes++; get.routeCompleted.push(get.locationResponse[i]); } });*/ let totalRoutes = this.totalOnRoute + this.totalCompleted; let percent = (this.totalCompleted / totalRoutes) * 100 let percentPending = 0; if(totalRoutes != 0) { if(percent % 1 != 0) { this.completion = percent.toFixed(2); percentPending = 100 - percent this.routesPending = percentPending.toFixed(2); } else { this.completion = percent; percentPending = 100 - percent this.routesPending = percentPending; } } else { this.completion = 0; this.routesPending = 0; } }); this._tenantDashboardService .getLocationData(id, typeId, date, contactId, actionType) .subscribe((data) => { if(data) { this.hideloader(); } this.locationRouteResponse = data; var splitted = this.locationRouteResponse.locationCurrentTime.split(" ", 2); this.locationTime = splitted[0]; this.locaitonAmPm = splitted[1]; if(this.locationRouteResponse.nextArrivalTime == "") { this.nextArrivalTime = ""; this.nextArrivalTimeAmPm = ""; this.nextArrivalSample = null; } else { var splitNextArrival = this.locationRouteResponse.nextArrivalTime.split(" ", 2); this.nextArrivalTime = splitNextArrival[0]; this.nextArrivalTimeAmPm = splitNextArrival[1]; this.nextArrivalSample = this.locationRouteResponse.nextArrival; } }); this.runDelayed(()=>{ this.loading = false; $('nav').attr('style', 'display: flex !important'); }); }); } /*onNameChange = (id) => { this.runDelayed(()=>{ if(this.routeTypeId == undefined) { this.routeTypeId = 0 } this.initialVal = id; this.getLocation(id, this.routeTypeId, this.initialDate); }); } onDateChange = (date) => { this.runDelayed(()=>{ if(this.routeTypeId == undefined) { this.routeTypeId = 0 } this.initialDate = date; this.getLocation(this.initialVal, this.routeTypeId, date); }); }*/ submitSettings() : void { this.labId = Number((document.getElementById('txtLaboratory')).value); this.cfHeight = { 'padding-top': '20px' }; if(this.labId == 0) { this.message.warn('','Please select laboratory'); } else { $('nav').attr('style', 'display: none !important'); $( "#fs" ).show(); this.minutesFilter = Number((document.getElementById('refreshMin')).value) != 0 ? Number((document.getElementById('refreshMin')).value) : undefined; this.initialVal = Number((document.getElementById('txtLocation')).value); this.actionType = Number((document.getElementById('type')).value); let routeTypeTxt = $( "#routeType option:selected" ).text(); this.routeTypeName = routeTypeTxt.split(' ').join(', ') this.routeTypeIds = $("#routeType").val(); if(this.routeTypeIds.length == 0) { this.routeTypeName = 'All' } this.actionTxt = $( "#type option:selected" ).text(); //$(your selector).attr('value2') let value = this.laboratories.find(i => i.contactId === this.labId); this.labTxt = value.name; //console.log(this.labTxt); this.initialDate = this.dateInput; this.refreshDefaultVal = this.minutesFilter; this.locationResponse = null; this.nextArrivalTime = null; this.nextArrivalTimeAmPm = null; this.nextArrivalSample = null; this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); clearInterval(this.interval); if(this.interval == undefined) { this.interval = setInterval(() => { this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); }, 300000); } if(this.minutesFilter == undefined) { this.refreshDefaultVal = 0; this.refrehText = '5 mins'; this.interval = setInterval(() => { this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); }, 300000); } else if(this.minutesFilter == 1) { this.refrehText = '10 mins'; this.interval = setInterval(() => { this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); }, 600000); } else if(this.minutesFilter == 2) { this.refrehText = '20 mins'; this.interval = setInterval(() => { this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); }, 1200000); } else if(this.minutesFilter == 3) { this.refrehText = '25 mins'; this.interval = setInterval(() => { this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); }, 1500000); } else if(this.minutesFilter == 4) { this.refrehText = '30 mins'; this.interval = setInterval(() => { this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); }, 1800000); } //this.getLocation(this.initialVal, this.routeTypeId, this.dateInput); //this.openFullscreen(); this.isHidden = false; this.isfullscreen == true const elem = this.divRef.nativeElement; //var result = document.getElementsByClassName("bs-datepicker-container"); //console.log(elem.requestFullscreen); if (elem.requestFullscreen) { elem.requestFullscreen(); $('nav').attr('style', 'display: none !important'); } else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); $('nav').attr('style', 'display: none !important'); } else if (elem.mozRequestFullScreen) { elem.mozRequestFullScreen(); $('nav').attr('style', 'display: none !important'); } else if (elem.webkitRequestFullscreen) { elem.webkitRequestFullscreen(); $('nav').attr('style', 'display: none !important'); } //this.isfullscreen = true; } //this.showSettings = false; } /*refresh() { this.ngOnInit(); //this.dashboardControl.reloadData(); this.minutesFilter = Number((document.getElementById('refreshMin')).value) != 0 ? Number((document.getElementById('refreshMin')).value) : undefined; clearInterval(this.interval); if(this.minutesFilter == undefined) { this.refrehText = '5 mins'; this.interval = setInterval(() => { this.ngOnInit(); }, 300000); } else if(this.minutesFilter == 1) { this.refrehText = '10 mins'; this.interval = setInterval(() => { this.ngOnInit(); }, 600000); } else if(this.minutesFilter == 2) { this.refrehText = '20 mins'; this.interval = setInterval(() => { this.ngOnInit(); }, 1200000); } else if(this.minutesFilter == 3) { this.refrehText = '25 mins'; this.interval = setInterval(() => { this.ngOnInit(); }, 1500000); } else if(this.minutesFilter == 4) { this.refrehText = '30 mins'; this.interval = setInterval(() => { this.ngOnInit(); }, 1800000); } }*/ refreshPage() { //this.spinnerService.show(); //console.log(this.spinnerService); this.locationResponse = null; this.locationRouteResponseCompleted = null; this.nextArrivalTime = null; this.nextArrivalTimeAmPm = null; this.nextArrivalSample = null; this.showAfter = false; this.showAfterLastSched = false; this.runDelayed(()=>{ this.getLocation(this.initialVal, this.routeTypeIds, this.initialDate, this.labId, this.actionType); }); } filterRouteType() { this.ngOnInit(); } /*subLocationFilter() { abp.event.on('app.dashboardFilters.locationFilter.onNameChange', this.onNameChange); } unSubLocationFilter() { abp.event.off('app.dashboardFilters.locationFilter.onNameChange', this.onNameChange); } subDateFilter() { abp.event.on('app.dashboardFilters.dateFilter.onNameChange', this.onDateChange); } unSubDateFilter() { abp.event.off('app.dashboardFilters.dateFilter.onNameChange', this.onDateChange); }*/ hideloader() { /*document.getElementById('currentTime') .style.display = 'none'; document.getElementById('inboundTotal') .style.display = 'none'; document.getElementById('totalInHouse') .style.display = 'none'; document.getElementById('grandTotal') .style.display = 'none'; document.getElementById('completion') .style.display = 'none'; document.getElementById('routesPending') .style.display = 'none'; document.getElementById('nextArrival') .style.display = 'none';*/ this.showAfter = true; } /*hideloaderLastSched() { document.getElementById('loadingLastSched') .style.display = 'none'; }*/ hideloaderGrid() { /*document.getElementById('lastSched') .style.display = 'none';*/ this.showAfterLastSched = true; } ngOnDestroy(): void { //this.unSubLocationFilter(); //this.unSubDateFilter(); clearInterval(this.interval); } }