From 18c4e6029fb84e9f90e5b389bdf2f25ef93d7b7d Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:00:46 -0800 Subject: [PATCH] Fixhancement: restore search highlighting and add for built-in viewer (#8885) --- src-ui/messages.xlf | 79 ++++++++++--------- .../preview-popup.component.html | 3 +- .../preview-popup.component.spec.ts | 20 +++++ .../preview-popup/preview-popup.component.ts | 16 +++- .../services/rest/document.service.spec.ts | 2 +- .../src/app/services/rest/document.service.ts | 14 ++-- 6 files changed, 90 insertions(+), 44 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 0b5d6b7da..4d628135c 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -523,7 +523,7 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 124 + 123 @@ -589,7 +589,7 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 184 + 183 src/app/components/document-detail/document-detail.component.html @@ -723,11 +723,11 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 111 + 110 src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 127 + 126 src/app/components/common/system-status-dialog/system-status-dialog.component.html @@ -1445,7 +1445,7 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 183 + 182 src/app/components/document-list/bulk-editor/bulk-editor.component.html @@ -4310,11 +4310,11 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 104 + 103 src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 138 + 137 @@ -4329,43 +4329,43 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 169 + 168 src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 171 + 170 Create new user account src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts - 66 + 71 Edit user account src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts - 70 + 75 Totp deactivated src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts - 126 + 131 Totp deactivation failed src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts - 129 + 134 src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts - 134 + 139 @@ -4775,35 +4775,42 @@ Use parameters for webhook body src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html - 341 + 342 + + + + Send webhook payload as JSON + + src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html + 343 Webhook params src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html - 343 + 346 Webhook body src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html - 345 + 348 Webhook headers src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html - 347 + 350 Include document src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html - 348 + 351 @@ -5182,7 +5189,7 @@ src/app/components/document-list/document-card-small/document-card-small.component.ts - 118 + 121 @@ -5387,7 +5394,7 @@ src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 156 + 155 src/app/components/common/share-links-dropdown/share-links-dropdown.component.html @@ -5425,11 +5432,11 @@ Copied! src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 55 + 54 src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 163 + 162 src/app/components/common/share-links-dropdown/share-links-dropdown.component.html @@ -5440,91 +5447,91 @@ Warning: changing the token cannot be undone src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 57 + 56 Connected social accounts src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 63 + 62 Set a password before disconnecting social account. src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 67 + 66 Disconnect src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 73 + 72 Disconnect social account src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 75 + 74 Warning: disconnecting social accounts cannot be undone src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 85 + 84 Connect new social account src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 90 + 89 Scan the QR code with your authenticator app and then enter the code below src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 115 + 114 Authenticator secret src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 118 + 117 You can store this secret and use it to reinstall your authenticator app at a later time. src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 119 + 118 Code src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 122 + 121 Recovery codes will not be shown again, make sure to save them. src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 141 + 140 Copy codes src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html - 159 + 158 diff --git a/src-ui/src/app/components/common/preview-popup/preview-popup.component.html b/src-ui/src/app/components/common/preview-popup/preview-popup.component.html index 59c179832..7dc0ee708 100644 --- a/src-ui/src/app/components/common/preview-popup/preview-popup.component.html +++ b/src-ui/src/app/components/common/preview-popup/preview-popup.component.html @@ -28,7 +28,8 @@ [original-size]="false" [show-borders]="false" [show-all]="true" - (error)="onError($event)"> + (text-layer-rendered)="onPageRendered()" + (error)="onError($event)" #pdfViewer> } } diff --git a/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts b/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts index e8d34286e..db2c0d3de 100644 --- a/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts +++ b/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts @@ -158,4 +158,24 @@ describe('PreviewPopupComponent', () => { jest.advanceTimersByTime(1) expect(component.popover.isOpen()).toBeFalsy() }) + + it('should dispatch find event on viewer loaded if searchQuery set', () => { + documentService.searchQuery = 'test' + settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false) + component.popover.open() + jest.advanceTimersByTime(1000) + fixture.detectChanges() + // normally setup by pdf-viewer + jest.replaceProperty(component.pdfViewer, 'eventBus', { + dispatch: jest.fn(), + } as any) + const dispatchSpy = jest.spyOn(component.pdfViewer.eventBus, 'dispatch') + component.onPageRendered() + expect(dispatchSpy).toHaveBeenCalledWith('find', { + query: 'test', + caseSensitive: false, + highlightAll: true, + phraseSearch: true, + }) + }) }) diff --git a/src-ui/src/app/components/common/preview-popup/preview-popup.component.ts b/src-ui/src/app/components/common/preview-popup/preview-popup.component.ts index 039264fd0..2fa1760ec 100644 --- a/src-ui/src/app/components/common/preview-popup/preview-popup.component.ts +++ b/src-ui/src/app/components/common/preview-popup/preview-popup.component.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http' import { Component, Input, OnDestroy, ViewChild } from '@angular/core' import { NgbPopover, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap' -import { PdfViewerModule } from 'ng2-pdf-viewer' +import { PdfViewerComponent, PdfViewerModule } from 'ng2-pdf-viewer' import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons' import { first, Subject, takeUntil } from 'rxjs' import { Document } from 'src/app/data/document' @@ -57,6 +57,8 @@ export class PreviewPopupComponent implements OnDestroy { @ViewChild('popover') popover: NgbPopover + @ViewChild('pdfViewer') pdfViewer: PdfViewerComponent + mouseOnPreview: boolean = false popoverClass: string = 'shadow popover-preview' @@ -114,6 +116,18 @@ export class PreviewPopupComponent implements OnDestroy { } } + onPageRendered() { + // Only triggered by the pngx pdf viewer + if (this.documentService.searchQuery) { + this.pdfViewer.eventBus.dispatch('find', { + query: this.documentService.searchQuery, + caseSensitive: false, + highlightAll: true, + phraseSearch: true, + }) + } + } + get previewUrl() { return this.documentService.getPreviewUrl(this.document.id) } diff --git a/src-ui/src/app/services/rest/document.service.spec.ts b/src-ui/src/app/services/rest/document.service.spec.ts index dd4df41f8..dc358d6c7 100644 --- a/src-ui/src/app/services/rest/document.service.spec.ts +++ b/src-ui/src/app/services/rest/document.service.spec.ts @@ -276,7 +276,7 @@ describe(`DocumentService`, () => { service.searchQuery = searchQuery let url = service.getPreviewUrl(documents[0].id) expect(url).toEqual( - `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/preview/#search="${searchQuery}"` + `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/preview/#search=%22${searchQuery}%22` ) }) diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index d9ae04563..e05ab8373 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -222,12 +222,12 @@ export class DocumentService extends AbstractPaperlessService { } getPreviewUrl(id: number, original: boolean = false): string { - let url = this.getResourceUrl(id, 'preview') - if (this._searchQuery) url += `#search="${this._searchQuery}"` + let url = new URL(this.getResourceUrl(id, 'preview')) + if (this._searchQuery) url.hash = `#search="${this.searchQuery}"` if (original) { - url += '?original=true' + url.searchParams.append('original', 'true') } - return url + return url.toString() } getThumbUrl(id: number): string { @@ -309,6 +309,10 @@ export class DocumentService extends AbstractPaperlessService { } public set searchQuery(query: string) { - this._searchQuery = query + this._searchQuery = query.trim() + } + + public get searchQuery(): string { + return this._searchQuery } }