78793730cb2f9ca61cce4a9480c8fdc27564f6f0
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / resolver.service.ts
1 import {Injectable} from '@angular/core';
2 import {Router, Resolve, RouterStateSnapshot,
3         ActivatedRouteSnapshot} from '@angular/router';
4 import {ServerStoreService} from '@eg/core/server-store.service';
5 import {NetService} from '@eg/core/net.service';
6 import {OrgService} from '@eg/core/org.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {CatalogService} from '@eg/share/catalog/catalog.service';
9 import {StaffCatalogService} from './catalog.service';
10 import {BasketService} from '@eg/share/catalog/basket.service';
11
12
13 @Injectable()
14 export class CatalogResolver implements Resolve<Promise<any[]>> {
15
16     constructor(
17         private router: Router,
18         private store: ServerStoreService,
19         private org: OrgService,
20         private net: NetService,
21         private auth: AuthService,
22         private cat: CatalogService,
23         private staffCat: StaffCatalogService,
24         private basket: BasketService
25     ) {}
26
27     resolve(
28         route: ActivatedRouteSnapshot,
29         state: RouterStateSnapshot): Promise<any[]> {
30
31         console.debug('CatalogResolver:resolve()');
32
33         return Promise.all([
34             this.cat.fetchCcvms(),
35             this.cat.fetchCmfs(),
36             this.fetchSettings(),
37             this.basket.getRecordIds()
38         ]);
39     }
40
41     fetchSettings(): Promise<any> {
42
43         return this.store.getItemBatch([
44             'eg.search.search_lib',
45             'eg.search.pref_lib',
46             'eg.search.adv_pane',
47             'eg.catalog.results.count',
48             'cat.holdings_show_empty_org',
49             'cat.holdings_show_empty',
50             'cat.marcedit.stack_subfields',
51             'cat.marcedit.flateditor',
52             'cat.holdings_show_copies',
53             'cat.holdings_show_vols',
54             'opac.staff_saved_search.size',
55             'eg.catalog.search_templates',
56             'opac.staff_saved_search.size',
57             'opac.search.enable_bookplate_search',
58             'eg.staffcat.exclude_electronic'
59         ]).then(settings => {
60             this.staffCat.defaultSearchOrg =
61                 this.org.get(settings['eg.search.search_lib']);
62             this.staffCat.prefOrg =
63                 this.org.get(settings['eg.search.pref_lib']);
64             this.staffCat.defaultTab = settings['eg.search.adv_pane'];
65             if (settings['eg.catalog.results.count']) {
66                this.staffCat.defaultSearchLimit =
67                   Number(settings['eg.catalog.results.count']);
68             }
69             this.staffCat.enableBookplates =
70                 settings['opac.search.enable_bookplate_search'];
71             this.staffCat.showExcludeElectronic =
72                 settings['eg.staffcat.exclude_electronic'] === true;
73         });
74     }
75 }
76