1 import {Injectable} from '@angular/core';
2 import {Router, ActivatedRoute} from '@angular/router';
3 import {IdlObject} from '@eg/core/idl.service';
4 import {OrgService} from '@eg/core/org.service';
5 import {CatalogService} from '@eg/share/catalog/catalog.service';
6 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
7 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
10 * Shared bits needed by the staff version of the catalog.
14 export class StaffCatalogService {
16 searchContext: CatalogSearchContext;
18 defaultSearchOrg: IdlObject;
19 defaultSearchLimit: number;
21 // TODO: does unapi support pref-lib for result-page copy counts?
24 // Cache the currently selected detail record (i.g. catalog/record/123)
25 // summary so the record detail component can avoid duplicate fetches
26 // during record tab navigation.
27 currentDetailRecordSummary: any;
30 private router: Router,
31 private route: ActivatedRoute,
32 private org: OrgService,
33 private cat: CatalogService,
34 private catUrl: CatalogUrlService
37 createContext(): void {
38 // Initialize the search context from the load-time URL params.
39 // Do this here so the search form and other context data are
40 // applied on every page, not just the search results page. The
41 // search results pages will handle running the actual search.
43 this.catUrl.fromUrlParams(this.route.snapshot.queryParamMap);
45 this.searchContext.org = this.org; // service, not searchOrg
46 this.searchContext.isStaff = true;
47 this.applySearchDefaults();
50 applySearchDefaults(): void {
51 if (!this.searchContext.searchOrg) {
52 this.searchContext.searchOrg =
53 this.defaultSearchOrg || this.org.root();
56 if (!this.searchContext.pager.limit) {
57 this.searchContext.pager.limit = this.defaultSearchLimit || 20;
62 * Redirect to the search results page while propagating the current
63 * search paramters into the URL. Let the search results component
64 * execute the actual search.
67 if (!this.searchContext.isSearchable()) { return; }
69 const params = this.catUrl.toUrlParams(this.searchContext);
71 // Force a new search every time this method is called, even if
72 // it's the same as the active search. Since router navigation
73 // exits early when the route + params is identical, add a
74 // random token to the route params to force a full navigation.
75 // This also resolves a problem where only removing secondary+
76 // versions of a query param fail to cause a route navigation.
77 // (E.g. going from two query= params to one). Investigation
79 params.ridx = '' + this.routeIndex++;
82 ['/staff/catalog/search'], {queryParams: params});
86 * Redirect to the browse results page while propagating the current
87 * browse paramters into the URL. Let the browse results component
88 * execute the actual browse.
91 if (!this.searchContext.browseSearch.isSearchable()) { return; }
93 const params = this.catUrl.toUrlParams(this.searchContext);
95 // Force a new browse every time this method is called, even if
96 // it's the same as the active browse. Since router navigation
97 // exits early when the route + params is identical, add a
98 // random token to the route params to force a full navigation.
99 // This also resolves a problem where only removing secondary+
100 // versions of a query param fail to cause a route navigation.
101 // (E.g. going from two query= params to one).
102 params.ridx = '' + this.routeIndex++;
104 this.router.navigate(
105 ['/staff/catalog/browse'], {queryParams: params});