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 } 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"; @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 } = {}; 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; filterDate: any; filteredRouteTypes: any; getManagerListDto: GetManagerListDto[]; isEnabledLaboratory:boolean = false; flyoutDate: Date; appSession: AppSessionService; userPreferenceInput: UserPreferenceInput = new UserPreferenceInput; // dateRange: moment.Moment = moment(); 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 _routeServiceProxy: ControllerRouteServiceProxy, private _userPreferenceServiceProxy: UserPreferencesServiceProxy ) { 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'); } _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(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) { this.locationId = parseInt(localStorage.getItem('operatingLocationId')); this.filters.locationFilter = parseInt(localStorage.getItem('operatingLocationId')); } 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 = []; } $('.kt-select2').select2(); if(this.appSession.tenantId!=null){ this.filterOrderTypes(); this.filterMobileVersion(); this.getRoutes(); this.filterManager(); } //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 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; } return XmlHttpRequestHelper.ajax('GET', AppConsts.remoteServiceBaseUrl + '/AbpUserConfiguration/GetAll', requestHeaders, null, (response) => { let result = response.result; localStorage.setItem('timeZoneId', result.timing.timeZoneInfo.iana.timeZoneId); // localStorage.setItem('userTimeZone', response.result.timing.timeZoneInfo.windows.timeZoneId); }); } 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; this.locations = x; 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.locationFilter = $("#locationSelectInput").val(); }); $('#groupGridBy').removeClass('kt-select2'); $('#groupGridBy').val(localStorage.getItem('groupGridBy')); // document.getElementById('groupGridBy').value = $('#groupGridBy').addClass('kt-select2'); this.selRouteType = localStorage.getItem('groupGridBy'); $('#locationSelectInput').val(localStorage.getItem('operatingLocationId')); this.filters.locationFilter = x["0"].id; this.userProfile = data; if(edition == 'STANDARD'){ $('.form-group-laboratory').css('display', 'none'); } } filterRoutes() { let that = this; if(this.isEnabledLaboratory){ this.completed = false; } var lang = abp.localization.currentLanguage.name; console.log(lang); 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); } that.getParentComponent().filters.startDate = moment(localStorage.getItem('loadDate')); // that.getParentComponent().getUserServerSettings('loadDate', str1); that.getParentComponent().filters.endDate = moment(localStorage.getItem('loadDate')); that.getParentComponent().firstload = true; localStorage.setItem('groupGridBy', $('#groupGridBy').val().toString()); that.getParentComponent().groupGridBy = $('#groupGridBy').val(); that.getParentComponent().filters.locationFilter = $("#locationSelectInput").val(); localStorage.setItem('operatingLocationId', $("#locationSelectInput").val().toString()); // this.getParentComponent().getUserServerSettings('operatingLocationId', $("#locationSelectInput").val().toString()); // localStorage.setItem('loadDate', moment.tz(this.flyoutDate, "Etc/UTC").format('MM/DD/YY')); that.userPreferenceInput.loadDateValue = localStorage.getItem('loadDate'); that.userPreferenceInput.locationValue = localStorage.getItem('operatingLocationId'); 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); } }); // this.userProfile.timezone = this.timezone; // this.userProfile.hasBackgroundImage = this.appSession.user.hasBackgroundImage; // this._profileService.updateCurrentUserProfile(this.userProfile).subscribe(() => { // localStorage.setItem('timeZone', this.timezone); // }); // set user config then updatelocalstorage // ControllerHeaderFlyoutComponent.getUserConfig(); this.routeIds = []; this.routeSel = []; this.orderTypeIds = []; this.filters.locationFilter = parseInt(localStorage.getItem('operatingLocationId')) this.getRoutes(); } generateRoutes() { this.getParentComponent().generateRoute(); } 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)); 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) .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; }); } }