diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html index afe325a7f..59958756c 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html @@ -98,9 +98,11 @@ - + @if (permissionService.currentUserCan(PermissionAction.View, PermissionType.OcrTemplate)) { + + } diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts index d3fcd5f08..90257b97a 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts @@ -1310,6 +1310,21 @@ describe('BulkEditorComponent', () => { expect(req.request.body).toEqual({ documents: [3, 4], }) + + component.runZoneOcrSelected() + modal.componentInstance.template = 3 + modal.componentInstance.confirm() + req = httpTestingController.expectOne( + `${environment.apiBaseUrl}documents/run_zone_ocr/` + ) + req.flush(true) + expect(req.request.body).toEqual({ + documents: [3, 4], + template: 3, + }) + httpTestingController.match( + `${environment.apiBaseUrl}ocr_templates/?page=1&page_size=100000` + ) // template list httpTestingController.match( `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true&include_selection_data=true` ) // list reload diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts index 5e78e5e60..26b91ba9d 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts @@ -64,6 +64,7 @@ import { MergeAsVersionsConfirmDialogComponent } from '../../common/confirm-dial import { MergeConfirmDialogComponent } from '../../common/confirm-dialog/merge-confirm-dialog/merge-confirm-dialog.component' import { ReprocessConfirmDialogComponent } from '../../common/confirm-dialog/reprocess-confirm-dialog/reprocess-confirm-dialog.component' import { RotateConfirmDialogComponent } from '../../common/confirm-dialog/rotate-confirm-dialog/rotate-confirm-dialog.component' +import { ZoneOcrConfirmDialogComponent } from '../../common/confirm-dialog/zone-ocr-confirm-dialog/zone-ocr-confirm-dialog.component' import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component' import { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component' import { DocumentTypeEditDialogComponent } from '../../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component' @@ -967,20 +968,25 @@ export class BulkEditorComponent } runZoneOcrSelected() { - const modal = this.modalService.open(ConfirmDialogComponent, { + const modal = this.modalService.open(ZoneOcrConfirmDialogComponent, { backdrop: 'static', }) - modal.componentInstance.title = $localize`Run zone OCR confirm` - modal.componentInstance.messageBold = $localize`This operation will run zone OCR on ${this.getSelectionSize()} selected document(s).` - modal.componentInstance.message = $localize`Fields mapped by each document type's OCR template will be overwritten.` - modal.componentInstance.btnClass = 'btn-warning' - modal.componentInstance.btnCaption = $localize`Proceed` - modal.componentInstance.confirmClicked + const dialog = modal.componentInstance as ZoneOcrConfirmDialogComponent + dialog.title = $localize`Run zone OCR confirm` + dialog.messageBold = $localize`This operation will run zone OCR on ${this.getSelectionSize()} selected document(s).` + dialog.message = $localize`Fields filled by the template will be overwritten.` + dialog.btnClass = 'btn-warning' + dialog.btnCaption = $localize`Proceed` + dialog.confirmClicked .pipe(takeUntil(this.unsubscribeNotifier)) .subscribe(() => { + dialog.buttonsEnabled.set(false) this.executeDocumentAction( modal, - this.documentService.runZoneOcrDocuments(this.getSelectionQuery()) + this.documentService.runZoneOcrDocuments( + this.getSelectionQuery(), + dialog.template + ) ) }) } diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 30520c2e6..f2740b32b 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -361,9 +361,13 @@ export class DocumentService extends AbstractPaperlessService { }) } - runZoneOcrDocuments(selection: DocumentSelectionQuery) { + runZoneOcrDocuments( + selection: DocumentSelectionQuery, + templateId: number | null = null + ) { return this.http.post(this.getResourceUrl(null, 'run_zone_ocr'), { ...selection, + ...(templateId ? { template: templateId } : {}), }) }