mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-10 00:18:41 +00:00
Crap missed versioning stuff, default to latest but allow specific
This commit is contained in:
10 files changed
+157
-32
No files matched your search
@@ -1909,9 +1909,10 @@ describe('DocumentDetailComponent', () => {
|
||||
expect(toastSpy).toHaveBeenCalledWith('Document reloaded.')
|
||||
})
|
||||
|
||||
it('should run zone OCR, report results and reload the document', () => {
|
||||
it('should run a chosen zone OCR template on the selected version and reload', () => {
|
||||
component.documentId.set(doc.id)
|
||||
component.document.set(doc)
|
||||
component.document.set({ ...doc, versions: docVersions })
|
||||
component.selectedVersionId.set(10)
|
||||
jest.spyOn(documentService, 'runZoneOcr').mockReturnValue(
|
||||
of({
|
||||
results: [
|
||||
@@ -1935,7 +1936,7 @@ describe('DocumentDetailComponent', () => {
|
||||
dialog.template = 3
|
||||
dialog.confirmClicked.emit()
|
||||
|
||||
expect(documentService.runZoneOcr).toHaveBeenCalledWith(doc.id, 3)
|
||||
expect(documentService.runZoneOcr).toHaveBeenCalledWith(doc.id, 3, 10)
|
||||
expect(toastSpy).toHaveBeenCalledWith(
|
||||
'Filled 1 of 2 fields. No value found for: Due'
|
||||
)
|
||||
@@ -1949,7 +1950,8 @@ describe('DocumentDetailComponent', () => {
|
||||
|
||||
it('should summarize zone OCR results', () => {
|
||||
component.documentId.set(doc.id)
|
||||
component.document.set(doc)
|
||||
component.document.set({ ...doc, versions: docVersions })
|
||||
component.selectedVersionId.set(12)
|
||||
jest.spyOn(component as any, 'loadDocument').mockImplementation(() => {})
|
||||
const runSpy = jest.spyOn(documentService, 'runZoneOcr')
|
||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||
@@ -1958,7 +1960,7 @@ describe('DocumentDetailComponent', () => {
|
||||
runSpy.mockReturnValueOnce(of({ status: 'completed', results: [] }))
|
||||
component.runZoneOcr()
|
||||
expect(modalSpy).not.toHaveBeenCalled()
|
||||
expect(runSpy).toHaveBeenCalledWith(doc.id, null)
|
||||
expect(runSpy).toHaveBeenCalledWith(doc.id, null, null)
|
||||
expect(toastSpy).toHaveBeenLastCalledWith(
|
||||
'Zone OCR found no fields to fill.'
|
||||
)
|
||||
@@ -2016,7 +2018,12 @@ describe('DocumentDetailComponent', () => {
|
||||
|
||||
it('should not allow saving or a second zone OCR run while one is running', () => {
|
||||
component.documentId.set(doc.id)
|
||||
component.document.set({ ...doc, __changedFields: ['title'] })
|
||||
component.document.set({
|
||||
...doc,
|
||||
versions: docVersions,
|
||||
__changedFields: ['title'],
|
||||
})
|
||||
component.selectedVersionId.set(doc.id)
|
||||
const pending = new Subject<any>()
|
||||
const runSpy = jest
|
||||
.spyOn(documentService, 'runZoneOcr')
|
||||
@@ -2026,7 +2033,7 @@ describe('DocumentDetailComponent', () => {
|
||||
component.runZoneOcr()
|
||||
modalSpy.mock.results[0].value.componentInstance.confirmClicked.emit()
|
||||
|
||||
expect(runSpy).toHaveBeenCalledWith(doc.id, null)
|
||||
expect(runSpy).toHaveBeenCalledWith(doc.id, null, doc.id)
|
||||
expect(component.zoneOcrRunning()).toBe(true)
|
||||
expect(component.networkActive()).toBe(true)
|
||||
const saveSpy = jest.spyOn(documentService, 'patch')
|
||||
|
||||
@@ -1572,8 +1572,9 @@ export class DocumentDetailComponent
|
||||
runZoneOcr() {
|
||||
if (this.networkActive()) return
|
||||
const documentId = this.documentId()
|
||||
const versionId = this.getSelectedNonLatestVersionId()
|
||||
if (!this.hasLocalEdits(this.document())) {
|
||||
this.executeZoneOcr(documentId, null)
|
||||
this.executeZoneOcr(documentId, null, versionId)
|
||||
return
|
||||
}
|
||||
const modal = this.modalService.open(ConfirmDialogComponent, {
|
||||
@@ -1589,7 +1590,7 @@ export class DocumentDetailComponent
|
||||
.subscribe(() => {
|
||||
modal.close()
|
||||
if (this.documentId() === documentId && !this.networkActive()) {
|
||||
this.executeZoneOcr(documentId, null)
|
||||
this.executeZoneOcr(documentId, null, versionId)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1598,6 +1599,7 @@ export class DocumentDetailComponent
|
||||
runZoneOcrWithOptions() {
|
||||
if (this.networkActive()) return
|
||||
const documentId = this.documentId()
|
||||
const versionId = this.getSelectedNonLatestVersionId()
|
||||
const modal = this.modalService.open(ZoneOcrConfirmDialogComponent, {
|
||||
backdrop: 'static',
|
||||
})
|
||||
@@ -1616,16 +1618,20 @@ export class DocumentDetailComponent
|
||||
.subscribe(() => {
|
||||
modal.close()
|
||||
if (this.documentId() === documentId && !this.networkActive()) {
|
||||
this.executeZoneOcr(documentId, dialog.template)
|
||||
this.executeZoneOcr(documentId, dialog.template, versionId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private executeZoneOcr(documentId: number, templateId: number | null) {
|
||||
private executeZoneOcr(
|
||||
documentId: number,
|
||||
templateId: number | null,
|
||||
versionId: number | null
|
||||
) {
|
||||
this.zoneOcrRunning.set(true)
|
||||
this.networkActive.set(true)
|
||||
this.documentsService
|
||||
.runZoneOcr(documentId, templateId)
|
||||
.runZoneOcr(documentId, templateId, versionId)
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
|
||||
@@ -572,8 +572,8 @@ describe(`DocumentService`, () => {
|
||||
expect(req.request.body).toEqual({})
|
||||
req.flush({ status: 'completed', results: [] })
|
||||
|
||||
subscription = service.runZoneOcr(documents[0].id, 3).subscribe()
|
||||
req = httpTestingController.expectOne(url)
|
||||
subscription = service.runZoneOcr(documents[0].id, 3, 10).subscribe()
|
||||
req = httpTestingController.expectOne(`${url}?version=10`)
|
||||
expect(req.request.body).toEqual({ template: 3 })
|
||||
req.flush({ status: 'completed', results: [] })
|
||||
})
|
||||
|
||||
@@ -373,11 +373,13 @@ export class DocumentService extends AbstractPaperlessService<Document> {
|
||||
|
||||
runZoneOcr(
|
||||
id: number,
|
||||
templateId: number | null = null
|
||||
templateId: number | null = null,
|
||||
versionId: number | null = null
|
||||
): Observable<OcrZoneRunResponse> {
|
||||
return this.http.post<OcrZoneRunResponse>(
|
||||
this.getResourceUrl(id, 'run-zone-ocr'),
|
||||
templateId ? { template: templateId } : {}
|
||||
templateId ? { template: templateId } : {},
|
||||
{ params: versionId ? { version: versionId.toString() } : {} }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user