cat-documents-ng 0.2.68 → 0.2.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
2
2
  import { Injectable, EventEmitter, Output, ViewChild, Input, ViewEncapsulation, Component, ChangeDetectionStrategy, Directive, NgModule, APP_INITIALIZER } from '@angular/core';
3
3
  import * as i2$1 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
- import { firstValueFrom, tap, EMPTY, catchError, throwError, of, combineLatest, Subject, Observable, takeUntil, Subscription, debounceTime as debounceTime$1, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
5
+ import { firstValueFrom, tap, EMPTY, catchError, throwError, of, combineLatest, Subject, Observable, from, concatMap, takeUntil, Subscription, debounceTime as debounceTime$1, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
6
6
  import { __decorate } from 'tslib';
7
7
  import { EntityStore, StoreConfig, QueryEntity } from '@datorama/akita';
8
8
  import * as i2 from '@angular/common/http';
@@ -2369,12 +2369,14 @@ class DocumentUploadService {
2369
2369
  */
2370
2370
  handleCreateFormData(uploadedFile, contextId) {
2371
2371
  if (uploadedFile) {
2372
+ console.log("formData 1", uploadedFile);
2372
2373
  let formData = new FormData();
2373
2374
  formData.append(SHARED.FILE, uploadedFile, uploadedFile.name);
2374
2375
  formData.append(SHARED.CONTEXT_ID, this.contextId);
2375
2376
  return formData;
2376
2377
  }
2377
2378
  else {
2379
+ console.log("formData 2", uploadedFile);
2378
2380
  return null;
2379
2381
  }
2380
2382
  }
@@ -2939,10 +2941,15 @@ class DocumentUploadComponent {
2939
2941
  * @param event - Event containing the selected files
2940
2942
  */
2941
2943
  onSelectedFiles(event) {
2942
- event.currentFiles.forEach((file, index) => {
2943
- this.handleTemplatedUpload(file);
2944
+ from(event.currentFiles).pipe(concatMap(file => this.uploadFile$(file)) // Upload one file at a time
2945
+ ).subscribe({
2946
+ complete: () => {
2947
+ console.log('✅ All files uploaded sequentially.');
2948
+ this.fileUploader.clear();
2949
+ this.cdr.detectChanges();
2950
+ this.onFormValidationChange.emit();
2951
+ }
2944
2952
  });
2945
- this.fileUploader.clear();
2946
2953
  }
2947
2954
  /**
2948
2955
  * Loads the list of applicants for the current context.
@@ -2997,34 +3004,74 @@ class DocumentUploadComponent {
2997
3004
  * Sets up progress tracking and upload listener for the file.
2998
3005
  * @param file - The file to be uploaded
2999
3006
  */
3000
- handleTemplatedUpload(file) {
3001
- if (!this.formService.validateContextId(this.contextId, 'Context ID is required for upload.'))
3002
- return;
3007
+ // handleTemplatedUpload(file: File): void {
3008
+ // if (!this.formService.validateContextId(this.contextId, 'Context ID is required for upload.')) return;
3009
+ // const formsData = this.documentService.handleCreateFormData(file, this.contextId);
3010
+ // console.log("1",formsData);
3011
+ // if (!formsData) {
3012
+ // this.messageService.add({severity: SHARED.SEVERITY,summary: SHARED.UPLOAD_ERROR_SUMMERY,detail: SHARED.UPLOAD_ERROR_DETAILS});
3013
+ // return;
3014
+ // }
3015
+ // this.fileProgress.set(file, SHARED.UPLOAD_PROGRESS_10);
3016
+ // const formattedSize = this.businessService.formatFileSize(file.size, this.config);
3017
+ // const uploadedFile = this.businessService.createUploadedFile(file, formattedSize);
3018
+ // uploadedFile.progress = SHARED.UPLOAD_PROGRESS_10;
3019
+ // console.log("2",uploadedFile);
3020
+ // this.uploadService.create(formsData).subscribe({
3021
+ // next: (event) => {
3022
+ // console.log("3",event);
3023
+ // uploadedFile.uploadResponse = event;
3024
+ // uploadedFile.progress = SHARED.UPLOAD_PROGRESS_100;
3025
+ // uploadedFile.url = event?.url;
3026
+ // uploadedFile.contentType = event?.contentType;
3027
+ // this.uploadedFiles.push(event);
3028
+ // this.fileProgress.set(file, SHARED.UPLOAD_PROGRESS_100);
3029
+ // // this.uploadCompleted.emit({ file, response: event });
3030
+ // this.cdr.detectChanges();
3031
+ // this.onFormValidationChange.emit();
3032
+ // console.log("4 uploadedFiles",this.uploadedFiles);
3033
+ // },
3034
+ // error: (error) => {
3035
+ // this.messageService.add({severity: SHARED.SEVERITY,summary: SHARED.UPLOAD_SUMMERY,detail: error?.message});
3036
+ // }
3037
+ // });
3038
+ // }
3039
+ uploadFile$(file) {
3040
+ if (!this.formService.validateContextId(this.contextId, 'Context ID is required for upload.')) {
3041
+ return of(null);
3042
+ }
3003
3043
  const formsData = this.documentService.handleCreateFormData(file, this.contextId);
3044
+ console.log("3 formsData", formsData);
3004
3045
  if (!formsData) {
3005
- this.messageService.add({ severity: SHARED.SEVERITY, summary: SHARED.UPLOAD_ERROR_SUMMERY, detail: SHARED.UPLOAD_ERROR_DETAILS });
3006
- return;
3046
+ this.messageService.add({
3047
+ severity: SHARED.SEVERITY,
3048
+ summary: SHARED.UPLOAD_ERROR_SUMMERY,
3049
+ detail: SHARED.UPLOAD_ERROR_DETAILS
3050
+ });
3051
+ return of(null);
3007
3052
  }
3053
+ // const formattedSize = this.businessService.formatFileSize(file.size, this.config);
3054
+ // const uploadedFile = this.businessService.createUploadedFile(file, formattedSize);
3055
+ // uploadedFile.progress = SHARED.UPLOAD_PROGRESS_10;
3056
+ // this.uploadedFiles.push(uploadedFile);
3008
3057
  this.fileProgress.set(file, SHARED.UPLOAD_PROGRESS_10);
3009
- const formattedSize = this.businessService.formatFileSize(file.size, this.config);
3010
- const uploadedFile = this.businessService.createUploadedFile(file, formattedSize);
3011
- uploadedFile.progress = SHARED.UPLOAD_PROGRESS_10;
3012
- this.uploadedFiles.push(uploadedFile);
3013
- this.uploadService.create(formsData).subscribe({
3014
- next: (event) => {
3015
- uploadedFile.uploadResponse = event;
3016
- uploadedFile.progress = SHARED.UPLOAD_PROGRESS_100;
3017
- uploadedFile.url = event?.url;
3018
- uploadedFile.contentType = event?.contentType;
3019
- this.fileProgress.set(file, SHARED.UPLOAD_PROGRESS_100);
3020
- // this.uploadCompleted.emit({ file, response: event });
3021
- this.cdr.detectChanges();
3022
- this.onFormValidationChange.emit();
3023
- },
3024
- error: (error) => {
3025
- this.messageService.add({ severity: SHARED.SEVERITY, summary: SHARED.UPLOAD_SUMMERY, detail: error?.message });
3026
- }
3027
- });
3058
+ console.log("4 formData", formsData);
3059
+ return this.uploadService.create(formsData).pipe(tap((event) => {
3060
+ console.log("5 event", event);
3061
+ // uploadedFile.uploadResponse = event;
3062
+ // uploadedFile.progress = SHARED.UPLOAD_PROGRESS_100;
3063
+ // uploadedFile.url = event?.url;
3064
+ // uploadedFile.contentType = event?.contentType;
3065
+ this.uploadedFiles.push(event);
3066
+ this.fileProgress.set(file, SHARED.UPLOAD_PROGRESS_100);
3067
+ }), catchError((error) => {
3068
+ this.messageService.add({
3069
+ severity: SHARED.SEVERITY,
3070
+ summary: SHARED.UPLOAD_SUMMERY,
3071
+ detail: error?.message || 'Upload failed'
3072
+ });
3073
+ return of(null); // Continue with next file
3074
+ }));
3028
3075
  }
3029
3076
  /**
3030
3077
  * Removes a document from the uploaded files list.