1 import {Component, OnInit, OnDestroy} from '@angular/core';
2 import {ActivatedRoute, ParamMap} from '@angular/router';
3 import {Subscription} from 'rxjs';
4 import {CatalogService} from '@eg/share/catalog/catalog.service';
5 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
6 import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
7 import {StaffCatalogService} from '../catalog.service';
10 selector: 'eg-catalog-browse-results',
11 templateUrl: 'results.component.html'
13 export class BrowseResultsComponent implements OnInit, OnDestroy {
15 searchContext: CatalogSearchContext;
17 routeSub: Subscription;
20 private route: ActivatedRoute,
21 private cat: CatalogService,
22 private catUrl: CatalogUrlService,
23 private staffCat: StaffCatalogService
27 this.searchContext = this.staffCat.searchContext;
28 this.routeSub = this.route.queryParamMap.subscribe(
29 (params: ParamMap) => this.browseByUrl(params)
34 this.routeSub.unsubscribe();
37 browseByUrl(params: ParamMap): void {
38 this.catUrl.applyUrlParams(this.searchContext, params);
39 const bs = this.searchContext.browseSearch;
41 // SearchContext applies a default fieldClass value of 'keyword'.
42 // Replace with 'title', since there is no 'keyword' browse.
43 if (bs.fieldClass === 'keyword') {
44 bs.fieldClass = 'title';
47 if (bs.isSearchable()) {
49 this.cat.browse(this.searchContext)
50 .subscribe(result => this.addResult(result));
54 addResult(result: any) {
56 result.compiledHeadings = [];
58 // Avoi dupe headings per see
61 result.sees.forEach(sees => {
62 if (!sees.control_set) { return; }
64 sees.headings.forEach(headingStruct => {
65 const fieldId = Object.keys(headingStruct)[0];
66 const heading = headingStruct[fieldId][0];
68 const inList = result.list_authorities.filter(
69 id => Number(id) === Number(heading.target))[0];
73 && heading.target_count
75 && !seen[heading.target]) {
77 seen[heading.target] = true;
79 result.compiledHeadings.push({
80 heading: heading.heading,
81 target: heading.target,
82 target_count: heading.target_count,
89 this.results.push(result);
92 browseIsDone(): boolean {
93 return this.searchContext.searchState === CatalogSearchState.COMPLETE;
96 browseIsActive(): boolean {
97 return this.searchContext.searchState === CatalogSearchState.SEARCHING;
100 browseHasResults(): boolean {
101 return this.browseIsDone() && this.results.length > 0;
105 const firstResult = this.results[0];
107 this.searchContext.browseSearch.pivot = firstResult.pivot_point;
108 this.staffCat.browse();
113 const lastResult = this.results[this.results.length - 1];
115 this.searchContext.browseSearch.pivot = lastResult.pivot_point;
116 this.staffCat.browse();
120 searchByBrowseEntry(result) {
122 // Avoid propagating browse values to term search.
123 this.searchContext.browseSearch.reset();
125 this.searchContext.termSearch.hasBrowseEntry =
126 result.browse_entry + ',' + result.fields;
127 this.staffCat.search();
130 // NOTE: to test unauthorized heading display in concerto
131 // browse for author = kab
132 newBrowseFromHeading(heading) {
133 this.searchContext.browseSearch.value = heading.heading;
134 this.staffCat.browse();