import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, Input, TemplateRef, Output, EventEmitter } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ControllerRouteDetailServiceProxy, UpdateRouteInput, RouteServiceProxy, ShippingPackageServiceProxy, CreateOptimizeInputDto, Route4MeServiceProxy } from '@shared/service-proxies/service-proxies'; import { RouteDetailModal } from './route-detail-modal.component'; import { MovePendingOrder } from './move-order-modal.component'; import { CreateIncidentsModal } from './create-incidents-modal.component'; import { AppSessionService } from '@shared/common/session/app-session.service'; import * as moment from 'moment'; import { Table } from "primeng/table"; import { LazyLoadEvent } from "primeng/primeng"; import { Paginator } from 'primeng/components/paginator/paginator'; import { HttpClient } from '@angular/common/http'; import { finalize } from 'rxjs/operators'; import * as _ from 'lodash'; import { MessageService } from 'primeng/api'; import * as signalR from '@aspnet/signalr'; import {Location} from '@angular/common'; declare var $: any; declare var jquery: any; @Component({ templateUrl: 'route-detail.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./route-detail.component.less'], animations: [appModuleAnimation()], selector: 'routeDetailComponent', providers: [MessageService] }) export class RouteDetailComponent extends AppComponentBase implements OnInit { saving = false; routeId: number = null; details: boolean = false; _isLab: boolean = false; routeCode: string; vehicleName: string; loadDate: string; locationName: string; reload: any; route: UpdateRouteInput = new UpdateRouteInput(); routeDetailTenant:string = 'STANDARD'; totalItems: any; packages: Array<{id: number, name: string}> = new Array(); OptimizeInput = new CreateOptimizeInputDto(); @ViewChild('routeDetailModal', { static: true }) routeDetailModal: RouteDetailModal; @ViewChild('movePendingOrderModal', { static: true }) movePendingOrderModal: MovePendingOrder; @ViewChild('createIncidentsModal', { static: true }) createIncidentsModal: CreateIncidentsModal; // @Input() hfRouteDetails: TemplateRef; @Input() labRouteDetails: any; @ViewChild("dataTable", { static: true }) dataTable: Table @ViewChild("paginator", { static: true }) paginator: Paginator @Output() reloadTable: EventEmitter = new EventEmitter(); // locations: LocationListDto[] = []; constructor( injector: Injector, private id: ActivatedRoute, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _controllerRoutePackages: ShippingPackageServiceProxy, private _controllerRoute: RouteServiceProxy, private _appSessionService: AppSessionService, private messageService: MessageService, private _location:Location, private _route4me : Route4MeServiceProxy // private _routeService: RouteServiceProxy ) { super(injector); this._isLab = abp.features.isEnabled('App.RouteDetails'); if(this._isLab){ this.routeDetailTenant = 'LAB'; } this.id.paramMap.subscribe(params => { this.routeId = Number(params.get('id')); }); } ngOnInit(): void { this.primengTableHelper.showLoadingIndicator(); this.getDetails(); // this.countItems(); // const connection = new signalR.HubConnectionBuilder() // .configureLogging(signalR.LogLevel.Information) // .withUrl("http://localhost:65302/location") // .build(); // connection.start().then(function () { // console.log('Connecteddfsdfsdf!'); // }).catch(function (err) { // return console.error(err.toString()); // }); // connection.on("GetLocation", (latitude: string,longitude: string) => { // this.messageService.add({ severity: 'success', summary: 'Success Message', detail: 'Notificiation' }); // }); } countItems(){ let maxcount = 700; if(this._isLab){ this._controllerRouteDetails.getRouteSchedDetails( undefined, this.routeId, undefined, undefined, undefined, undefined, maxcount, undefined // this.primengTableHelper.getMaxResultCount(this.paginator, event), // this.primengTableHelper.getSkipCount(this.paginator, event) ) .pipe(finalize(() => this.spinnerService.hide() )) .subscribe(result => { let sampleCount = 0 for (let index = 0; index < result.items.length; index++) { for (let key = 0; key < result.items[index].orderPackages.length; key++) { if(result.items[index].orderPackages[key].package.name != "Default"){ result.items[index].packageCount += result.items[index].orderPackages[key].quantity; console.log(result.items[index].packageCount) } } sampleCount += result.items[index].packageCount } this.totalItems = sampleCount; }); } else{ this._controllerRouteDetails .getControllerRouteDetailList( this.routeId, undefined) .subscribe(result => { let sampleCount = 0 for (let index = 0; index < result.items.length; index++) { sampleCount += result.items[index]['packageCount']; } this.totalItems = sampleCount; // this.primengTableHelper.totalRecordsCount = result.items.length; // this.primengTableHelper.records = result.items; // // this.spinnerService.hide(); // this.primengTableHelper.isLoading = false; }); } } getDetails() { this._controllerRouteDetails.getControllerRouteDetail(this.routeId) .subscribe(result => { this.routeCode = result.routeTemplate.name; this.route.vehicleId = result.vehicleId; this.route.completion = result.completion; this.route.departure = result.departure; this.route.loadDate = result.loadDate; this.route.locked = result.locked; this.route.routeTemplateId = result.routeTemplateId; this.route.locationId = result.locationId; this.route.id = this.routeId; this.locationName = result.location.name; if (result.vehicle) { this.vehicleName = result.vehicle.name; } //this.loadDate = moment(result.loadDate).toDate(); this.loadDate = localStorage.getItem('loadDate'); this.labRouteDetails = result.routeTemplate.name; }); } updateRoute() { this._controllerRoute.updateRoute(this.route) .pipe(finalize(() => this.saving = false)) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); }); } setDeparture() { if (!this.route.locked) { if (this.route.departure) { this.route.departure = null; } else { this.route.departure = moment.utc(moment(new Date()).format('YYYY-MM-DD h:m a')); } this.updateRoute(); } else { this.notify.info(this.l('Unlocked Loadlist First')); } } setCompletion() { if (!this.route.locked) { if (this.route.completion) { this.route.completion = null; } else { this.route.completion = moment.utc(moment(new Date()).format('YYYY-MM-DD h:m a')); } this.updateRoute(); } else { this.notify.info(this.l('Unlocked Loadlist First')); } } optimizeRoute(routeID){ this.spinnerService.show(); this.OptimizeInput.routeId = routeID; this.OptimizeInput.isReOptimize = true; this._route4me.optimize(this.OptimizeInput) .subscribe((optimizeResult) => { this.spinnerService.hide(); this.notify.info(this.l('Route has been re-optimized')); }); } ngAfterViewInit() { $('.kt-select2').select2(); $('.selectpicker').selectpicker(); } loadTable($event) { this.reload = $event; } goBack(){ this._location.back(); } onShown() { } }