1 import {Component, OnInit, Input} from '@angular/core';
2 import {Observable, Subscription} from 'rxjs';
3 import {map, switchMap, distinctUntilChanged} from 'rxjs/operators';
4 import {ActivatedRoute, ParamMap} from '@angular/router';
5 import {CatalogService} from '@eg/share/catalog/catalog.service';
6 import {BibRecordService} from '@eg/share/catalog/bib-record.service';
7 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
8 import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
9 import {PcrudService} from '@eg/core/pcrud.service';
10 import {StaffCatalogService} from '../catalog.service';
11 import {IdlObject} from '@eg/core/idl.service';
14 selector: 'eg-catalog-browse-results',
15 templateUrl: 'results.component.html'
17 export class BrowseResultsComponent implements OnInit {
19 searchContext: CatalogSearchContext;
23 private route: ActivatedRoute,
24 private pcrud: PcrudService,
25 private cat: CatalogService,
26 private bib: BibRecordService,
27 private catUrl: CatalogUrlService,
28 private staffCat: StaffCatalogService
32 this.searchContext = this.staffCat.searchContext;
33 this.route.queryParamMap.subscribe((params: ParamMap) => {
34 this.browseByUrl(params);
38 browseByUrl(params: ParamMap): void {
39 this.catUrl.applyUrlParams(this.searchContext, params);
40 const bs = this.searchContext.browseSearch;
42 // SearchContext applies a default fieldClass value of 'keyword'.
43 // Replace with 'title', since there is no 'keyword' browse.
44 if (bs.fieldClass === 'keyword') {
45 bs.fieldClass = 'title';
48 if (bs.isSearchable()) {
50 this.cat.browse(this.searchContext)
51 .subscribe(result => this.addResult(result));
55 addResult(result: any) {
57 result.compiledHeadings = [];
59 // Avoi dupe headings per see
62 result.sees.forEach(sees => {
63 if (!sees.control_set) { return; }
65 sees.headings.forEach(headingStruct => {
66 const fieldId = Object.keys(headingStruct)[0];
67 const heading = headingStruct[fieldId][0];
69 const inList = result.list_authorities.filter(
70 id => Number(id) === Number(heading.target))[0];
74 && heading.target_count
76 && !seen[heading.target]) {
78 seen[heading.target] = true;
80 result.compiledHeadings.push({
81 heading: heading.heading,
82 target: heading.target,
83 target_count: heading.target_count,
90 this.results.push(result);
93 browseIsDone(): boolean {
94 return this.searchContext.searchState === CatalogSearchState.COMPLETE;
97 browseIsActive(): boolean {
98 return this.searchContext.searchState === CatalogSearchState.SEARCHING;
101 browseHasResults(): boolean {
102 return this.browseIsDone() && this.results.length > 0;
106 const firstResult = this.results[0];
108 this.searchContext.browseSearch.pivot = firstResult.pivot_point;
109 this.staffCat.browse();
114 const lastResult = this.results[this.results.length - 1];
116 this.searchContext.browseSearch.pivot = lastResult.pivot_point;
117 this.staffCat.browse();
121 searchByBrowseEntry(result) {
123 // Avoid propagating browse values to term search.
124 this.searchContext.browseSearch.reset();
126 this.searchContext.termSearch.hasBrowseEntry =
127 result.browse_entry + ',' + result.fields;
128 this.staffCat.search();
131 // NOTE: to test unauthorized heading display in concerto
132 // browse for author = kab
133 newBrowseFromHeading(heading) {
134 this.searchContext.browseSearch.value = heading.heading;
135 this.staffCat.browse();