import { Component , OnInit , OnDestroy } from '@angular/core' ; import { Meta } from '@angular/platform-browser' ; import { ActivatedRoute , ParamMap , Router , NavigationEnd } from '@angular/router' ; import { Subscription } from 'rxjs' ; import { ContributorService } from '@core/contributor.service' ; import { EventService } from '@core/event.service' ; import { EventDepthPipe } from '../event-depth.pipe' ; import { DateTimePipe } from '@shared/date-time.pipe' ; import { LocationPipe } from '@shared/location.pipe' ; /**
 * Main event page component, wraps inbound data components
 */ @ Component ( { providers : [ EventDepthPipe , DateTimePipe , LocationPipe ] , selector : 'app-event-page' , styleUrls : [ './event-page.component.scss' ] , templateUrl : './event-page.component.html' } ) export class EventPageComponent implements OnInit , OnDestroy { child : any = null ; subscription = new Subscription ( ) ; constructor ( public route , public contributorService , public eventService , public meta , public router , public locationPipe , public eventDepthPipe , public dateTimePipe ) { } ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } ngOnInit ( ) { this . sendPageView ( this . router . url ) ; this . subscription . add ( this . route . paramMap . subscribe ( ( paramMap ) => { return this . onParamMapChange ( paramMap ) ; } ) ) ; this . subscription . add ( this . eventService . event$ . subscribe ( event => { if ( ! event . id ) { return ; } if ( event . properties . title ) { this . meta . updateTag ( { content : event . properties . title , property : 'og:title' } ) ; } this . meta . updateTag ( { content : this . updateDescriptionMetaTag ( event ) , property : 'og:description' } ) ; } ) ) ; try { this . subscription . add ( this . router . events . subscribe ( e => { if ( e instanceof NavigationEnd ) { this . sendPageView ( e . urlAfterRedirects ) ; if ( this . child !== this . route . firstChild ) { this . child = this . route . firstChild ; window . scrollTo ( 0 , 0 ) ; } } } ) ) ; } catch ( e ) { console . log ( e ) ; } } param paramMap onParamMapChange ( paramMap ) { this . eventService . getEvent ( paramMap . get ( 'eventid' ) ) ; } param url sendPageView ( url ) { try { ( window as any ) . gas ( 'send' , { hitType : 'pageview' , page : url } ) ; } catch ( e ) { return ; } } param index param item trackByIndex ( index , item ) { return index ; } param event updateDescriptionMetaTag ( event ) { try { const time = this . dateTimePipe . transform ( event . properties . time ) ; const location = this . locationPipe . transform ( event . geometry . coordinates ) ; const depth = this . eventDepthPipe . transform ( event ) ; return time + ' | ' + location + ' | ' + depth ; } catch ( e ) { return 'Earthquake event page.' ; } } }