From bcd8aa205adc8be90361a0da4e9752ecf887d688 Mon Sep 17 00:00:00 2001 From: Sandipan Mitra Date: Wed, 5 Feb 2025 18:01:28 +0530 Subject: [PATCH] worked on upload loading progress bar --- .../all-patients/all-patients.component.html | 7 +- .../all-patients/all-patients.component.ts | 50 ++++--- .../patient-record.component.html | 25 +++- .../patient-record.component.ts | 131 +++++++++++------- 4 files changed, 143 insertions(+), 70 deletions(-) diff --git a/angular/src/app/patients/all-patients/all-patients.component.html b/angular/src/app/patients/all-patients/all-patients.component.html index 64159d6..b79aacd 100644 --- a/angular/src/app/patients/all-patients/all-patients.component.html +++ b/angular/src/app/patients/all-patients/all-patients.component.html @@ -92,9 +92,14 @@
+ (change)="profileimageupload($event)"/>
{{error}} + +
+

Uploading... {{ uploadProgress }}%

+ +
{{imgpath}} diff --git a/angular/src/app/patients/all-patients/all-patients.component.ts b/angular/src/app/patients/all-patients/all-patients.component.ts index b9cbffb..c722433 100644 --- a/angular/src/app/patients/all-patients/all-patients.component.ts +++ b/angular/src/app/patients/all-patients/all-patients.component.ts @@ -1,6 +1,6 @@ import { PermissionService } from '@abp/ng.core'; import { Confirmation, ConfirmationService, ToasterService } from '@abp/ng.theme.shared'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpEventType, HttpParams, HttpRequest } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { NgForm } from '@angular/forms'; import { Router } from '@angular/router'; @@ -8,6 +8,7 @@ import { PagingSortPatientResultDto } from '@proxy/dto'; import { Gender, Status } from '@proxy/global-enum'; import { PatientService } from '@proxy/patients'; import { PatientDto, CreateUpdatePatientDto } from '@proxy/patients/dto'; +import { environment } from 'src/environments/environment'; @Component({ selector: 'app-all-patients', @@ -38,18 +39,7 @@ export class AllPatientsComponent implements OnInit { error: string = ''; imgpath: string = ''; guid: string = '00000000-0000-0000-0000-000000000000'; - options: Partial = { - hideCancelBtn: false, - hideYesBtn: false, - dismissible: false, - cancelText: 'Close', - // yesText: 'Confirm', - messageLocalizationParams: ['Demo'], - titleLocalizationParams: [], - // You can customize icon - // icon: 'fa fa-exclamation-triangle', // or - // iconTemplate : '' - }; + uploadProgress = 0; constructor( private patientService: PatientService, @@ -103,6 +93,7 @@ export class AllPatientsComponent implements OnInit { this.imgpath = ''; this.selectedgender = 0; this.selectedstatus = 0; + this.uploadProgress = 0; } loadPatient(event: any) { @@ -174,14 +165,41 @@ export class AllPatientsComponent implements OnInit { formdata.append('file', input.files[0]); this.UploadFileData(tag, formdata); } else { + this.uploadProgress = 0; return; } } + UploadFileData(tag: string, formdata: FormData) { - this.patientService.uploadFile(tag, formdata).subscribe(result => { - this.selectedPatient.imageID = result; - }); + // this.patientService.uploadFile(tag, formdata).subscribe(result => { + // this.selectedPatient.imageID = result; + // }); + const req = new HttpRequest( + 'POST', + environment.apis.default.url + '/api/app/patient/upload-file', + formdata, + { + reportProgress: true, + responseType: 'text', + params: new HttpParams().set('tagName', tag), + } + ); + this.http.request(req).subscribe( + event => { + if (event.type === HttpEventType.UploadProgress) { + this.uploadProgress = Math.round((event.loaded / event.total!) * 100); + console.log(event.type, this.uploadProgress); + } else if (event.type === HttpEventType.Response) { + this.uploadProgress = 100; + this.selectedPatient.imageID = event.body.toString(); + } + }, + error => { + console.error('Upload failed', error); + this.uploadProgress = 0; + } + ); } editPatient(Patient: any) { diff --git a/angular/src/app/patients/patient-record/patient-record.component.html b/angular/src/app/patients/patient-record/patient-record.component.html index 44ff19f..630f94b 100644 --- a/angular/src/app/patients/patient-record/patient-record.component.html +++ b/angular/src/app/patients/patient-record/patient-record.component.html @@ -83,8 +83,8 @@ Patient ID - Full Name - Gender + Full Name + Gender Date of Admission Diagnosis Lab Reports @@ -194,16 +194,24 @@
+ (change)="handleUpload($event,'Lab-Report')" />
+
+

Uploading... {{ uploadProgress }}%

+ +
{{labReportUrlpath}}
+ (change)="handleUpload($event,'Medication')" />
+
+

Uploading... {{ uploadProgress }}%

+ +
{{medicationUrlpath}}
@@ -213,9 +221,14 @@
+ (change)="handleUpload($event,'Medication-History')" />
- {{medicationHistoryUrlpath}} +
+

Uploading... {{ uploadProgress }}%

+ +
+ {{medicationHistoryUrlpath}}
diff --git a/angular/src/app/patients/patient-record/patient-record.component.ts b/angular/src/app/patients/patient-record/patient-record.component.ts index 49358ae..b3ee512 100644 --- a/angular/src/app/patients/patient-record/patient-record.component.ts +++ b/angular/src/app/patients/patient-record/patient-record.component.ts @@ -8,6 +8,7 @@ import { PermissionService } from '@abp/ng.core'; import { ActivatedRoute, Router } from '@angular/router'; import { environment } from 'src/environments/environment'; import { Confirmation, ConfirmationService, ToasterService } from '@abp/ng.theme.shared'; +import { HttpClient, HttpEventType, HttpParams, HttpRequest } from '@angular/common/http'; @Component({ selector: 'app-patient-record', @@ -40,18 +41,7 @@ export class PatientRecordComponent implements OnInit { medicationHistoryUrlpath: string; medicationUrlpath: string; guid: string = '00000000-0000-0000-0000-000000000000'; - options: Partial = { - hideCancelBtn: false, - hideYesBtn: false, - dismissible: false, - cancelText: 'Close', - yesText: 'Confirm', - messageLocalizationParams: ['Demo'], - titleLocalizationParams: [], - // You can customize icon - // icon: 'fa fa-exclamation-triangle', // or - // iconTemplate : '' - }; + uploadProgress = 0; constructor( private patientService: PatientService, @@ -59,7 +49,8 @@ export class PatientRecordComponent implements OnInit { private permissionChecker: PermissionService, private toaster: ToasterService, private route: ActivatedRoute, - private router: Router + private router: Router, + private http: HttpClient ) {} ngOnInit() { @@ -122,7 +113,6 @@ export class PatientRecordComponent implements OnInit { }); this.patientService.getPatientRecordList(this.params, id).subscribe(data => { this.patientrecords = data.items; - // console.log(data.items); this.totalRecords = data.totalCount; this.loading = false; }); @@ -201,50 +191,97 @@ export class PatientRecordComponent implements OnInit { }); } - handleLabReportUpload(event: Event): void { + handleUpload(event: Event, tag: string): void { const input = event.target as HTMLInputElement; - if (input && input.files) { - const tag = 'Lab-Report'; + if (input.files.length > 0) { const formdata = new FormData(); formdata.append('file', input.files[0]); this.UploadFileData(tag, formdata); + } else { + this.uploadProgress = 0; + return; } } - handleMedicationsUpload(event: any): void { - const input = event.target as HTMLInputElement; - if (input && input.files) { - const tag = 'Medication'; - const formdata = new FormData(); - formdata.append('file', input.files[0]); - this.UploadFileData(tag, formdata); - } - } + // handleLabReportUpload(event: Event): void { + // const input = event.target as HTMLInputElement; + // if (input && input.files) { + // const tag = 'Lab-Report'; + // const formdata = new FormData(); + // formdata.append('file', input.files[0]); + // this.UploadFileData(tag, formdata); + // } + // } - handleMedicationHistoryUpload(event: any): void { - const input = event.target as HTMLInputElement; - if (input && input.files) { - const tag = 'Medication-History'; - const formdata = new FormData(); - formdata.append('file', input.files[0]); - this.UploadFileData(tag, formdata); - } - } + // handleMedicationsUpload(event: any): void { + // const input = event.target as HTMLInputElement; + // if (input && input.files) { + // const tag = 'Medication'; + // const formdata = new FormData(); + // formdata.append('file', input.files[0]); + // this.UploadFileData(tag, formdata); + // } + // } + + // handleMedicationHistoryUpload(event: any): void { + // const input = event.target as HTMLInputElement; + // if (input && input.files) { + // const tag = 'Medication-History'; + // const formdata = new FormData(); + // formdata.append('file', input.files[0]); + // this.UploadFileData(tag, formdata); + // } + // } UploadFileData(tag: string, formdata: FormData) { - this.patientService.uploadFile(tag, formdata).subscribe(result => { - switch (tag) { - case 'Lab-Report': - this.selectedPatient.labReportUrlID = result; - break; - case 'Medication': - this.selectedPatient.medicationUrlID = result; - break; - case 'Medication-History': - this.selectedPatient.medicationHistoryUrlID = result; - break; + // this.patientService.uploadFile(tag, formdata).subscribe(result => { + // switch (tag) { + // case 'Lab-Report': + // this.selectedPatient.labReportUrlID = result; + // break; + // case 'Medication': + // this.selectedPatient.medicationUrlID = result; + // break; + // case 'Medication-History': + // this.selectedPatient.medicationHistoryUrlID = result; + // break; + // } + // }); + const req = new HttpRequest( + 'POST', + environment.apis.default.url + '/api/app/patient/upload-file', + formdata, + { + reportProgress: true, + responseType: 'text', + params: new HttpParams().set('tagName', tag), } - }); + ); + this.http.request(req).subscribe( + event => { + if (event.type === HttpEventType.UploadProgress) { + this.uploadProgress = Math.round((event.loaded / event.total!) * 100); + console.log(event.type, this.uploadProgress); + } else if (event.type === HttpEventType.Response) { + this.uploadProgress = 100; + switch (tag) { + case 'Lab-Report': + this.selectedPatient.labReportUrlID = event.body.toString(); + break; + case 'Medication': + this.selectedPatient.medicationUrlID = event.body.toString(); + break; + case 'Medication-History': + this.selectedPatient.medicationHistoryUrlID = event.body.toString(); + break; + } + } + }, + error => { + console.error('Upload failed', error); + this.uploadProgress = 0; + } + ); } savePatient(form: NgForm) {