From 14f46ebbf9d72d7395bf70ada12f09b39a72e5ff Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 22 Jul 2019 17:50:01 -0400 Subject: [PATCH] LPXXX Ang cat search filters / recents WIP Signed-off-by: Bill Erickson --- .../eg2/src/app/share/catalog/search-context.ts | 52 +++++++++++ .../eg2/src/app/staff/catalog/catalog.module.ts | 2 + .../eg2/src/app/staff/catalog/resolver.service.ts | 3 +- .../staff/catalog/search-filters.component.html | 62 +++++++++++++ .../app/staff/catalog/search-filters.component.ts | 100 +++++++++++++++++++++ .../app/staff/catalog/search-form.component.html | 8 ++ .../src/app/staff/catalog/search-form.component.ts | 36 +------- .../sql/Pg/upgrade/XXXX.data.search-templates.sql | 18 ++++ 8 files changed, 247 insertions(+), 34 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.ts create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.search-templates.sql diff --git a/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts b/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts index ef0fd552ea..565eca395b 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts @@ -483,5 +483,57 @@ export class CatalogSearchContext { return str; } + + // A search context can collect enough data for multiple search + // types to be searchable (e.g. users navigate through parts of a + // search form). Calling this method and providing a search type + // ensures the context is cleared of any data unrelated to the + // desired type. + scrub(searchType: string): void { + + switch (searchType) { + + case 'term': // AKA keyword search + this.marcSearch.reset(); + this.browseSearch.reset(); + this.identSearch.reset(); + this.cnBrowseSearch.reset(); + this.termSearch.hasBrowseEntry = ''; + this.termSearch.browseEntry = null; + this.termSearch.fromMetarecord = null; + this.termSearch.facetFilters = []; + break; + + case 'ident': + this.marcSearch.reset(); + this.browseSearch.reset(); + this.termSearch.reset(); + this.cnBrowseSearch.reset(); + break; + + case 'marc': + this.browseSearch.reset(); + this.termSearch.reset(); + this.identSearch.reset(); + this.cnBrowseSearch.reset(); + break; + + case 'browse': + this.marcSearch.reset(); + this.termSearch.reset(); + this.identSearch.reset(); + this.cnBrowseSearch.reset(); + this.browseSearch.pivot = null; + break; + + case 'cnbrowse': + this.marcSearch.reset(); + this.termSearch.reset(); + this.identSearch.reset(); + this.browseSearch.reset(); + this.cnBrowseSearch.offset = 0; + break; + } + } } 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 e78a951e62..5dae001a1e 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 @@ -26,6 +26,7 @@ import {HoldingsMaintenanceComponent} from './record/holdings.component'; import {ConjoinedComponent} from './record/conjoined.component'; import {CnBrowseComponent} from './cnbrowse.component'; import {CnBrowseResultsComponent} from './cnbrowse/results.component'; +import {SearchFiltersComponent} from './search-filters.component'; @NgModule({ declarations: [ @@ -47,6 +48,7 @@ import {CnBrowseResultsComponent} from './cnbrowse/results.component'; BrowseResultsComponent, ConjoinedComponent, HoldingsMaintenanceComponent, + SearchFiltersComponent, CnBrowseComponent, CnBrowseResultsComponent ], 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 1dac53644e..1b6dac1d4a 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 @@ -48,7 +48,8 @@ export class CatalogResolver implements Resolve> { 'cat.marcedit.stack_subfields', 'cat.marcedit.flateditor', 'cat.holdings_show_copies', - 'cat.holdings_show_vols' + 'cat.holdings_show_vols', + 'opac.staff_saved_search.size' ]).then(settings => { this.staffCat.defaultSearchOrg = this.org.get(settings['eg.search.search_lib']); diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.html new file mode 100644 index 0000000000..e3cdeb2344 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.html @@ -0,0 +1,62 @@ + +
+ + +
+ + +
+
+ +
+ + +
+
+ + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.ts new file mode 100644 index 0000000000..181b7e3ea4 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-filters.component.ts @@ -0,0 +1,100 @@ +import {Component, OnInit, Input} from '@angular/core'; +import {OrgService} from '@eg/core/org.service'; +import {ServerStoreService} from '@eg/core/server-store.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {CatalogService} from '@eg/share/catalog/catalog.service'; +import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service'; +import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context'; +import {StaffCatalogService} from './catalog.service'; +import {AnonCacheService} from '@eg/share/util/anon-cache.service'; +import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap'; + +const SAVED_TEMPLATES_SETTING = 'eg.catalog.search_templates'; + +class SearchTemplate { + name: string; + params: any; // routerLink-compatible URL params object + constructor(name: string, params: any) { + this.name = name; + this.params = params; + } +} + +@Component({ + selector: 'eg-catalog-search-filters', + templateUrl: 'search-filters.component.html' +}) +export class SearchFiltersComponent extends DialogComponent implements OnInit { + + recentSearchesCount = 0; + context: CatalogSearchContext; + templates: SearchTemplate[] = []; + templateName: string; + selectedTemplate: string; + + @Input() searchTab: string; + + constructor( + private org: OrgService, + private store: ServerStoreService, // search templates + private cache: AnonCacheService, // recent searches + private cat: CatalogService, + private catUrl: CatalogUrlService, + private staffCat: StaffCatalogService, + private modal: NgbModal) { + super(modal); + } + + ngOnInit() { + this.context = this.staffCat.searchContext; + this.org.settings('opac.staff_saved_search.size').then(sets => { + const size = sets['opac.staff_saved_search.size']; + if (size > 0) { this.recentSearchesCount = Number(size); } + }); + + this.getTemplates(); + } + + getTemplates(): Promise { + this.templates = []; + + return this.store.getItem(SAVED_TEMPLATES_SETTING).then( + templates => { + if (templates && templates.length) { + this.templates = templates; + + // route index required to force the route to take + // effect. See ./catalog.service.ts + this.templates.forEach(tmpl => + tmpl.params.ridx = this.staffCat.routeIndex++); + } + } + ); + } + + saveTemplate(): Promise { + if (!this.templateName) { return; } + + this.close(); + const tmpContext = this.staffCat.cloneContext(this.context); + tmpContext.scrub(this.searchTab); + const urlParams = this.catUrl.toUrlParams(tmpContext); + + // Some data should not go into the template. + delete urlParams.org; + delete urlParams.ridx; + + // Clear the query values, but leave the query param in + // place since the CatalogUrl services expect to see one. + urlParams.query = ['']; + + this.templates.push(new SearchTemplate(this.templateName, urlParams)); + + return this.store.setItem(SAVED_TEMPLATES_SETTING, this.templates) + .then(_ => this.close()); + } +} + + + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html index 8d6e34878a..a80e76bb18 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html @@ -345,6 +345,14 @@ TODO focus search input +
+
+
+ + +
+
+
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 c8cee02105..c3488df7dc 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 @@ -194,51 +194,21 @@ export class SearchFormComponent implements OnInit, AfterViewInit { // Form search overrides basket display this.context.showBasket = false; - switch (this.searchTab) { + this.context.scrub(this.searchTab); - case 'term': // AKA keyword search - this.context.marcSearch.reset(); - this.context.browseSearch.reset(); - this.context.identSearch.reset(); - this.context.cnBrowseSearch.reset(); - this.context.termSearch.hasBrowseEntry = ''; - this.context.termSearch.browseEntry = null; - this.context.termSearch.fromMetarecord = null; - this.context.termSearch.facetFilters = []; - this.staffCat.search(); - break; + switch (this.searchTab) { + case 'term': case 'ident': - this.context.marcSearch.reset(); - this.context.browseSearch.reset(); - this.context.termSearch.reset(); - this.context.cnBrowseSearch.reset(); - this.staffCat.search(); - break; - case 'marc': - this.context.browseSearch.reset(); - this.context.termSearch.reset(); - this.context.identSearch.reset(); - this.context.cnBrowseSearch.reset(); this.staffCat.search(); break; case 'browse': - this.context.marcSearch.reset(); - this.context.termSearch.reset(); - this.context.identSearch.reset(); - this.context.cnBrowseSearch.reset(); - this.context.browseSearch.pivot = null; this.staffCat.browse(); break; case 'cnbrowse': - this.context.marcSearch.reset(); - this.context.termSearch.reset(); - this.context.identSearch.reset(); - this.context.browseSearch.reset(); - this.context.cnBrowseSearch.offset = 0; this.staffCat.cnBrowse(); break; } diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.search-templates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.search-templates.sql new file mode 100644 index 0000000000..c68982ee68 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.search-templates.sql @@ -0,0 +1,18 @@ + +BEGIN; + +--SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); + +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + -- hmm, we probably need a 'catalog' settings group + 'eg.catalog.search_templates', 'gui', 'object', + oils_i18n_gettext( + 'eg.catalog.search_templates', + 'Staff Catalog Search Templates', + 'cwst', 'label' + ) +); + +COMMIT; + -- 2.11.0