diff --git a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.spec.ts b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.spec.ts index 70bd98302..4b2e2f990 100644 --- a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.spec.ts +++ b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.spec.ts @@ -84,7 +84,7 @@ describe('UploadFileWidgetComponent', () => { it('should change color by status phase', () => { const processingStatus = new FileStatus() - processingStatus.phase = FileStatusPhase.PROCESSING + processingStatus.phase = FileStatusPhase.WORKING expect(component.getStatusColor(processingStatus)).toEqual('primary') const failedStatus = new FileStatus() failedStatus.phase = FileStatusPhase.FAILED @@ -134,7 +134,7 @@ function mockConsumerStatuses(consumerStatusService) { switch (phase) { case FileStatusPhase.FAILED: return [new FileStatus()] - case FileStatusPhase.PROCESSING: + case FileStatusPhase.WORKING: return [new FileStatus(), new FileStatus()] case FileStatusPhase.STARTED: return [new FileStatus(), new FileStatus(), new FileStatus()] diff --git a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts index 96c8cdb25..68a3fbdfa 100644 --- a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts +++ b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts @@ -90,8 +90,9 @@ export class UploadFileWidgetComponent extends ComponentWithPermissions { getStatusColor(status: FileStatus) { switch (status.phase) { - case FileStatusPhase.PROCESSING: case FileStatusPhase.UPLOADING: + case FileStatusPhase.STARTED: + case FileStatusPhase.WORKING: return 'primary' case FileStatusPhase.FAILED: return 'danger' diff --git a/src-ui/src/app/services/consumer-status.service.spec.ts b/src-ui/src/app/services/consumer-status.service.spec.ts index 5c93f5160..3725f847d 100644 --- a/src-ui/src/app/services/consumer-status.service.spec.ts +++ b/src-ui/src/app/services/consumer-status.service.spec.ts @@ -60,10 +60,10 @@ describe('ConsumerStatusService', () => { current_progress: 50, max_progress: 100, document_id: 12, - status: 'STARTING', + status: 'WORKING', }) - expect(status.getProgress()).toBeCloseTo(0.6) // 0.8 * 50/100 + expect(status.getProgress()).toBeCloseTo(0.6) // (0.8 * 50/100) + .2 expect(consumerStatusService.getConsumerStatusNotCompleted()).toEqual([ status, ]) @@ -194,6 +194,7 @@ describe('ConsumerStatusService', () => { expect(consumerStatusService.getConsumerStatusCompleted()).toHaveLength(1) consumerStatusService.dismissCompleted() expect(consumerStatusService.getConsumerStatusCompleted()).toHaveLength(0) + consumerStatusService.disconnect() }) it('should support dismiss', () => { @@ -238,17 +239,40 @@ describe('ConsumerStatusService', () => { }) it('should notify of document created on status message without upload', () => { + let detected = false consumerStatusService.onDocumentDetected().subscribe((filestatus) => { expect(filestatus.phase).toEqual(FileStatusPhase.STARTED) + detected = true }) + consumerStatusService.connect() + server.send({ + task_id: '1234', + filename: 'file.pdf', + current_progress: 0, + max_progress: 100, + message: 'new_file', + status: 'STARTED', + }) + + consumerStatusService.disconnect() + expect(detected).toBeTruthy() + }) + + it('should notify of document in progress without upload', () => { + consumerStatusService.connect() server.send({ task_id: '1234', filename: 'file.pdf', current_progress: 50, max_progress: 100, - document_id: 12, - status: 'STARTING', + docuement_id: 12, + status: 'WORKING', }) + + consumerStatusService.disconnect() + expect(consumerStatusService.getConsumerStatusNotCompleted()).toHaveLength( + 1 + ) }) }) diff --git a/src-ui/src/app/services/consumer-status.service.ts b/src-ui/src/app/services/consumer-status.service.ts index 090d80433..394975333 100644 --- a/src-ui/src/app/services/consumer-status.service.ts +++ b/src-ui/src/app/services/consumer-status.service.ts @@ -3,10 +3,11 @@ import { Subject } from 'rxjs' import { environment } from 'src/environments/environment' import { WebsocketConsumerStatusMessage } from '../data/websocket-consumer-status-message' +// see ConsumerFilePhase in src/documents/consumer.py export enum FileStatusPhase { STARTED = 0, UPLOADING = 1, - PROCESSING = 2, + WORKING = 2, SUCCESS = 3, FAILED = 4, } @@ -49,7 +50,7 @@ export class FileStatus { return 0.0 case FileStatusPhase.UPLOADING: return (this.currentPhaseProgress / this.currentPhaseMaxProgress) * 0.2 - case FileStatusPhase.PROCESSING: + case FileStatusPhase.WORKING: return ( (this.currentPhaseProgress / this.currentPhaseMaxProgress) * 0.8 + 0.2 ) @@ -150,7 +151,7 @@ export class ConsumerStatusService { let created = statusMessageGet.created status.updateProgress( - FileStatusPhase.PROCESSING, + FileStatusPhase.WORKING, statusMessage.current_progress, statusMessage.max_progress ) @@ -164,16 +165,25 @@ export class ConsumerStatusService { } status.documentId = statusMessage.document_id - if (created && statusMessage.status == 'STARTED') { - this.documentDetectedSubject.next(status) + if (statusMessage.status in FileStatusPhase) { + status.phase = FileStatusPhase[statusMessage.status] } - if (statusMessage.status == 'SUCCESS') { - status.phase = FileStatusPhase.SUCCESS - this.documentConsumptionFinishedSubject.next(status) - } - if (statusMessage.status == 'FAILED') { - status.phase = FileStatusPhase.FAILED - this.documentConsumptionFailedSubject.next(status) + + switch (status.phase) { + case FileStatusPhase.STARTED: + if (created) this.documentDetectedSubject.next(status) + break + + case FileStatusPhase.SUCCESS: + this.documentConsumptionFinishedSubject.next(status) + break + + case FileStatusPhase.FAILED: + this.documentConsumptionFailedSubject.next(status) + break + + default: + break } } }