mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-20 00:39:32 -06:00
Queue updates to handle workflow triggering
This commit is contained in:
@@ -1236,6 +1236,24 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(confirmDialog.messageBold).toContain('Document was updated at')
|
expect(confirmDialog.messageBold).toContain('Document was updated at')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should queue incoming update while network is active and flush after', () => {
|
||||||
|
initNormally()
|
||||||
|
const loadSpy = jest.spyOn(component as any, 'loadDocument')
|
||||||
|
|
||||||
|
component.networkActive = true
|
||||||
|
;(component as any).handleIncomingDocumentUpdated({
|
||||||
|
document_id: component.documentId,
|
||||||
|
modified: '2026-02-17T00:00:00Z',
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(loadSpy).not.toHaveBeenCalled()
|
||||||
|
|
||||||
|
component.networkActive = false
|
||||||
|
;(component as any).flushPendingIncomingUpdate()
|
||||||
|
|
||||||
|
expect(loadSpy).toHaveBeenCalledWith(component.documentId, true)
|
||||||
|
})
|
||||||
|
|
||||||
it('should change preview element by render type', () => {
|
it('should change preview element by render type', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.document.archived_file_name = 'file.pdf'
|
component.document.archived_file_name = 'file.pdf'
|
||||||
|
|||||||
@@ -144,6 +144,11 @@ enum ContentRenderType {
|
|||||||
TIFF = 'tiff',
|
TIFF = 'tiff',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IncomingDocumentUpdate {
|
||||||
|
document_id: number
|
||||||
|
modified?: string
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'pngx-document-detail',
|
selector: 'pngx-document-detail',
|
||||||
templateUrl: './document-detail.component.html',
|
templateUrl: './document-detail.component.html',
|
||||||
@@ -265,6 +270,7 @@ export class DocumentDetailComponent
|
|||||||
unsubscribeNotifier: Subject<any> = new Subject()
|
unsubscribeNotifier: Subject<any> = new Subject()
|
||||||
docChangeNotifier: Subject<any> = new Subject()
|
docChangeNotifier: Subject<any> = new Subject()
|
||||||
private incomingUpdateModal: NgbModalRef
|
private incomingUpdateModal: NgbModalRef
|
||||||
|
private pendingIncomingUpdate: IncomingDocumentUpdate
|
||||||
|
|
||||||
requiresPassword: boolean = false
|
requiresPassword: boolean = false
|
||||||
password: string
|
password: string
|
||||||
@@ -483,8 +489,16 @@ export class DocumentDetailComponent
|
|||||||
this.incomingUpdateModal = null
|
this.incomingUpdateModal = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private flushPendingIncomingUpdate() {
|
||||||
|
if (!this.pendingIncomingUpdate || this.networkActive) return
|
||||||
|
const pendingUpdate = this.pendingIncomingUpdate
|
||||||
|
this.pendingIncomingUpdate = null
|
||||||
|
this.handleIncomingDocumentUpdated(pendingUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
private loadDocument(documentId: number, forceRemote: boolean = false): void {
|
private loadDocument(documentId: number, forceRemote: boolean = false): void {
|
||||||
this.closeIncomingUpdateModal()
|
this.closeIncomingUpdateModal()
|
||||||
|
this.pendingIncomingUpdate = null
|
||||||
this.previewUrl = this.documentsService.getPreviewUrl(documentId)
|
this.previewUrl = this.documentsService.getPreviewUrl(documentId)
|
||||||
this.updatePdfSource()
|
this.updatePdfSource()
|
||||||
this.http
|
this.http
|
||||||
@@ -578,12 +592,17 @@ export class DocumentDetailComponent
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleIncomingDocumentUpdated(data: {
|
private handleIncomingDocumentUpdated(data: IncomingDocumentUpdate): void {
|
||||||
document_id: number
|
if (
|
||||||
modified?: string
|
!this.documentId ||
|
||||||
}): void {
|
!this.document ||
|
||||||
if (!this.documentId || data.document_id !== this.documentId) return
|
data.document_id !== this.documentId
|
||||||
if (!this.document || this.networkActive) return
|
)
|
||||||
|
return
|
||||||
|
if (this.networkActive) {
|
||||||
|
this.pendingIncomingUpdate = data
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (this.openDocumentService.isDirty(this.document)) {
|
if (this.openDocumentService.isDirty(this.document)) {
|
||||||
this.showIncomingUpdateModal(data.modified)
|
this.showIncomingUpdateModal(data.modified)
|
||||||
@@ -1064,11 +1083,13 @@ export class DocumentDetailComponent
|
|||||||
this.networkActive = false
|
this.networkActive = false
|
||||||
this.error = null
|
this.error = null
|
||||||
if (close) {
|
if (close) {
|
||||||
|
this.pendingIncomingUpdate = null
|
||||||
this.close(() =>
|
this.close(() =>
|
||||||
this.openDocumentService.refreshDocument(this.documentId)
|
this.openDocumentService.refreshDocument(this.documentId)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this.openDocumentService.refreshDocument(this.documentId)
|
this.openDocumentService.refreshDocument(this.documentId)
|
||||||
|
this.flushPendingIncomingUpdate()
|
||||||
}
|
}
|
||||||
this.savedViewService.maybeRefreshDocumentCounts()
|
this.savedViewService.maybeRefreshDocumentCounts()
|
||||||
},
|
},
|
||||||
@@ -1093,6 +1114,7 @@ export class DocumentDetailComponent
|
|||||||
error
|
error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
this.flushPendingIncomingUpdate()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1132,6 +1154,7 @@ export class DocumentDetailComponent
|
|||||||
this.closeIncomingUpdateModal()
|
this.closeIncomingUpdateModal()
|
||||||
this.error = null
|
this.error = null
|
||||||
this.networkActive = false
|
this.networkActive = false
|
||||||
|
this.pendingIncomingUpdate = null
|
||||||
if (closeResult && updateResult && nextDocId) {
|
if (closeResult && updateResult && nextDocId) {
|
||||||
this.router.navigate(['documents', nextDocId])
|
this.router.navigate(['documents', nextDocId])
|
||||||
this.titleInput?.focus()
|
this.titleInput?.focus()
|
||||||
@@ -1141,6 +1164,7 @@ export class DocumentDetailComponent
|
|||||||
this.networkActive = false
|
this.networkActive = false
|
||||||
this.error = error.error
|
this.error = error.error
|
||||||
this.toastService.showError($localize`Error saving document`, error)
|
this.toastService.showError($localize`Error saving document`, error)
|
||||||
|
this.flushPendingIncomingUpdate()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user