1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnInit , ViewChild } from '@angular/core' ;
22import { AppService } from '../app.service' ;
33import { HttpClient } from '@angular/common/http' ;
44import { map , finalize } from 'rxjs/operators' ;
55import { ToastrService } from 'ngx-toastr' ;
6+ import { environment } from '../../environments/environment' ;
7+ import { LightboxComponent } from './lightbox/lightbox.component' ;
8+ import { CloudAppEventsService } from '@exlibris/exl-cloudapp-angular-lib' ;
69
710@Component ( {
811 selector : 'app-external' ,
912 templateUrl : './external.component.html' ,
1013 styleUrls : [ './external.component.scss' ]
1114} )
1215export class ExternalComponent implements OnInit {
13- running = false ;
16+ @ViewChild ( LightboxComponent , { static : true } ) lightbox : LightboxComponent ;
17+ running = { search : false , data : false } ;
1418 record : any ;
19+ images : Array < string > = [ ] ;
20+ authToken : string ;
1521
1622 constructor (
1723 private appService : AppService ,
24+ private eventsService : CloudAppEventsService ,
1825 private http : HttpClient ,
1926 private toastr : ToastrService
2027 ) { }
2128
2229 ngOnInit ( ) {
2330 this . appService . setTitle ( 'Reaching out' ) ;
31+ this . eventsService . getAuthToken ( )
32+ . subscribe ( authToken => this . authToken = authToken ) ;
2433 }
2534
2635 search ( identifierType : string , identifier : string ) {
27- this . running = true ;
36+ this . running . search = true ;
2837 this . record = null ;
29- this . http . get < any > ( `https://catalog.hathitrust.org/api/volumes/brief/ ${ identifierType } / ${ identifier } .json` )
38+ this . http . get < any > ( hathitrustSearchUrl ( identifierType , identifier ) )
3039 . pipe (
3140 map ( res => {
3241 if ( Object . keys ( res . records ) . length == 0 ) {
@@ -36,11 +45,39 @@ export class ExternalComponent implements OnInit {
3645 { id : Object . keys ( res . records ) [ 0 ] , ...Object . values ( res . records ) [ 0 ] } )
3746 }
3847 } ) ,
39- finalize ( ( ) => this . running = false )
48+ finalize ( ( ) => this . running . search = false )
4049 )
41- . subscribe ( {
42- next : response => this . record = response ,
43- error : ( e ) => this . toastr . error ( e . message )
50+ . subscribe ( {
51+ next : resp => this . record = resp ,
52+ error : e => this . toastr . error ( e . message )
4453 } ) ;
4554 }
55+
56+ dataApi ( id : string ) {
57+ const headers = { 'Authorization' : `Bearer ${ this . authToken } ` } ;
58+ this . lightbox . headers = headers ;
59+ this . running . data = true ;
60+ this . http . get < any > ( hathitrustMetaUrl ( id ) , { headers } ) . pipe (
61+ map ( resp => {
62+ if ( resp [ 'htd:seqmap' ] && resp [ 'htd:seqmap' ] [ 0 ] && resp [ 'htd:seqmap' ] [ 0 ] [ 'htd:seq' ] ) {
63+ const seqmap : Array < any > = resp [ 'htd:seqmap' ] [ 0 ] [ 'htd:seq' ] ;
64+ return seqmap . map ( s => hathitrustImageUrl ( id , s . pseq ) ) ;
65+ }
66+ } ) ,
67+ finalize ( ( ) => this . running . data = false )
68+ ) . subscribe ( {
69+ next : resp => this . images = resp ,
70+ error : e => this . toastr . error ( e . message )
71+ } )
72+ }
73+
74+ openModal ( ) {
75+ this . lightbox . openModal ( ) ;
76+ this . lightbox . images = this . images ;
77+ this . lightbox . currentSlide ( 1 ) ;
78+ }
4679}
80+
81+ const hathitrustMetaUrl = ( id : string ) => `${ environment . hathitrustProxy } /volume/meta/${ id } ?v=2&format=json` ;
82+ const hathitrustImageUrl = ( id : string , pseq : string ) => `${ environment . hathitrustProxy } /volume/pageimage/${ id } /${ pseq } ?v=2&format=png&res=2` ;
83+ const hathitrustSearchUrl = ( identifierType : string , identifier : string ) => `${ environment . hathitrustUrl } /api/volumes/brief/${ identifierType } /${ identifier } .json` ;
0 commit comments