import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { EntityDtoOfInt64, ContactServiceProxy, ContactListDto, PostalCodeServiceProxy } from '@shared/service-proxies/service-proxies'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { HttpClient } from '@angular/common/http'; import { FileUpload } from 'primeng/fileupload'; import { finalize } from 'rxjs/operators'; @Component({ templateUrl: './vendors.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./vendors.component.less'], animations: [appModuleAnimation()] }) export class VendorsComponent extends AppComponentBase { @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; //Filters filters: { id: number; firstName: string; lastName: string; nameFilter: string, postalCodeId: number } = {}; filteredPostal:any; advancedFiltersAreShown = false; constructor( injector: Injector, private _contactService: ContactServiceProxy, private _postalCodeService: PostalCodeServiceProxy, private _activatedRoute: ActivatedRoute, private _httpClient: HttpClient, private _router: Router, private _fileDownloadService: FileDownloadService, ) { super(injector); } ngOnInit(){ this.filterPostal(); $('.kt-select2').select2(); } getContact(event?: LazyLoadEvent) { this.filters.postalCodeId = Number((document.getElementById('postalCodeInput')).value) ? Number((document.getElementById('postalCodeInput')).value) : undefined; if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._contactService.getContactVendorQPaged( undefined, undefined, undefined, this.filters.postalCodeId, undefined, undefined, undefined, undefined, undefined, undefined, this.filters.nameFilter, this.filters.firstName, this.filters.lastName, undefined, undefined, undefined, undefined, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getMaxResultCount(this.paginator, event), this.primengTableHelper.getSkipCount(this.paginator, event) ).pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } deleteContact(contact: ContactListDto): void { this.message.confirm( this.l('VendorDeleteWarningMessage', contact.firstName+" "+contact.lastName), this.l('AreYouSure'), (isConfirmed) => { if (isConfirmed) { this._contactService.deleteContact(contact.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } createOrEditVendor(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } console.log(myurl); this._router.navigateByUrl(myurl); } filterPostal(): void { this._postalCodeService.getDistinctPostalCode( undefined ).subscribe(result => { this.filteredPostal = result.items; }); } exportToExcel(): void { this.filters.postalCodeId = Number((document.getElementById('postalCodeInput')).value) ? Number((document.getElementById('postalCodeInput')).value) : undefined; this._contactService.getVendorToExcel( undefined, undefined, undefined, this.filters.postalCodeId, this.filters.nameFilter, this.filters.firstName, this.filters.lastName ) .subscribe(result => { console.log(result); this._fileDownloadService.downloadTempFile(result); }); } }