From 50a5192c89622200194352f646a5b8a53d926f97 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 8 Sep 2025 09:19:40 -0700 Subject: [PATCH] Fix frontend versions switching [ci skip] --- .../document-detail.component.html | 52 +++++++++---------- .../document-detail.component.ts | 8 ++- .../src/app/services/rest/document.service.ts | 9 +++- src-ui/src/main.ts | 2 + src/documents/serialisers.py | 4 ++ 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index 80a89f180..825ea8b9e 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -1,7 +1,30 @@ + + @if (document?.versions?.length > 0) { +
+
+ + +
+ + +
+ } @if (archiveContentRenderType === ContentRenderType.PDF && !useNativePdfViewer) { @if (previewNumPages) { -
+
Page
of {{previewNumPages}}
@@ -44,27 +67,6 @@ }
- @if (document?.versions?.length > 0) { -
- - -
- } -
- - - -
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 1c7386ea5..62fa941be 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -638,8 +638,10 @@ export class DocumentDetailComponent updateComponent(doc: Document) { this.document = doc - // Default selected version is the head document - this.selectedVersionId = doc.id + // Default selected version is the newest version + this.selectedVersionId = doc.versions?.length + ? Math.max(...doc.versions) + : doc.id this.requiresPassword = false this.updateFormForCustomFields() if (this.archiveContentRenderType === ContentRenderType.TIFF) { @@ -708,6 +710,8 @@ export class DocumentDetailComponent selectVersion(versionId: number) { this.selectedVersionId = versionId this.previewUrl = this.documentsService.getPreviewUrl( + this.documentId, + false, this.selectedVersionId ) this.thumbUrl = this.documentsService.getThumbUrl(this.selectedVersionId) diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index b70e953b9..79eb28467 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -163,12 +163,19 @@ export class DocumentService extends AbstractPaperlessService { }) } - getPreviewUrl(id: number, original: boolean = false): string { + getPreviewUrl( + id: number, + original: boolean = false, + versionID: number = null + ): string { let url = new URL(this.getResourceUrl(id, 'preview')) if (this._searchQuery) url.hash = `#search="${this.searchQuery}"` if (original) { url.searchParams.append('original', 'true') } + if (versionID) { + url.searchParams.append('version', versionID.toString()) + } return url.toString() } diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index 029ec72ac..e744d6058 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -77,6 +77,7 @@ import { fileEarmarkFill, fileEarmarkLock, fileEarmarkMinus, + fileEarmarkPlus, fileEarmarkRichtext, fileText, files, @@ -286,6 +287,7 @@ const icons = { fileEarmarkFill, fileEarmarkLock, fileEarmarkMinus, + fileEarmarkPlus, fileEarmarkRichtext, files, fileText, diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 4d7b27c51..bbcc23934 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -957,6 +957,10 @@ class DocumentSerializer( request.version if request else settings.REST_FRAMEWORK["DEFAULT_VERSION"], ) + if doc.get("versions") is not None: + doc["versions"] = sorted(doc["versions"], reverse=True) + doc["versions"].append(doc["id"]) + if api_version < 9: # provide created as a datetime for backwards compatibility from django.utils import timezone