LP1806087 Angular catalog Ang7 & lint repairs
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / resolver.service.ts
1 import {Injectable} from '@angular/core';
2 import {Observable, Observer} from 'rxjs';
3 import {Router, Resolve, RouterStateSnapshot,
4         ActivatedRouteSnapshot} from '@angular/router';
5 import {ServerStoreService} from '@eg/core/server-store.service';
6 import {NetService} from '@eg/core/net.service';
7 import {OrgService} from '@eg/core/org.service';
8 import {AuthService} from '@eg/core/auth.service';
9 import {PcrudService} from '@eg/core/pcrud.service';
10 import {CatalogService} from '@eg/share/catalog/catalog.service';
11 import {StaffCatalogService} from './catalog.service';
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     ) {}
25
26     resolve(
27         route: ActivatedRouteSnapshot,
28         state: RouterStateSnapshot): Promise<any[]> {
29
30         console.debug('CatalogResolver:resolve()');
31
32         return Promise.all([
33             this.cat.fetchCcvms(),
34             this.cat.fetchCmfs(),
35             this.fetchSettings()
36         ]);
37     }
38
39     fetchSettings(): Promise<any> {
40
41         return this.store.getItemBatch([
42             'eg.search.search_lib',
43             'eg.search.pref_lib'
44         ]).then(settings => {
45             this.staffCat.defaultSearchOrg =
46                 this.org.get(settings['eg.search.search_lib']);
47             this.staffCat.prefOrg =
48                 this.org.get(settings['eg.search.pref_lib']);
49         });
50     }
51 }
52