import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { OrderServiceProxy, OrderListDto, LocationServiceProxy, LocationListDto } from '@shared/service-proxies/service-proxies'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment'; import { CreateOrderModalComponent } from './create-order-modal.component'; import { PrimengTableHelper } from '@shared/helpers/PrimengTableHelper'; @Component({ templateUrl: './order.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class OrderComponent extends AppComponentBase { @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; @ViewChild('createOrderModal', {static: false}) createOrderModal: CreateOrderModalComponent; //Filters filterText = undefined; locationFilter: LocationListDto = new LocationListDto(); filterDate = moment().format('MM/DD/YYYY'); maxResultCount = 1000; filteredOrder: any; filteredLocation: any; advancedFiltersAreShown: false; pickupEta: any; deliveryEta: any; constructor( injector: Injector, private router: Router, private _orderAppService: OrderServiceProxy, private _locationAppService: LocationServiceProxy ) { super(injector); } ngOnInit(){ $('.kt-select2').select2({ placeholder: "Select location.." }); this.filterLocation(); this.filterOrder(); } getOrders(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } //if(Number((document.getElementById('FilterByLocation')).value) === 0){ //this.filterText = undefined; //}else{ //this.filterText = Number((document.getElementById('FilterByLocation')).value); //} console.log(this.filterText); this.spinnerService.show(); this._orderAppService.getOrder( this.filterText, undefined, undefined, undefined, undefined, //this.filterText, undefined, undefined, undefined, //moment(this.filterDate), this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getMaxResultCount(this.paginator, event), this.primengTableHelper.getSkipCount(this.paginator, event) ).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; // result.items.forEach(item => { // let total = 0; // item.orderPackages.forEach(orderPackage => { // total = total + orderPackage.quantity; // }); // item.totalPackages = total; // }); this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } createOrder(): void { this.createOrderModal.show(); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } filterLocation(): void { this._locationAppService.getLocation( undefined, undefined, undefined, this.maxResultCount, undefined, ).subscribe(result => { this.filteredLocation = result.items; console.log(this.filteredLocation); }); } deleteOrder(order: OrderListDto): void { this.message.confirm( this.l('AreYouSure'), (isConfirmed) => { if (isConfirmed) { this._orderAppService.deleteOrder(order.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } createOrUpdate(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } console.log(myurl); this.router.navigateByUrl(myurl); } filterOrder(){ this._orderAppService.getOrder( this.filterText, undefined, undefined, undefined, undefined, //this.filterText, undefined, undefined, undefined, undefined, this.maxResultCount, undefined, ).subscribe(result => { this.filteredOrder = result.items; console.log(this.filteredOrder); this.spinnerService.hide(); }); } }