mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-27 06:14:54 +00:00
Fix: propagate reload to PDF viewer even when URL doesnt change
This commit is contained in:
@@ -283,6 +283,22 @@ describe('PngxPdfViewerComponent', () => {
|
||||
expect(mockViewer.currentPageNumber).toBe(1)
|
||||
})
|
||||
|
||||
it('reloads when the source revision changes', () => {
|
||||
const resetSpy = jest.spyOn(component as any, 'resetViewerState')
|
||||
const loadSpy = jest
|
||||
.spyOn(component as any, 'loadDocument')
|
||||
.mockImplementation(() => {})
|
||||
component.src = 'test.pdf'
|
||||
component.sourceRevision = 1
|
||||
|
||||
component.ngOnChanges({
|
||||
sourceRevision: new SimpleChange(0, 1, false),
|
||||
})
|
||||
|
||||
expect(resetSpy).toHaveBeenCalled()
|
||||
expect(loadSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('applies viewer state after view init when already loaded', () => {
|
||||
const applySpy = jest.spyOn(component as any, 'applyViewerState')
|
||||
;(component as any).hasLoaded = true
|
||||
|
||||
@@ -43,6 +43,7 @@ export class PngxPdfViewerComponent
|
||||
private readonly document = inject<Document>(DOCUMENT)
|
||||
|
||||
@Input() src!: string
|
||||
@Input() sourceRevision = 0
|
||||
@Input() password?: string
|
||||
@Input() page?: number
|
||||
@Output() pageChange = new EventEmitter<number>()
|
||||
@@ -93,7 +94,7 @@ export class PngxPdfViewerComponent
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['src'] || changes['password']) {
|
||||
if (changes['src'] || changes['sourceRevision'] || changes['password']) {
|
||||
this.resetViewerState()
|
||||
if (this.src) {
|
||||
this.loadDocument()
|
||||
|
||||
@@ -472,6 +472,7 @@
|
||||
<div class="preview-sticky pdf-viewer-container">
|
||||
<pngx-pdf-viewer
|
||||
[src]="pdfSource()"
|
||||
[sourceRevision]="previewRevision()"
|
||||
[password]="pdfPassword()"
|
||||
[renderMode]="PdfRenderMode.All"
|
||||
[page]="previewCurrentPage()" (pageChange)="previewCurrentPage.set($event)"
|
||||
|
||||
@@ -1602,6 +1602,7 @@ describe('DocumentDetailComponent', () => {
|
||||
expect(openDoc.__changedFields).toEqual([])
|
||||
expect(setDirtySpy).toHaveBeenCalledWith(openDoc, false)
|
||||
expect(saveSpy).toHaveBeenCalled()
|
||||
expect(component.previewRevision()).toBe(1)
|
||||
})
|
||||
|
||||
it('should ignore incoming update for a different document id', () => {
|
||||
|
||||
@@ -249,6 +249,7 @@ export class DocumentDetailComponent
|
||||
titleSubject: Subject<string> = new Subject()
|
||||
readonly previewUrl = signal<string>(undefined)
|
||||
readonly pdfSource = signal<string>(undefined)
|
||||
readonly previewRevision = signal(0)
|
||||
readonly pdfPassword = signal<string>(undefined)
|
||||
readonly thumbUrl = signal<string>(undefined)
|
||||
readonly previewText = signal<string>(undefined)
|
||||
@@ -609,6 +610,9 @@ export class DocumentDetailComponent
|
||||
.subscribe()
|
||||
}
|
||||
this.updateComponent(useDoc)
|
||||
if (forceRemote) {
|
||||
this.previewRevision.update((revision) => revision + 1)
|
||||
}
|
||||
this.titleSubject
|
||||
.pipe(
|
||||
debounceTime(1000),
|
||||
|
||||
Reference in New Issue
Block a user