import { Component, Injector, ViewEncapsulation, ViewChild } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { ClinicsServiceProxy, ClinicDto } 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 { CreateOrEditClinicModalComponent } from './create-or-edit-clinic-modal.component'; import { ViewClinicModalComponent } from './view-clinic-modal.component'; 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 { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import * as moment from 'moment-timezone'; import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { AppConsts } from '@shared/AppConsts'; import { ImportRouteScheduleTracking } from './route-schedule-import-tracking'; import * as signalR from '@aspnet/signalr'; import { ProgressBarService } from '@app/shared/layout/progressbar/progressbar.service'; @Component({ templateUrl: './clinics.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./clinic.component.less'], animations: [appModuleAnimation()] }) export class ClinicsComponent extends AppComponentBase { @ViewChild('createOrEditClinicModal', { static: true }) createOrEditClinicModal: CreateOrEditClinicModalComponent; @ViewChild('viewClinicModalComponent', { static: true }) viewClinicModal: ViewClinicModalComponent; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('importRouteScheduleTracking', {static: false}) importRouteScheduleTracking: ImportRouteScheduleTracking; advancedFiltersAreShown = false; filterText = ''; clinicNotesFilter = ''; billingNotesFilter = ''; clinicNameFilter = ''; clinicAccountFilter = ''; clinicAddressFilter = ''; inactive: boolean = false; maxContactIdFilter : number; maxContactIdFilterEmpty : number; minContactIdFilter : number; minContactIdFilterEmpty : number; _entityTypeFullName = 'SprintTek.Laboratory.Clinic'; entityHistoryEnabled = false; uploadUrl: string; importRouteScheduleImpoting: boolean = false; private hubConnection: signalR.HubConnection; constructor( injector: Injector, private _clinicsServiceProxy: ClinicsServiceProxy, private _notifyService: NotifyService, private _tokenAuth: TokenAuthServiceProxy, private _activatedRoute: ActivatedRoute, private _fileDownloadService: FileDownloadService, private _httpClient: HttpClient, private _router: Router, private _progressBar: ProgressBarService, private router: Router, ) { super(injector); } ngOnInit(): void { this.entityHistoryEnabled = this.setIsEntityHistoryEnabled(); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/Import/ImportFromExcel'; this.importRouteScheduleImpoting = abp.features.isEnabled('App.OrderImporting'); } private setIsEntityHistoryEnabled(): boolean { let customSettings = (abp as any).custom; return customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } getClinics(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._clinicsServiceProxy.getAll( this.filterText, this.clinicNotesFilter, this.billingNotesFilter, this.inactive, this.clinicAccountFilter, this.clinicNameFilter, this.clinicAddressFilter, this.maxContactIdFilter == null ? this.maxContactIdFilterEmpty: this.maxContactIdFilter, this.minContactIdFilter == null ? this.minContactIdFilterEmpty: this.minContactIdFilter, 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; //console.log(result.items); this.primengTableHelper.hideLoadingIndicator(); this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } createClinic(): void { //this.createOrEditClinicModal.show(); } showHistory(clinic: ClinicDto): void { this.entityTypeHistoryModal.show({ entityId: clinic.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Clinic - " +clinic.clinicName }); } deleteClinic(clinic: ClinicDto): void { this.message.confirm( '', '', (isConfirmed) => { if (isConfirmed) { this._clinicsServiceProxy.delete(clinic.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } exportToExcel(): void { this.spinnerService.show(); this._clinicsServiceProxy.getClinicsToExcel( this.filterText, this.clinicNotesFilter, this.billingNotesFilter, this.maxContactIdFilter == null ? this.maxContactIdFilterEmpty: this.maxContactIdFilter, this.minContactIdFilter == null ? this.minContactIdFilterEmpty: this.minContactIdFilter, this.clinicAccountFilter, this.clinicNameFilter, this.inactive ) .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.message.warn('', "No data to export"); this.spinnerService.hide(); } }); } createOrEditClinic(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } console.log(myurl); this._router.navigateByUrl(myurl); } uploadExcel(data: { files: File }): void { this.backgroundProcessListener(); this.importRouteScheduleTracking.clearMessages(); //this.importRouteScheduleTracking.modal.show(); const formData: FormData = new FormData(); const file = data.files[0]; formData.append('file', file, file.name); formData.append('key','workbook'); formData.append('loadDate', moment().tz(localStorage.getItem('timeZoneId')).format()); // formData.append('entity','addresses','addresses'); this._httpClient .post(this.uploadUrl, formData) .subscribe(response => { if (response.success) { this.notify.info('Import process is queued. Please wait'); this.toggle(true); } else if (response.error != null) { this.notify.error(this.l('ImportFailed')); this.toggle(false); } }); } uploadCallInExcel(data: { files: File }): void { //this.importRouteScheduleTracking.clearMessages(); //this.importRouteScheduleTracking.modal.show(); const formData: FormData = new FormData(); const file = data.files[0]; formData.append('file', file, file.name); formData.append('callin','callin'); // formData.append('entity','addresses','addresses'); this._httpClient .post(this.uploadUrl, formData) .subscribe(response => { if (response.success) { this.notify.info(this.l('ImportStart')); } else if (response.error != null) { this.notify.error(this.l('ImportFailed')); } }); } onUploadExcelError(): void { this.notify.error(this.l('ImportFailed')); } backgroundProcessListener() { this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(AppConsts.remoteServiceBaseUrl + '/import') .build(); this.hubConnection .start() .then(() => console.log('Connection started')) .catch(err => { console.log('Error while starting connection: ' + err); this.toggle(false); }); this.hubConnection.on('BackgroundMessage', (message) => { if(message.match(/End Importing/)){ this.importRouteScheduleTracking.importing = false; this.toggle(false); this.notify.success('Import process is complete'); this.getClinics(); this.hubConnection.off; }else{ this.importRouteScheduleTracking.logMessage(message); } this.sendMessage(message); }); } viewClinic(id: number): void{ this.viewClinicModal.show(id); } toggle(toggle: boolean) { this._progressBar.toggleProgressBar(toggle); } sendMessage(message: string) { this._progressBar.sendMessage(message); } }