From 719f76060b04d746aed806f26bf881bbd18e0ba9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 22 May 2024 16:19:46 -0700 Subject: [PATCH] Enhancement: default to title/content search, allow choosing full search link from global search (#6805) --- src-ui/messages.xlf | 186 ++++++++++-------- .../admin/settings/settings.component.html | 18 +- .../admin/settings/settings.component.spec.ts | 2 +- .../admin/settings/settings.component.ts | 10 +- .../global-search.component.html | 8 +- .../global-search.component.spec.ts | 35 +++- .../global-search/global-search.component.ts | 22 ++- src-ui/src/app/data/ui-settings.ts | 11 ++ 8 files changed, 191 insertions(+), 101 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 5edab40e9..37fecf495 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -350,7 +350,7 @@ src/app/components/admin/settings/settings.component.html - 323 + 339 src/app/components/app-frame/app-frame.component.html @@ -563,7 +563,7 @@ src/app/components/admin/settings/settings.component.html - 403 + 419 src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html @@ -705,7 +705,7 @@ src/app/components/admin/settings/settings.component.html - 391 + 407 src/app/components/admin/tasks/tasks.component.html @@ -1025,21 +1025,50 @@ src/app/components/app-frame/global-search/global-search.component.ts - 93 + 104 - - Search database only (do not include advanced search results) + + Do not include advanced search results src/app/components/admin/settings/settings.component.html 204 + + Full search links to + + src/app/components/admin/settings/settings.component.html + 212 + + + + Title and content search + + src/app/components/admin/settings/settings.component.html + 216 + + + + Advanced search + + src/app/components/admin/settings/settings.component.html + 217 + + + src/app/components/app-frame/global-search/global-search.component.html + 24 + + + src/app/components/document-list/filter-editor/filter-editor.component.ts + 143 + + Notes src/app/components/admin/settings/settings.component.html - 208 + 224 src/app/components/document-list/document-list.component.html @@ -1058,14 +1087,14 @@ Enable notes src/app/components/admin/settings/settings.component.html - 212 + 228 Permissions src/app/components/admin/settings/settings.component.html - 220 + 236 src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.html @@ -1120,28 +1149,28 @@ Default Permissions src/app/components/admin/settings/settings.component.html - 223 + 239 Settings apply to this user account for objects (Tags, Mail Rules, etc.) created via the web UI src/app/components/admin/settings/settings.component.html - 227,229 + 243,245 Default Owner src/app/components/admin/settings/settings.component.html - 234 + 250 Objects without an owner can be viewed and edited by all users src/app/components/admin/settings/settings.component.html - 238 + 254 src/app/components/common/input/permissions/permissions-form/permissions-form.component.html @@ -1152,18 +1181,18 @@ Default View Permissions src/app/components/admin/settings/settings.component.html - 243 + 259 Users: src/app/components/admin/settings/settings.component.html - 248 + 264 src/app/components/admin/settings/settings.component.html - 275 + 291 src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html @@ -1194,11 +1223,11 @@ Groups: src/app/components/admin/settings/settings.component.html - 258 + 274 src/app/components/admin/settings/settings.component.html - 285 + 301 src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html @@ -1229,14 +1258,14 @@ Default Edit Permissions src/app/components/admin/settings/settings.component.html - 270 + 286 Edit permissions also grant viewing permissions src/app/components/admin/settings/settings.component.html - 294 + 310 src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html @@ -1255,56 +1284,56 @@ Notifications src/app/components/admin/settings/settings.component.html - 302 + 318 Document processing src/app/components/admin/settings/settings.component.html - 305 + 321 Show notifications when new documents are detected src/app/components/admin/settings/settings.component.html - 309 + 325 Show notifications when document processing completes successfully src/app/components/admin/settings/settings.component.html - 310 + 326 Show notifications when document processing fails src/app/components/admin/settings/settings.component.html - 311 + 327 Suppress notifications on dashboard src/app/components/admin/settings/settings.component.html - 312 + 328 This will suppress all messages about document processing status on the dashboard. src/app/components/admin/settings/settings.component.html - 312 + 328 Saved views src/app/components/admin/settings/settings.component.html - 320 + 336 src/app/components/app-frame/app-frame.component.html @@ -1315,14 +1344,14 @@ Show warning when closing saved views with unsaved changes src/app/components/admin/settings/settings.component.html - 326 + 342 Views src/app/components/admin/settings/settings.component.html - 330 + 346 src/app/components/document-list/document-list.component.html @@ -1333,7 +1362,7 @@ Show on dashboard src/app/components/admin/settings/settings.component.html - 343 + 359 src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html @@ -1344,7 +1373,7 @@ Show in sidebar src/app/components/admin/settings/settings.component.html - 347 + 363 src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html @@ -1355,7 +1384,7 @@ Actions src/app/components/admin/settings/settings.component.html - 351 + 367 src/app/components/admin/tasks/tasks.component.html @@ -1418,7 +1447,7 @@ Delete src/app/components/admin/settings/settings.component.html - 353 + 369 src/app/components/admin/users-groups/users-groups.component.html @@ -1529,42 +1558,42 @@ Documents page size src/app/components/admin/settings/settings.component.html - 364 + 380 Display as src/app/components/admin/settings/settings.component.html - 367 + 383 Table src/app/components/admin/settings/settings.component.html - 369 + 385 Small Cards src/app/components/admin/settings/settings.component.html - 370 + 386 Large Cards src/app/components/admin/settings/settings.component.html - 371 + 387 Show src/app/components/admin/settings/settings.component.html - 375 + 391 src/app/components/document-list/document-list.component.html @@ -1575,7 +1604,7 @@ Default src/app/components/admin/settings/settings.component.html - 375 + 391 src/app/components/document-detail/document-detail.component.html @@ -1586,14 +1615,14 @@ No saved views defined. src/app/components/admin/settings/settings.component.html - 384 + 400 Cancel src/app/components/admin/settings/settings.component.html - 404 + 420 src/app/components/common/confirm-dialog/confirm-dialog.component.ts @@ -1678,7 +1707,7 @@ Error retrieving users src/app/components/admin/settings/settings.component.ts - 189 + 192 src/app/components/admin/users-groups/users-groups.component.ts @@ -1689,7 +1718,7 @@ Error retrieving groups src/app/components/admin/settings/settings.component.ts - 208 + 211 src/app/components/admin/users-groups/users-groups.component.ts @@ -1700,35 +1729,35 @@ Saved view "" deleted. src/app/components/admin/settings/settings.component.ts - 423 + 427 Settings were saved successfully. src/app/components/admin/settings/settings.component.ts - 553 + 561 Settings were saved successfully. Reload is required to apply some changes. src/app/components/admin/settings/settings.component.ts - 557 + 565 Reload now src/app/components/admin/settings/settings.component.ts - 558 + 566 An error occurred while saving settings. src/app/components/admin/settings/settings.component.ts - 568 + 576 src/app/components/app-frame/app-frame.component.ts @@ -1739,7 +1768,7 @@ Error while storing settings on server. src/app/components/admin/settings/settings.component.ts - 602 + 610 @@ -2125,11 +2154,11 @@ src/app/components/app-frame/global-search/global-search.component.html - 55 + 59 src/app/components/app-frame/global-search/global-search.component.html - 72 + 76 src/app/components/common/input/permissions/permissions-form/permissions-form.component.html @@ -2683,41 +2712,34 @@ src/app/components/app-frame/global-search/global-search.component.html 8 - - - Advanced search src/app/components/app-frame/global-search/global-search.component.html - 23 - - - src/app/components/document-list/filter-editor/filter-editor.component.ts - 143 + 26 Open src/app/components/app-frame/global-search/global-search.component.html - 49 + 53 src/app/components/app-frame/global-search/global-search.component.html - 52 + 56 Filter documents src/app/components/app-frame/global-search/global-search.component.html - 58 + 62 Download src/app/components/app-frame/global-search/global-search.component.html - 69 + 73 src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html @@ -2744,113 +2766,113 @@ No results src/app/components/app-frame/global-search/global-search.component.html - 83 + 87 Documents src/app/components/app-frame/global-search/global-search.component.html - 86 + 90 Saved Views src/app/components/app-frame/global-search/global-search.component.html - 92 + 96 Tags src/app/components/app-frame/global-search/global-search.component.html - 99 + 103 Correspondents src/app/components/app-frame/global-search/global-search.component.html - 106 + 110 Document types src/app/components/app-frame/global-search/global-search.component.html - 113 + 117 Storage paths src/app/components/app-frame/global-search/global-search.component.html - 120 + 124 Users src/app/components/app-frame/global-search/global-search.component.html - 127 + 131 Groups src/app/components/app-frame/global-search/global-search.component.html - 134 + 138 Custom fields src/app/components/app-frame/global-search/global-search.component.html - 141 + 145 Mail accounts src/app/components/app-frame/global-search/global-search.component.html - 148 + 152 Mail rules src/app/components/app-frame/global-search/global-search.component.html - 155 + 159 Workflows src/app/components/app-frame/global-search/global-search.component.html - 162 + 166 Successfully updated object. src/app/components/app-frame/global-search/global-search.component.ts - 182 + 193 src/app/components/app-frame/global-search/global-search.component.ts - 220 + 231 Error occurred saving object. src/app/components/app-frame/global-search/global-search.component.ts - 185 + 196 src/app/components/app-frame/global-search/global-search.component.ts - 223 + 234 diff --git a/src-ui/src/app/components/admin/settings/settings.component.html b/src-ui/src/app/components/admin/settings/settings.component.html index 87d7ba68a..bcab7de33 100644 --- a/src-ui/src/app/components/admin/settings/settings.component.html +++ b/src-ui/src/app/components/admin/settings/settings.component.html @@ -201,7 +201,23 @@ - + + + + + + + + + Full search links to + + + + Title and content search + Advanced search + + + diff --git a/src-ui/src/app/components/admin/settings/settings.component.spec.ts b/src-ui/src/app/components/admin/settings/settings.component.spec.ts index 71778d394..47581ddba 100644 --- a/src-ui/src/app/components/admin/settings/settings.component.spec.ts +++ b/src-ui/src/app/components/admin/settings/settings.component.spec.ts @@ -309,7 +309,7 @@ describe('SettingsComponent', () => { expect(toastErrorSpy).toHaveBeenCalled() expect(storeSpy).toHaveBeenCalled() expect(appearanceSettingsSpy).not.toHaveBeenCalled() - expect(setSpy).toHaveBeenCalledTimes(26) + expect(setSpy).toHaveBeenCalledTimes(27) // succeed storeSpy.mockReturnValueOnce(of(true)) diff --git a/src-ui/src/app/components/admin/settings/settings.component.ts b/src-ui/src/app/components/admin/settings/settings.component.ts index 036f27f48..fcb7d7c65 100644 --- a/src-ui/src/app/components/admin/settings/settings.component.ts +++ b/src-ui/src/app/components/admin/settings/settings.component.ts @@ -27,7 +27,7 @@ import { } from 'rxjs' import { Group } from 'src/app/data/group' import { SavedView } from 'src/app/data/saved-view' -import { SETTINGS_KEYS } from 'src/app/data/ui-settings' +import { GlobalSearchType, SETTINGS_KEYS } from 'src/app/data/ui-settings' import { User } from 'src/app/data/user' import { DocumentListViewService } from 'src/app/services/document-list-view.service' import { @@ -101,6 +101,7 @@ export class SettingsComponent defaultPermsEditGroups: new FormControl(null), documentEditingRemoveInboxTags: new FormControl(null), searchDbOnly: new FormControl(null), + searchLink: new FormControl(null), notificationsConsumerNewDocument: new FormControl(null), notificationsConsumerSuccess: new FormControl(null), @@ -129,6 +130,8 @@ export class SettingsComponent public systemStatus: SystemStatus + public readonly GlobalSearchType = GlobalSearchType + get systemStatusHasErrors(): boolean { return ( this.systemStatus.database.status === SystemStatusItemStatus.ERROR || @@ -306,6 +309,7 @@ export class SettingsComponent SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS ), searchDbOnly: this.settings.get(SETTINGS_KEYS.SEARCH_DB_ONLY), + searchLink: this.settings.get(SETTINGS_KEYS.SEARCH_FULL_TYPE), savedViews: {}, } } @@ -539,6 +543,10 @@ export class SettingsComponent SETTINGS_KEYS.SEARCH_DB_ONLY, this.settingsForm.value.searchDbOnly ) + this.settings.set( + SETTINGS_KEYS.SEARCH_FULL_TYPE, + this.settingsForm.value.searchLink + ) this.settings.setLanguage(this.settingsForm.value.displayLanguage) this.settings .storeSettings() diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.html b/src-ui/src/app/components/app-frame/global-search/global-search.component.html index eeb118967..1e51dc1b6 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.html +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.html @@ -19,8 +19,12 @@ @if (query) { - - Advanced search + + @if (useAdvancedForFullSearch) { + Advanced search + } @else { + Search + } } diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts index 076fa95d1..f2a1ac3a6 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts @@ -25,6 +25,7 @@ import { FILTER_HAS_DOCUMENT_TYPE_ANY, FILTER_HAS_STORAGE_PATH_ANY, FILTER_HAS_TAGS_ALL, + FILTER_TITLE_CONTENT, } from 'src/app/data/filter-rule-type' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { DocumentService } from 'src/app/services/rest/document.service' @@ -37,6 +38,8 @@ import { ElementRef } from '@angular/core' import { ToastService } from 'src/app/services/toast.service' import { DataType } from 'src/app/data/datatype' import { queryParamsFromFilterRules } from 'src/app/utils/query-params' +import { SettingsService } from 'src/app/services/settings.service' +import { GlobalSearchType, SETTINGS_KEYS } from 'src/app/data/ui-settings' const searchResults = { total: 11, @@ -130,6 +133,7 @@ describe('GlobalSearchComponent', () => { let documentService: DocumentService let documentListViewService: DocumentListViewService let toastService: ToastService + let settingsService: SettingsService beforeEach(async () => { await TestBed.configureTestingModule({ @@ -150,6 +154,7 @@ describe('GlobalSearchComponent', () => { documentService = TestBed.inject(DocumentService) documentListViewService = TestBed.inject(DocumentListViewService) toastService = TestBed.inject(ToastService) + settingsService = TestBed.inject(SettingsService) fixture = TestBed.createComponent(GlobalSearchComponent) component = fixture.componentInstance @@ -262,7 +267,7 @@ describe('GlobalSearchComponent', () => { component.searchResults = searchResults as any component.resultsDropdown.open() component.query = 'test' - const advancedSearchSpy = jest.spyOn(component, 'runAdvanedSearch') + const advancedSearchSpy = jest.spyOn(component, 'runFullSearch') component.searchInputKeyDown(new KeyboardEvent('keydown', { key: 'Enter' })) expect(advancedSearchSpy).toHaveBeenCalled() }) @@ -499,15 +504,6 @@ describe('GlobalSearchComponent', () => { expect(focusSpy).toHaveBeenCalled() }) - it('should support explicit advanced search', () => { - const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') - component.query = 'test' - component.runAdvanedSearch() - expect(qfSpy).toHaveBeenCalledWith([ - { rule_type: FILTER_FULLTEXT_QUERY, value: 'test' }, - ]) - }) - it('should support open in new window', () => { const openSpy = jest.spyOn(window, 'open') const event = new Event('click') @@ -528,4 +524,23 @@ describe('GlobalSearchComponent', () => { button.dispatchEvent(keyboardEvent) expect(dispatchSpy).toHaveBeenCalledTimes(2) // once for keydown, second for click }) + + it('should support title content search and advanced search', () => { + const qfSpy = jest.spyOn(documentListViewService, 'quickFilter') + component.query = 'test' + component.runFullSearch() + expect(qfSpy).toHaveBeenCalledWith([ + { rule_type: FILTER_TITLE_CONTENT, value: 'test' }, + ]) + + settingsService.set( + SETTINGS_KEYS.SEARCH_FULL_TYPE, + GlobalSearchType.ADVANCED + ) + component.query = 'test' + component.runFullSearch() + expect(qfSpy).toHaveBeenCalledWith([ + { rule_type: FILTER_FULLTEXT_QUERY, value: 'test' }, + ]) + }) }) diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.ts index 2742ff59a..dda1bc5f3 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.ts @@ -15,6 +15,7 @@ import { FILTER_HAS_DOCUMENT_TYPE_ANY, FILTER_HAS_STORAGE_PATH_ANY, FILTER_HAS_TAGS_ALL, + FILTER_TITLE_CONTENT, } from 'src/app/data/filter-rule-type' import { DataType } from 'src/app/data/datatype' import { ObjectWithId } from 'src/app/data/object-with-id' @@ -42,6 +43,8 @@ import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dial import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component' import { HotKeyService } from 'src/app/services/hot-key.service' import { paramsFromViewState } from 'src/app/utils/query-params' +import { SettingsService } from 'src/app/services/settings.service' +import { GlobalSearchType, SETTINGS_KEYS } from 'src/app/data/ui-settings' @Component({ selector: 'pngx-global-search', @@ -63,6 +66,13 @@ export class GlobalSearchComponent implements OnInit { @ViewChildren('primaryButton') primaryButtons: QueryList @ViewChildren('secondaryButton') secondaryButtons: QueryList + get useAdvancedForFullSearch(): boolean { + return ( + this.settingsService.get(SETTINGS_KEYS.SEARCH_FULL_TYPE) === + GlobalSearchType.ADVANCED + ) + } + constructor( public searchService: SearchService, private router: Router, @@ -71,7 +81,8 @@ export class GlobalSearchComponent implements OnInit { private documentListViewService: DocumentListViewService, private permissionsService: PermissionsService, private toastService: ToastService, - private hotkeyService: HotKeyService + private hotkeyService: HotKeyService, + private settingsService: SettingsService ) { this.queryDebounce = new Subject() @@ -282,7 +293,7 @@ export class GlobalSearchComponent implements OnInit { this.primaryButtons.first.nativeElement.click() this.searchInput.nativeElement.blur() } else if (this.query?.length) { - this.runAdvanedSearch() + this.runFullSearch() this.reset(true) } } else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) { @@ -378,9 +389,12 @@ export class GlobalSearchComponent implements OnInit { ) } - public runAdvanedSearch() { + public runFullSearch() { + const ruleType = this.useAdvancedForFullSearch + ? FILTER_FULLTEXT_QUERY + : FILTER_TITLE_CONTENT this.documentListViewService.quickFilter([ - { rule_type: FILTER_FULLTEXT_QUERY, value: this.query }, + { rule_type: ruleType, value: this.query }, ]) this.reset(true) } diff --git a/src-ui/src/app/data/ui-settings.ts b/src-ui/src/app/data/ui-settings.ts index 6f8f246ff..29ea08786 100644 --- a/src-ui/src/app/data/ui-settings.ts +++ b/src-ui/src/app/data/ui-settings.ts @@ -12,6 +12,11 @@ export interface UiSetting { default: any } +export enum GlobalSearchType { + ADVANCED = 'advanced', + TITLE_CONTENT = 'title-content', +} + export const SETTINGS_KEYS = { LANGUAGE: 'language', APP_LOGO: 'app_logo', @@ -57,6 +62,7 @@ export const SETTINGS_KEYS = { DOCUMENT_EDITING_REMOVE_INBOX_TAGS: 'general-settings:document-editing:remove-inbox-tags', SEARCH_DB_ONLY: 'general-settings:search:db-only', + SEARCH_FULL_TYPE: 'general-settings:search:more-link', } export const SETTINGS: UiSetting[] = [ @@ -225,4 +231,9 @@ export const SETTINGS: UiSetting[] = [ type: 'boolean', default: false, }, + { + key: SETTINGS_KEYS.SEARCH_FULL_TYPE, + type: 'string', + default: GlobalSearchType.TITLE_CONTENT, + }, ]