import { Component, Injector, ViewEncapsulation, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { OrderTypesServiceProxy, OrderTypeDto, GetOrderTypeForViewDto, ClientLogsServiceProxy, NameValueDto, ClientDriverServiceProxy, ClientDriversDto } from '@shared/service-proxies/service-proxies'; import { NotifyService } from '@abp/notify/notify.service'; import { AppComponentBase } from '@shared/common/app-component-base'; import { TokenAuthServiceProxy } from '@shared/service-proxies/service-proxies'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { Table } from 'primeng/components/table/table'; import { Paginator } from 'primeng/components/paginator/paginator'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { FileDownloadService } from '@shared/utils/file-download.service'; import * as _ from 'lodash'; import * as moment from 'moment'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; @Component({ templateUrl: './client-drivers.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class ClientDriverComponent extends AppComponentBase { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; _entityTypeFullName = 'SprintTek.Shipping.Integration.ClientDriver'; entityHistoryEnabled = false; advancedFiltersAreShown = false; filterText = ''; codeFilter = ''; descriptionFilter = ''; isActiveFilter = -1; colorFilter = ''; accountId:number; driverId = ''; firstName = ''; lastName = ''; clientAccountList: NameValueDto[]; constructor( injector: Injector, private _clientDriverServiceProxy: ClientDriverServiceProxy, private _downloadLogServiceProxy: ClientLogsServiceProxy, private router: Router, ) { super(injector); } ngOnInit(): void{ this.setIsEntityHistoryEnabled(); $('.kt-select2').select2(); this.getClientAccounts(); } private setIsEntityHistoryEnabled(): void { let customSettings = (abp as any).custom; this.entityHistoryEnabled = customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } showHistory(role: ClientDriversDto): void { this.entityTypeHistoryModal.show({ entityId: role.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Driver - " +role.firstName +" " +role.lastName }); } getClientDrivers(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this.accountId = $('#Accounts').val()=='null' ? undefined : Number($('#Accounts').val()); this._clientDriverServiceProxy.getAllClientDrivers( this.filterText, this.driverId, this.firstName, this.lastName, this.accountId, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } // deleteOrderType(orderType: OrderTypeDto): void { // this.message.confirm( // '', // '', // (isConfirmed) => { // if (isConfirmed) { // this._downloadLogServiceProxy.deleteClientOrderLog(orderType.id) // .subscribe(() => { // this.reloadPage(); // this.notify.success(this.l('SuccessfullyDeleted')); // }); // } // } // ); // } exportToExcel(event?: LazyLoadEvent): void { this.spinnerService.show(); this._clientDriverServiceProxy.getClientDriverToExcel( this.filterText, this.driverId, this.firstName, this.lastName, this.accountId, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ) .subscribe(result => { if(result!=undefined){ if(result.fileUrl!=undefined){ this.router.navigate([]).then(result1 => { window.open(result.fileUrl, '_blank'); }); this.spinnerService.hide(); }else{ this.spinnerService.hide(); } }else{ this.spinnerService.hide(); } }); } getClientAccounts(){ this._downloadLogServiceProxy.getClientAccountList().subscribe(res => { this.clientAccountList = res; }); } }