1 import {Component, OnInit, Input} from '@angular/core';
2 import {Observable} from 'rxjs/Observable';
3 import {Subscription} from 'rxjs/Subscription';
4 import {map, switchMap, distinctUntilChanged} from 'rxjs/operators';
5 import {ActivatedRoute, ParamMap} from '@angular/router';
6 import {CatalogService} from '@eg/share/catalog/catalog.service';
7 import {BibRecordService} from '@eg/share/catalog/bib-record.service';
8 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
9 import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
10 import {PcrudService} from '@eg/core/pcrud.service';
11 import {StaffCatalogService} from '../catalog.service';
12 import {IdlObject} from '@eg/core/idl.service';
15 selector: 'eg-catalog-browse-results',
16 templateUrl: 'results.component.html'
18 export class BrowseResultsComponent implements OnInit {
20 searchContext: CatalogSearchContext;
24 private route: ActivatedRoute,
25 private pcrud: PcrudService,
26 private cat: CatalogService,
27 private bib: BibRecordService,
28 private catUrl: CatalogUrlService,
29 private staffCat: StaffCatalogService
33 this.searchContext = this.staffCat.searchContext;
34 this.route.queryParamMap.subscribe((params: ParamMap) => {
35 this.browseByUrl(params);
39 browseByUrl(params: ParamMap): void {
40 this.catUrl.applyUrlParams(this.searchContext, params);
41 const bs = this.searchContext.browseSearch;
43 // SearchContext applies a default fieldClass value of 'keyword'.
44 // Replace with 'title', since there is no 'keyword' browse.
45 if (bs.fieldClass === 'keyword') {
46 bs.fieldClass = 'title';
49 if (bs.isSearchable()) {
51 this.cat.browse(this.searchContext)
52 .subscribe(result => this.addResult(result))
56 addResult(result: any) {
58 result.compiledHeadings = [];
60 // Avoi dupe headings per see
63 result.sees.forEach(sees => {
64 if (!sees.control_set) { return; }
66 sees.headings.forEach(headingStruct => {
67 const fieldId = Object.keys(headingStruct)[0];
68 const heading = headingStruct[fieldId][0];
70 const inList = result.list_authorities.filter(
71 id => Number(id) === Number(heading.target))[0]
75 && heading.target_count
77 && !seen[heading.target]) {
79 seen[heading.target] = true;
81 result.compiledHeadings.push({
82 heading: heading.heading,
83 target: heading.target,
84 target_count: heading.target_count,
91 this.results.push(result);
94 browseIsDone(): boolean {
95 return this.searchContext.searchState === CatalogSearchState.COMPLETE;
98 browseIsActive(): boolean {
99 return this.searchContext.searchState === CatalogSearchState.SEARCHING;
102 browseHasResults(): boolean {
103 return this.browseIsDone() && this.results.length > 0;
107 const firstResult = this.results[0];
109 this.searchContext.browseSearch.pivot = firstResult.pivot_point;
110 this.staffCat.browse();
115 const lastResult = this.results[this.results.length - 1];
117 this.searchContext.browseSearch.pivot = lastResult.pivot_point;
118 this.staffCat.browse();
122 searchByBrowseEntry(result) {
124 // Avoid propagating browse values to term search.
125 this.searchContext.browseSearch.reset();
127 this.searchContext.termSearch.hasBrowseEntry =
128 result.browse_entry + ',' + result.fields;
129 this.staffCat.search();
132 // NOTE: to test unauthorized heading display in concerto
133 // browse for author = kab
134 newBrowseFromHeading(heading) {
135 this.searchContext.browseSearch.value = heading.heading;
136 this.staffCat.browse();