LP1819745 Ang staff result page link repairs
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / result / facets.component.ts
1 import {Component, OnInit, Input} from '@angular/core';
2 import {CatalogService} from '@eg/share/catalog/catalog.service';
3 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
4 import {CatalogSearchContext, FacetFilter} from '@eg/share/catalog/search-context';
5 import {StaffCatalogService} from '../catalog.service';
6
7 export const FACET_CONFIG = {
8     display: [
9         {facetClass : 'author',  facetOrder : ['personal', 'corporate']},
10         {facetClass : 'subject', facetOrder : ['topic']},
11         {facetClass : 'identifier', facetOrder : ['genre']},
12         {facetClass : 'series',  facetOrder : ['seriestitle']},
13         {facetClass : 'subject', facetOrder : ['name', 'geographic']}
14     ],
15     displayCount : 5
16 };
17
18 @Component({
19   selector: 'eg-catalog-result-facets',
20   templateUrl: 'facets.component.html'
21 })
22 export class ResultFacetsComponent implements OnInit {
23
24     searchContext: CatalogSearchContext;
25     facetConfig: any;
26
27     constructor(
28         private cat: CatalogService,
29         private catUrl: CatalogUrlService,
30         private staffCat: StaffCatalogService
31     ) {
32         this.facetConfig = FACET_CONFIG;
33     }
34
35     ngOnInit() {
36         this.searchContext = this.staffCat.searchContext;
37     }
38
39     facetIsApplied(cls: string, name: string, value: string): boolean {
40         return this.searchContext.termSearch.hasFacet(new FacetFilter(cls, name, value));
41     }
42
43     getFacetUrlParams(cls: string, name: string, value: string): any {
44         const context = this.staffCat.cloneContext(this.searchContext);
45         context.termSearch.toggleFacet(new FacetFilter(cls, name, value));
46         context.pager.offset = 0;
47         return this.catUrl.toUrlParams(context);
48     }
49 }
50
51