import { Component, Injector, ViewEncapsulation, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { OrderTypesServiceProxy, OrderTypeDto, GetOrderTypeForViewDto, ClientLogsServiceProxy, NameValueDto } 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'; import { ViewOrderTypeModalComponent } from '@app/sprintship/order-management/order-types/view-orderType-modal.component'; import { ViewOrderLogsModalComponent } from './view-order-logs.component'; @Component({ templateUrl: './order-log.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class OrderLogComponent extends AppComponentBase { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('ViewOrderLogModal', { static: true }) ViewOrderLogModal: ViewOrderLogsModalComponent; _entityTypeFullName = 'SprintTek.Shipping.Order.OrderLog'; entityHistoryEnabled = false; advancedFiltersAreShown = false; filterText = ''; codeFilter = ''; descriptionFilter = ''; isActiveFilter = -1; colorFilter = ''; accountId:number; clientAccountList: NameValueDto[]; constructor( injector: Injector, 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: GetOrderTypeForViewDto): void { this.entityTypeHistoryModal.show({ entityId: role.orderType.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Order Type - " +role.orderType.description }); } getDownloadLogs(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._downloadLogServiceProxy.getClientOrderLog( this.filterText, 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._downloadLogServiceProxy.getClientOrderLogsToExcel( this.filterText, 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; }); } }