From 7dc6adfcca7e56b53906adb7110a25545483d1e1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 31 Oct 2019 17:56:39 -0400 Subject: [PATCH] LP1850938 Angular Catalog Preferences Page Adds a new "Catalog Preferences" interface, accessible directly from the catalog. The UI houses the search preferences (default search lib, preferred library, default search tab), a new staff-specific hits-per-page setting. Other preferences may be added later. Adds support for selecting a default search tab using the existing 'eg.search.adv_pane' setting. Reduce API call count by loading more of the catalog preference settings in the main batch invoked by the page resolver. Signed-off-by: Bill Erickson Signed-off-by: Terran McCanna --- .../staff/catalog/basket-actions.component.html | 38 ++++++---- .../eg2/src/app/staff/catalog/catalog.module.ts | 2 + .../eg2/src/app/staff/catalog/catalog.service.ts | 3 + .../eg2/src/app/staff/catalog/prefs.component.html | 84 ++++++++++++++++++++++ .../eg2/src/app/staff/catalog/prefs.component.ts | 73 +++++++++++++++++++ .../eg2/src/app/staff/catalog/resolver.service.ts | 9 +++ .../eg2/src/app/staff/catalog/routing.module.ts | 5 ++ .../src/app/staff/catalog/search-form.component.ts | 20 +++++- .../staff/catalog/search-templates.component.ts | 5 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 10 +++ .../src/sql/Pg/upgrade/XXXX.data.catalog-prefs.sql | 15 ++++ 11 files changed, 244 insertions(+), 20 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.ts create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.catalog-prefs.sql diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html index 2f32c22fc5..752557c503 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html @@ -12,26 +12,34 @@ -
+
- - - - - - - + + + + + + + +
+
+ + + + +
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts index 810b9507fd..d9e2143ed8 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts @@ -30,6 +30,7 @@ import {CnBrowseComponent} from './cnbrowse.component'; import {CnBrowseResultsComponent} from './cnbrowse/results.component'; import {SearchTemplatesComponent} from './search-templates.component'; import {MarcEditModule} from '@eg/staff/share/marc-edit/marc-edit.module'; +import {PreferencesComponent} from './prefs.component'; @NgModule({ declarations: [ @@ -54,6 +55,7 @@ import {MarcEditModule} from '@eg/staff/share/marc-edit/marc-edit.module'; SearchTemplatesComponent, CnBrowseComponent, OpacViewComponent, + PreferencesComponent, CnBrowseResultsComponent ], imports: [ diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts index 86501fc10f..e6da35879b 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts @@ -23,6 +23,9 @@ export class StaffCatalogService { // TODO: does unapi support pref-lib for result-page copy counts? prefOrg: IdlObject; + // Default search tab + defaultTab: string; + // Cache the currently selected detail record (i.g. catalog/record/123) // summary so the record detail component can avoid duplicate fetches // during record tab navigation. diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.html new file mode 100644 index 0000000000..b7ed34ed85 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.html @@ -0,0 +1,84 @@ + + + + + + + +
+
+ +
+
+ + +
+
+ The default search library setting determines what library is + searched from the advanced search screen and portal page by + default. Manual selection of a search library will override it. One + recommendation is to set the search library to the highest point you + would normally want to search. +
+
+ +
+
+ +
+
+ + +
+
+ The preferred library is used to show copies and URIs regardless + of the library searched. One recommendation is to set this to your + workstation library so that local copies show up first in search + results. +
+
+ +
+
+ +
+
+ + + + + + + +
+
+ Focus this search tab by default when opening new catalog pages. +
+
+ +
+
+ +
+
+ +
+
+ The number of search results to display per page. +
+
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.ts new file mode 100644 index 0000000000..7d81a07eb6 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/prefs.component.ts @@ -0,0 +1,73 @@ +import {Component, OnInit, ViewChild} from '@angular/core'; +import {IdlObject} from '@eg/core/idl.service'; +import {StaffCatalogService} from './catalog.service'; +import {ServerStoreService} from '@eg/core/server-store.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; + +/* Component for managing catalog preferences */ + +const CATALOG_PREFS = [ + 'eg.search.search_lib', + 'eg.search.pref_lib', + 'eg.search.adv_pane', + 'eg.catalog.results.count' +]; + +@Component({ + templateUrl: 'prefs.component.html' +}) +export class PreferencesComponent implements OnInit { + + settings: Object = {}; + + @ViewChild('successMsg', {static: false}) successMsg: StringComponent; + @ViewChild('failMsg', {static: false}) failMsg: StringComponent; + + constructor( + private store: ServerStoreService, + private toast: ToastService, + private staffCat: StaffCatalogService, + ) {} + + ngOnInit() { + this.staffCat.createContext(); + + // Pre-fetched by the resolver. + this.store.getItemBatch(CATALOG_PREFS) + .then(settings => this.settings = settings); + } + + orgChanged(org: IdlObject, setting: string) { + const localVar = setting === 'eg.search.search_lib' ? + 'defaultSearchOrg' : 'prefOrg'; + + this.updateValue(setting, org ? org.id() : null) + .then(val => this.staffCat[localVar] = val); + } + + paneChanged(entry: ComboboxEntry) { + this.updateValue('eg.search.adv_pane', entry ? entry.id : null) + .then(value => this.staffCat.defaultTab = value); + } + + countChanged() { + this.updateValue('eg.catalog.results.count', + this.settings['eg.catalog.results.count'] || null) + .then(value => { + this.staffCat.searchContext.pager.limit = value || 20; + }); + } + + updateValue(setting: string, value: any): Promise { + const promise = (value === null) ? + this.store.removeItem(setting) : + this.store.setItem(setting, value); + + return promise + .then(_ => this.toast.success(this.successMsg.text)) + .then(_ => value); + } +} + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts b/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts index 1b6dac1d4a..842893cf11 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts @@ -43,18 +43,27 @@ export class CatalogResolver implements Resolve> { return this.store.getItemBatch([ 'eg.search.search_lib', 'eg.search.pref_lib', + 'eg.search.adv_pane', + 'eg.catalog.results.count', 'cat.holdings_show_empty_org', 'cat.holdings_show_empty', 'cat.marcedit.stack_subfields', 'cat.marcedit.flateditor', 'cat.holdings_show_copies', 'cat.holdings_show_vols', + 'opac.staff_saved_search.size', + 'eg.catalog.search_templates', 'opac.staff_saved_search.size' ]).then(settings => { this.staffCat.defaultSearchOrg = this.org.get(settings['eg.search.search_lib']); this.staffCat.prefOrg = this.org.get(settings['eg.search.pref_lib']); + this.staffCat.defaultTab = settings['eg.search.adv_pane']; + if (settings['eg.catalog.results.count']) { + this.staffCat.defaultSearchLimit = + Number(settings['eg.catalog.results.count']); + } }); } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts index b70290583e..85e958bd84 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts @@ -8,6 +8,7 @@ import {HoldComponent} from './hold/hold.component'; import {BrowseComponent} from './browse.component'; import {CnBrowseComponent} from './cnbrowse.component'; import {CanDeactivateGuard} from '@eg/share/util/can-deactivate.guard'; +import {PreferencesComponent} from './prefs.component'; const routes: Routes = [{ path: '', @@ -35,6 +36,10 @@ const routes: Routes = [{ path: 'cnbrowse', component: CnBrowseComponent, resolve: {catResolver : CatalogResolver} + }, { + path: 'prefs', + component: PreferencesComponent, + resolve: {catResolver : CatalogResolver} } ]; diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts index 42e70861f6..357f7be493 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts @@ -7,6 +7,13 @@ import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search import {StaffCatalogService} from './catalog.service'; import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +// Maps opac-style default tab names to local tab names. +const LEGACY_TAB_NAME_MAP = { + expert: 'marc', + numeric: 'ident', + advanced: 'term' +}; + @Component({ selector: 'eg-catalog-search-form', styleUrls: ['search-form.component.css'], @@ -87,9 +94,18 @@ export class SearchFormComponent implements OnInit, AfterViewInit { this.searchTab = 'ident'; } else if (this.context.browseSearch.isSearchable()) { this.searchTab = 'browse'; - } else { - // Default tab + } else if (this.context.termSearch.isSearchable()) { this.searchTab = 'term'; + + } else { + + this.searchTab = + LEGACY_TAB_NAME_MAP[this.staffCat.defaultTab] + || this.staffCat.defaultTab || 'term'; + + } + + if (this.searchTab === 'term') { this.refreshCopyLocations(); } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-templates.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/search-templates.component.ts index 8a1eb7d0ff..46974509dd 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-templates.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-templates.component.ts @@ -62,10 +62,9 @@ export class SearchTemplatesComponent extends DialogComponent implements OnInit ngOnInit() { this.context = this.staffCat.searchContext; - console.log('ngOnInit() with selected = ', this.staffCat.selectedTemplate); - this.org.settings('opac.staff_saved_search.size').then(sets => { - const size = sets['opac.staff_saved_search.size'] || 0; + this.serverStore.getItem('opac.staff_saved_search.size') + .then(size => { if (!size) { return; } this.recentSearchesCount = Number(size); diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index a49cf02de8..257117b1d0 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -20308,3 +20308,13 @@ VALUES ( ) ); +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.catalog.results.count', 'gui', 'integer', + oils_i18n_gettext( + 'eg.catalog.results.count', + 'Catalog Results Page Size', + 'cwst', 'label' + ) +); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.catalog-prefs.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.catalog-prefs.sql new file mode 100644 index 0000000000..1380afa6af --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.catalog-prefs.sql @@ -0,0 +1,15 @@ +BEGIN; + +-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); + +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.catalog.results.count', 'gui', 'integer', + oils_i18n_gettext( + 'eg.catalog.results.count', + 'Catalog Results Page Size', + 'cwst', 'label' + ) +); + +COMMIT; -- 2.11.0