Fixhancement: restore search highlighting and add for built-in viewer (#8885)

This commit is contained in:
shamoon 2025-01-23 15:00:46 -08:00 committed by GitHub
parent 6c34e37838
commit 18c4e6029f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 90 additions and 44 deletions

View File

@ -523,7 +523,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">124</context>
<context context-type="linenumber">123</context>
</context-group>
</trans-unit>
<trans-unit id="3823219296477075982" datatype="html">
@ -589,7 +589,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">184</context>
<context context-type="linenumber">183</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-detail/document-detail.component.html</context>
@ -723,11 +723,11 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">111</context>
<context context-type="linenumber">110</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">127</context>
<context context-type="linenumber">126</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/system-status-dialog/system-status-dialog.component.html</context>
@ -1445,7 +1445,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">183</context>
<context context-type="linenumber">182</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>
@ -4310,11 +4310,11 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">104</context>
<context context-type="linenumber">103</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">138</context>
<context context-type="linenumber">137</context>
</context-group>
</trans-unit>
<trans-unit id="8418597938335066730" datatype="html">
@ -4329,43 +4329,43 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">169</context>
<context context-type="linenumber">168</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">171</context>
<context context-type="linenumber">170</context>
</context-group>
</trans-unit>
<trans-unit id="1436831433675346331" datatype="html">
<source>Create new user account</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts</context>
<context context-type="linenumber">66</context>
<context context-type="linenumber">71</context>
</context-group>
</trans-unit>
<trans-unit id="2887331217965896363" datatype="html">
<source>Edit user account</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts</context>
<context context-type="linenumber">70</context>
<context context-type="linenumber">75</context>
</context-group>
</trans-unit>
<trans-unit id="5872286584705575476" datatype="html">
<source>Totp deactivated</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts</context>
<context context-type="linenumber">126</context>
<context context-type="linenumber">131</context>
</context-group>
</trans-unit>
<trans-unit id="6439190193788239059" datatype="html">
<source>Totp deactivation failed</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts</context>
<context context-type="linenumber">129</context>
<context context-type="linenumber">134</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts</context>
<context context-type="linenumber">134</context>
<context context-type="linenumber">139</context>
</context-group>
</trans-unit>
<trans-unit id="8419515490539218007" datatype="html">
@ -4775,35 +4775,42 @@
<source>Use parameters for webhook body</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>
<context context-type="linenumber">341</context>
<context context-type="linenumber">342</context>
</context-group>
</trans-unit>
<trans-unit id="4078214298308732810" datatype="html">
<source>Send webhook payload as JSON</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>
<context context-type="linenumber">343</context>
</context-group>
</trans-unit>
<trans-unit id="6806149889743731985" datatype="html">
<source>Webhook params</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>
<context context-type="linenumber">343</context>
<context context-type="linenumber">346</context>
</context-group>
</trans-unit>
<trans-unit id="7089924379374330" datatype="html">
<source>Webhook body</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>
<context context-type="linenumber">345</context>
<context context-type="linenumber">348</context>
</context-group>
</trans-unit>
<trans-unit id="3829826512656746316" datatype="html">
<source>Webhook headers</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>
<context context-type="linenumber">347</context>
<context context-type="linenumber">350</context>
</context-group>
</trans-unit>
<trans-unit id="2114525789021600887" datatype="html">
<source>Include document</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>
<context context-type="linenumber">348</context>
<context context-type="linenumber">351</context>
</context-group>
</trans-unit>
<trans-unit id="4626030417479279989" datatype="html">
@ -5182,7 +5189,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-small/document-card-small.component.ts</context>
<context context-type="linenumber">118</context>
<context context-type="linenumber">121</context>
</context-group>
</trans-unit>
<trans-unit id="2504502765849142619" datatype="html">
@ -5387,7 +5394,7 @@
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">156</context>
<context context-type="linenumber">155</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.html</context>
@ -5425,11 +5432,11 @@
<source>Copied!</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">55</context>
<context context-type="linenumber">54</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">163</context>
<context context-type="linenumber">162</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.html</context>
@ -5440,91 +5447,91 @@
<source>Warning: changing the token cannot be undone</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">57</context>
<context context-type="linenumber">56</context>
</context-group>
</trans-unit>
<trans-unit id="8935717557476105185" datatype="html">
<source>Connected social accounts</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">63</context>
<context context-type="linenumber">62</context>
</context-group>
</trans-unit>
<trans-unit id="8383227756109993898" datatype="html">
<source>Set a password before disconnecting social account.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">67</context>
<context context-type="linenumber">66</context>
</context-group>
</trans-unit>
<trans-unit id="2907016025519254862" datatype="html">
<source>Disconnect</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">73</context>
<context context-type="linenumber">72</context>
</context-group>
</trans-unit>
<trans-unit id="5322995394400578831" datatype="html">
<source>Disconnect <x id="INTERPOLATION" equiv-text="{{ account.name }}"/> social account</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">75</context>
<context context-type="linenumber">74</context>
</context-group>
</trans-unit>
<trans-unit id="649824314893051979" datatype="html">
<source>Warning: disconnecting social accounts cannot be undone</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">85</context>
<context context-type="linenumber">84</context>
</context-group>
</trans-unit>
<trans-unit id="1375396510511350122" datatype="html">
<source>Connect new social account</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">90</context>
<context context-type="linenumber">89</context>
</context-group>
</trans-unit>
<trans-unit id="4187671210825254690" datatype="html">
<source>Scan the QR code with your authenticator app and then enter the code below</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">115</context>
<context context-type="linenumber">114</context>
</context-group>
</trans-unit>
<trans-unit id="5867169599865838267" datatype="html">
<source>Authenticator secret</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">118</context>
<context context-type="linenumber">117</context>
</context-group>
</trans-unit>
<trans-unit id="5331198279926709145" datatype="html">
<source>You can store this secret and use it to reinstall your authenticator app at a later time.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">119</context>
<context context-type="linenumber">118</context>
</context-group>
</trans-unit>
<trans-unit id="8186013988289067040" datatype="html">
<source>Code</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">122</context>
<context context-type="linenumber">121</context>
</context-group>
</trans-unit>
<trans-unit id="3176701652604668614" datatype="html">
<source>Recovery codes will not be shown again, make sure to save them.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">141</context>
<context context-type="linenumber">140</context>
</context-group>
</trans-unit>
<trans-unit id="2722512118372958038" datatype="html">
<source>Copy codes</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
<context context-type="linenumber">159</context>
<context context-type="linenumber">158</context>
</context-group>
</trans-unit>
<trans-unit id="6141884091799403188" datatype="html">

View File

@ -28,7 +28,8 @@
[original-size]="false"
[show-borders]="false"
[show-all]="true"
(error)="onError($event)">
(text-layer-rendered)="onPageRendered()"
(error)="onError($event)" #pdfViewer>
</pdf-viewer>
}
}

View File

@ -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,
})
})
})

View File

@ -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)
}

View File

@ -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`
)
})

View File

@ -222,12 +222,12 @@ export class DocumentService extends AbstractPaperlessService<Document> {
}
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<Document> {
}
public set searchQuery(query: string) {
this._searchQuery = query
this._searchQuery = query.trim()
}
public get searchQuery(): string {
return this._searchQuery
}
}