import { Injector, Component, ViewChild, AfterViewInit, HostBinding, ElementRef, OnInit, Input, ViewContainerRef } from "@angular/core"; import { AppComponentBase } from "@shared/common/app-component-base"; import { Router } from "@angular/router"; import { TabsetComponent } from "ngx-bootstrap"; import * as moment from 'moment-timezone'; import { CurrentUserProfileEditDto, OrderTypesServiceProxy, MobileAppVersionServiceProxy, ControllerRouteServiceProxy, LocatorServiceProxy, RouteTypesServiceProxy, RouteDefinitionsServiceProxy, GetManagerListDto, UserPreferenceInput, UserPreferencesServiceProxy, LocationServiceProxy } from '@shared/service-proxies/service-proxies'; import { XmlHttpRequestHelper } from '@shared/helpers/XmlHttpRequestHelper'; import { AppConsts } from '@shared/AppConsts'; import { AppSessionService } from "@shared/common/session/app-session.service"; import { xor } from "lodash"; @Component({ selector: 'controllerHeaderFlyoutComponent', templateUrl: 'controller-header-flyout.component.html', // animations: [appModuleAnimation()], styleUrls: ['controller-header-flyout.component.less'], providers: [MobileAppVersionServiceProxy] }) export class ControllerHeaderFlyoutComponent extends AppComponentBase implements OnInit, AfterViewInit { @HostBinding('id') id = 'kt_quick_sidebar'; @HostBinding('class') classes = 'kt-quick-panel'; @HostBinding('attr.mQuickSidebarOffcanvas') @HostBinding('style.overflow') styleOverflow: any = 'hidden'; mQuickSidebarOffcanvas: any; showLocationIcon: boolean = false; showPackageTypeIcon: boolean = false; showFleetIcon: boolean = false showDriverIcon: boolean = false showContactsIcon: boolean = false showCorporateIdentity: boolean = false showAccountsIcon = false hideEmpty: boolean = false; hideCompleted: boolean = true; hidePickedUp: boolean = true; rowsToShow: number = 50; todaysDate: Date; locationId: number; locations: any; filters: { locationFilter: number, statusFilter: number, typeFilter: number, startDate: Date, endDate: Date, orderStatusCode: string, orderType: string, osName: string, locationIds: number[] } = {}; searchFilters: { route: string, vehicleName: string, driverName: string, showCompletion: boolean, routeIds: Array, orderType: Array, deviceType: string, } = {}; timezone: string; currentRoutes: any; selRouteType: any; public userProfile: CurrentUserProfileEditDto; filterRouteData = []; filteredOrderTypes: any; filteredMobileVersion: any; @Input() routeIds: Array = []; @Input() routeSel: Array = []; @Input() orderTypeIds: Array = []; @Input() orderTypeSel: Array = []; @Input() routeTypeIds: Array = []; @Input() routeTypeSel: Array = []; @Input() managerIds: Array = []; @Input() managerSel: Array = []; @ViewChild('controllerTab', { static: false }) staticTabs: TabsetComponent; completed: boolean = false; showEmptyRoute: boolean = false; filterDate: any; filteredRouteTypes: any; getManagerListDto: GetManagerListDto[]; isEnabledLaboratory: boolean = false; flyoutDate: Date; appSession: AppSessionService; userPreferenceInput: UserPreferenceInput = new UserPreferenceInput; // dateRange: moment.Moment = moment(); editionLab: boolean; driverThreshold: any; driverThresholdId: any; defaultLocation:any; filteredLocations:any; isLocationEmpty:boolean = false; constructor( injector: Injector, private el: ElementRef, private router: Router, private viewContainerRef: ViewContainerRef, private _orderTypesServiceProxy: OrderTypesServiceProxy, private _mobileAppVersionServiceProxy: MobileAppVersionServiceProxy, private _locatorAppService: LocatorServiceProxy, private _routeTypesServiceProxy: RouteTypesServiceProxy, private _routeDefinitionServiceProxy: RouteDefinitionsServiceProxy, private _locationAppService: LocationServiceProxy, private _routeServiceProxy: ControllerRouteServiceProxy, private _userPreferenceServiceProxy: UserPreferencesServiceProxy, private _locationServiceProxy: LocationServiceProxy, ) { super(injector); this.todaysDate = new Date(Date.now()); this.currentRoutes = this.router.url; this.currentRoutes = this.currentRoutes.toString().split('/'); this.currentRoutes = this.currentRoutes[this.currentRoutes.length - 1]; this.isEnabledLaboratory = abp.features.isEnabled('App.ControllerRouteManagementFeature.RouteDetailsManagementFeature'); this.filters.locationIds = []; } _isOpen: boolean; _pinned = false; timeId: any; getParentComponent() { return this.viewContainerRef['_data'].componentView.component.viewContainerRef['_view'].component } ngOnInit(): void { this.timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(this.timeId); this.getFilter(); if (localStorage.getItem('loadDate') == null) { $(".controllerDatePicker1").val(moment(this.todaysDate).format('MM/DD/YYYY')); this.flyoutDate = moment(Date.now()).toDate(); } else { // $(".controllerDatePicker1").val(moment(localStorage.getItem('loadDate')).format('MM/DD/YYYY')); if (isNaN(Date.parse(localStorage.getItem('loadDate')))) { if (localStorage.getItem('loadDate').search('-') > 0) { var str = localStorage.getItem('loadDate').split('-'); var str1 = str[1] + '/' + str[2] + '/' + str[0]; localStorage.setItem('loadDate', str1); this.getParentComponent().getUserServerSettings('loadDate', str1); } } $(".controllerDatePicker1").val(localStorage.getItem('loadDate')); this.flyoutDate = moment.tz(localStorage.getItem('loadDate'), this.timeId).toDate() } if (localStorage.getItem('operatingLocationId') != null) { if (localStorage.getItem('operatingLocationId').search(',') > 0) { this.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function(item) { return parseInt(item, 10); }); }else{ if(this.isNumeric(localStorage.getItem('operatingLocationId'))){ this.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); } } } if (localStorage.getItem('THRESHOLD') != null) { this.driverThresholdId = parseInt(localStorage.getItem('THRESHOLD')); } if (localStorage.getItem('showEmptyRoute') != null) { this.showEmptyRoute = JSON.parse(localStorage.getItem('showEmptyRoute')); } if (localStorage.getItem('showCompleted') != null) { this.completed = JSON.parse(localStorage.getItem('showCompleted')); } if (sessionStorage.getItem('timer-interval') != null) { $('#refreshInterval').val(sessionStorage.getItem('timer-interval')); } if (this.routeIds[0] != 0 && this.routeIds[0] != undefined) { // this.filters.startDate = moment(localStorage.getItem('loadDate')); this.filterDate = localStorage.getItem('loadDate'); } else { // this.todaysDate = moment(Date.now()).format(); // this.filters.startDate = moment(this.todaysDate); this.filterDate = moment(Date.now()).local().format('YYYY-MM-DD'); // this.route = []; this.routeSel = []; this.routeIds = []; } if (this.appSession.tenantId != null) { // this.filterOrderTypes(); this.filterMobileVersion(); // this.getRoutes(); this.filterManager(); this.getLocationLock(); } this.getDriverInactiveThreshold(); //filter // this.filterRoutes(); ControllerHeaderFlyoutComponent.getUserConfig(); if (this.isEnabledLaboratory) { this.filterRouteTypes(); } this.routeTypeIds = JSON.parse(localStorage.getItem('selectedRouteTypeIds')) == null ? [] : JSON.parse(localStorage.getItem('selectedRouteTypeIds')); this.routeTypeSel = JSON.parse(localStorage.getItem('selectedRouteTypeIds')) == null ? [] : JSON.parse(localStorage.getItem('selectedRouteTypeIds')); this.managerIds = JSON.parse(localStorage.getItem('selectedManagerIds')) == null ? [] : JSON.parse(localStorage.getItem('selectedManagerIds')); this.managerSel = JSON.parse(localStorage.getItem('selectedManagerIds')) == null ? [] : JSON.parse(localStorage.getItem('selectedManagerIds')); } ngAfterViewInit(): void { $(".select2-container").css("width", "100%"); $(".form-control").css("height", "38px"); $(".input-group-append").css("display", "none"); this.mQuickSidebarOffcanvas = new KTOffcanvas(this.el.nativeElement, { overlay: true, baseClass: 'kt-quick-panel', closeBy: 'controller-header-close', toggleBy: 'controller_header_settings_toggle' }); this.mQuickSidebarOffcanvas.events.push({ name: 'afterHide', handler: () => { if (this._pinned) { this.mQuickSidebarOffcanvas.show(); } else { this.isOpen = false; } } }, { name: 'afterShow', handler: () => { this.isOpen = true; } }); } private getDriverInactiveThreshold(): void { this._routeServiceProxy.getDriverInactiveThreshold().subscribe(result => { this.driverThreshold = result; }); } private static getUserConfig(): any { const cookieLangValue = abp.utils.getCookieValue('Abp.Localization.CultureName'); const token = abp.auth.getToken(); let requestHeaders = { '.AspNetCore.Culture': ('c=' + cookieLangValue + '|uic=' + cookieLangValue), 'Abp.TenantId': abp.multiTenancy.getTenantIdCookie() }; if (token) { requestHeaders['Authorization'] = 'Bearer ' + token; } } set pinned(newValue: boolean) { if (newValue === this._pinned) { return; } this._pinned = newValue; } get pinned(): boolean { return this._pinned; } reversePinned(): void { this.pinned = !this.pinned; } set isOpen(newValue: boolean) { if (newValue === this._isOpen) { return; } this._isOpen = newValue; } get isOpen(): boolean { return this._isOpen; } switchHideEmpty(event) { this.hideEmpty = event.target.checked; } switchHideCompleted(event) { this.hideCompleted = event.target.checked; } switchHidePickedUp(event) { this.hidePickedUp = event.target.checked; } showFlyout(x: any, data: any, edition: any): void { let that = this; if (localStorage.getItem('operatingLocationId') != null) { if (localStorage.getItem('operatingLocationId').search(',') > 0) { this.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function(item) { return parseInt(item, 10); }); }else{ this.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); } } let values = []; this.filters.locationIds.forEach(el => { values.push(el); }); this.defaultLocation = values; this.locations = x; let key, key2, arrAny = {}, arrHolder = []; for (key in x) { arrAny = { 'name': x[key].name, 'id': x[key].id, 'selected': false }; for (key2 in this.defaultLocation) { if (this.defaultLocation[key2] == x[key].id) { arrAny = { 'name': x[key].name, 'id': x[key].id, 'selected': true }; } } arrHolder.push(arrAny); } this.filteredLocations = arrHolder; this.routeTypeIds = JSON.parse(localStorage.getItem('selectedRouteTypeIds')) == null ? [] : JSON.parse(localStorage.getItem('selectedRouteTypeIds')); this.managerIds = JSON.parse(localStorage.getItem('selectedManagerIds')) == null ? [] : JSON.parse(localStorage.getItem('selectedManagerIds')); if (this.routeTypeIds.length == 0) { this.unselectAllRouteType(); } if (this.managerIds.length == 0) { this.unselectAllManager(); } $('#locationSelectInput').on('change', function () { $("#locationSelectInput").val($(this).val()); that.getParentComponent().filters.locationIds = $("#locationSelectInput").val(); }); $('#groupGridBy').removeClass('kt-select2'); $('#groupGridBy').val(localStorage.getItem('groupGridBy') == null ? 'None' : localStorage.getItem('groupGridBy')); // document.getElementById('groupGridBy').value = $('#groupGridBy').addClass('kt-select2'); this.selRouteType = localStorage.getItem('groupGridBy') == null ? 'None' : localStorage.getItem('groupGridBy'); // $('#locationSelectInput').val(localStorage.getItem('operatingLocationId')); // this.filters.locationFilter = x["0"].id; this.userProfile = data; this.editionLab = edition == 'STANDARD' ? false : true; this.locationId = parseInt(localStorage.getItem('operatingLocationId')); if (localStorage.getItem('THRESHOLD') != null) { this.driverThresholdId = parseInt(localStorage.getItem('THRESHOLD')); } setTimeout(function(){ $('.kt-select2').select2(); }, 100); } filterRoutes() { this.getParentComponent().filters.locationIds = $("#locationSelectInput").val(); if(this.getParentComponent().filters.locationIds.length==0){ (document.getElementById('locationSelectInput')).style.border="1px solid red"; this.isLocationEmpty = true; }else{ this.isLocationEmpty = false; let that = this; if (this.isEnabledLaboratory) { this.completed = false; } var lang = abp.localization.currentLanguage.name; if (lang == "en-GB") { var str = $('.controllerDatePicker1').val().toString().split('/'); var str1 = str[1] + '/' + str[0] + '/' + str[2]; localStorage.setItem('loadDate', str1); } else { var str = $('.controllerDatePicker1').val().toString().split('/'); var str1 = str[0] + '/' + str[1] + '/' + str[2]; localStorage.setItem('loadDate', str1); } this.getLocationLock(); that.getParentComponent().filters.startDate = moment(localStorage.getItem('loadDate')); that.getParentComponent().filters.endDate = moment(localStorage.getItem('loadDate')); that.getParentComponent().firstload = true; if($('#groupGridBy').val()!=null){ localStorage.setItem('groupGridBy', $('#groupGridBy').val().toString()); that.getParentComponent().groupGridBy = $('#groupGridBy').val(); } that.getParentComponent().filters.locationIds = $("#locationSelectInput").val(); localStorage.setItem('operatingLocationId', $("#locationSelectInput").val().toString()); var threshold = $("#driverInactive").val() == 0 ? undefined : $("#driverInactive").val().toString(); if (threshold != undefined) { localStorage.setItem('THRESHOLD', $("#driverInactive").val().toString()); that.userPreferenceInput.thresholdValue = localStorage.getItem('THRESHOLD'); } else { localStorage.removeItem('THRESHOLD'); } that.userPreferenceInput.loadDateValue = localStorage.getItem('loadDate'); that.userPreferenceInput.locationValue = localStorage.getItem('operatingLocationId'); localStorage.setItem('showEmptyRoute', String(this.showEmptyRoute)); localStorage.setItem('showCompleted', String(this.completed)); that.spinnerService.show(); that._userPreferenceServiceProxy.createOrEditUserPreference(that.userPreferenceInput).subscribe(res => { that.searchFilters.showCompletion = this.completed; that.getParentComponent().searchFilters.showCompletion = this.completed; that.getParentComponent().filterRoutes(); }); // this.getParentComponent().refresh(null); that.locations.forEach(element => { if (element.id == $("#locationSelectInput").val()) { that.timezone = element.timezone; localStorage.setItem('timeZone', that.timezone); } }); // set user config then updatelocalstorage ControllerHeaderFlyoutComponent.getUserConfig(); this.routeIds = []; this.routeSel = []; this.orderTypeIds = []; // this.filters.locationFilter = parseInt(localStorage.getItem('operatingLocationId')); if (localStorage.getItem('operatingLocationId').search(',') > 0) { this.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function(item) { return parseInt(item, 10); }); }else{ if(this.isNumeric(localStorage.getItem('operatingLocationId'))){ this.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); } } } } generateRoutes(event: any) // generateRoutes() { event.target.disabled = true; let locationName = $('#locationSelectInput option:selected').text().replace(/\s/g, ''); let locationId = $('#locationSelectInput').val(); // console.log(localStorage.getItem('loadDate')); // console.log(moment(localStorage.getItem('loadDate')).format('YYYY-MM-DD')); // console.log(moment(localStorage.getItem('loadDate')).tz(localStorage.getItem('timeZoneId')).format('YYYY-MM-DD')); // let loadDate = localStorage.getItem('loadDate') ; // let date = moment.utc(loadDate) // this._locationAppService.isHolidayOnLocation(date,Number(locationId)).subscribe(result =>{ // if(result) // { // this.message.info('Today is a holiday. Route and orders are not allowed to be generated') // } else { // this.getParentComponent().generateRoute(); // let hideFlyOut: HTMLElement = document.getElementById('controller-header-close') as HTMLElement; // hideFlyOut.click(); // } }); this.getParentComponent().generateRoute(); let hideFlyOut: HTMLElement = document.getElementById('controller-header-close') as HTMLElement; hideFlyOut.click(); // if(localStorage.getItem('loadDate') == '09/07/2020' && // // if (moment(localStorage.getItem('loadDate')).format('YYYY-MM-DD') == '2020-09-07' && // (locationName != 'Calgary-Antech' && locationName != 'BC-Antech')) } enableButton() { (document.getElementById('updateRoutesBtn') as HTMLInputElement).disabled = false; } selectAll() { this.routeIds = this.filterRouteData.map(x => x.routeId); this.routeSel = this.filterRouteData.map(x => x.routeId); } unselectAll() { this.routeIds = []; this.routeSel = []; } clearAll() { this.routeIds = []; this.routeSel = []; } addRoute(event) { this.routeIds.push(event.routeId); } removeRoute(event) { const index = this.routeIds.indexOf(event.value.routeId, 0); if (index > -1) { this.routeIds.splice(index, 1); } const index2 = this.routeSel.indexOf(event.value.routeId, 0); if (index2 > -1) { this.routeSel.splice(index2, 1); } } selectAllOrderType() { this.orderTypeIds = this.filteredOrderTypes.map(x => x.code); this.orderTypeSel = this.filteredOrderTypes.map(x => x.id); } unselectAllOrderType() { this.orderTypeIds = []; this.orderTypeSel = []; } clearAllOrderType() { this.orderTypeIds = []; this.orderTypeSel = []; } addOrderType(event) { this.orderTypeIds.push(event.code); } removeOrderType(event) { const index = this.orderTypeIds.indexOf(event.value.code, 0); if (index > -1) { this.orderTypeIds.splice(index, 1); } const index2 = this.orderTypeSel.indexOf(event.value.id, 0); if (index2 > -1) { this.orderTypeSel.splice(index2, 1); } } selectAllRouteType() { this.routeTypeSel = this.filteredRouteTypes.map(x => x.id); this.routeTypeIds = this.filteredRouteTypes.map(x => x.id); } unselectAllRouteType() { this.routeTypeIds = []; this.routeTypeSel = []; } clearAllRouteType() { this.routeTypeIds = []; this.routeTypeSel = []; } addRouteType(event) { this.routeTypeIds.push(event.id); } removeRouteType(event) { const index = this.routeTypeIds.indexOf(event.value.id, 0); if (index > -1) { this.routeTypeIds.splice(index, 1); } const index2 = this.routeTypeSel.indexOf(event.value.id, 0); if (index2 > -1) { this.routeTypeSel.splice(index2, 1); } } selectAllManager() { this.managerSel = this.getManagerListDto.map(x => x.userId); this.managerIds = this.getManagerListDto.map(x => x.userId); } unselectAllManager() { this.managerIds = []; this.managerSel = []; } clearAllManager() { this.managerIds = []; this.managerSel = []; } addManager(event) { this.managerIds.push(event.userId); } removeManager(event) { const index = this.managerIds.indexOf(event.value.userId, 0); if (index > -1) { this.managerIds.splice(index, 1); } const index2 = this.managerSel.indexOf(event.value.userId, 0); if (index2 > -1) { this.managerSel.splice(index2, 1); } } filterOrderTypes() { this._orderTypesServiceProxy.getAll(undefined, undefined, undefined, 1, undefined, undefined, undefined, undefined).subscribe(result => { this.filteredOrderTypes = []; var arryHolder = {} for (var key in result.items) { // if (result.items[key].orderType.code != "CALLBACK") { arryHolder = { 'id': result.items[key].orderType.id, 'description': result.items[key].orderType.description, 'code': result.items[key].orderType.code } this.filteredOrderTypes.push(arryHolder); // } } }); } filterMobileVersion() { this._routeServiceProxy.getMobileVersionsFilter().subscribe(result => { this.filteredMobileVersion = result; }); } addedFilter() { if (this.isEnabledLaboratory) { this.completed = false; } this.getParentComponent().filters.orderType = $('#orderTypesSelectInput').val(); this.getParentComponent().filters.osName = $('#mobileSelectInput').val(); this.getParentComponent().searchFilters.showCompletion = this.completed; this.getParentComponent().filters.routeIds = this.routeIds; this.getParentComponent().filters.orderType = this.orderTypeIds; this.getParentComponent().filters.managerIds = this.managerIds; this.getParentComponent().filters.routeTypeIds = this.routeTypeIds; localStorage.setItem('selectedRouteTypeIds', JSON.stringify(this.routeTypeIds)); localStorage.setItem('selectedManagerIds', JSON.stringify(this.managerIds)); localStorage.setItem('showEmptyRoute', String(this.showEmptyRoute)); localStorage.setItem('showCompleted', String(this.completed)); this.getParentComponent().filterRoutes(); } activeDriver() { this.routeSel = []; this.routeIds = []; let tmp = []; this._locatorAppService.getActiveRoutes(moment.tz(localStorage.getItem('loadDate'), this.timeId), this.filters.locationFilter).subscribe(result => { result.items.forEach(item => { tmp.push(item.routeId); this.routeIds.push(item.routeId); }); this.routeSel = tmp; }); } getRoutes() { //this._locatorAppService.getLaboratoryDriverFilter(moment.tz(localStorage.getItem('loadDate'), this.timeId), moment.tz(localStorage.getItem('loadDate'), this.timeId), this.filters.locationFilter, undefined, undefined, this.routeIds,undefined,undefined) //.subscribe((result) => { //this.filterRouteData = result.items; //}); } getFilter() { if (localStorage.getItem('searchFilter') == null) { this.searchFilters.route = ''; this.searchFilters.driverName = ''; this.searchFilters.showCompletion = false; this.searchFilters.vehicleName = ''; } else { this.searchFilters = JSON.parse(localStorage.getItem('searchFilter')); } localStorage.setItem('searchFilter', JSON.stringify(this.searchFilters)); this.completed = this.searchFilters.showCompletion; } // changeInterval(): void { // sessionStorage.setItem('timer-interval', $('#refreshInterval').val().toString()); // this.getParentComponent().timerInterval = sessionStorage.getItem('timer-interval'); // this.getParentComponent().resetInterval(); // } filterRouteTypes(): void { this._routeTypesServiceProxy.getAll(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { this.filteredRouteTypes = []; var arryHolder = {} for (var key in result.items) { arryHolder = { 'id': result.items[key].routeType.id, 'description': result.items[key].routeType.description, 'code': result.items[key].routeType.routeTypeCode } this.filteredRouteTypes.push(arryHolder); } }); } filterManager(): void { this._routeDefinitionServiceProxy.getManagerList() .subscribe(result => { this.getManagerListDto = result; }); } getLocationLock(): void { this.filters.locationIds = []; if (localStorage.getItem('operatingLocationId').search(',') > 0) { this.filters.locationIds = localStorage.getItem('operatingLocationId').split(',').map(function(item) { return parseInt(item, 10); }); }else{ if(this.isNumeric(localStorage.getItem('operatingLocationId'))){ this.filters.locationIds = []; this.filters.locationIds.push(parseInt(localStorage.getItem('operatingLocationId'))); } } let locId = localStorage.getItem('operatingLocationId')!=null? this.filters.locationIds==[] || this.filters.locationIds == null ? this.locations['0'].id : this.filters.locationIds[0].valueOf() : this.locations['0'].id; if (locId) { this._locationServiceProxy.getLocationForLock(locId, moment.tz(localStorage.getItem('loadDate'), this.timeId)).subscribe(result => { this.getParentComponent().lockOrUnlockLocation = result.lock; this.getParentComponent().lockOrUnlockLocationDetails = result; }) } } isNumeric = (val: string): boolean => { return !isNaN(Number(val)); } }