import { Component } from '@angular/core' ; import { I18nService } from 'i18n/i18n.service' ; import { EndangeredLanguage , EndangeredLanguageService } from 'services/endangered-language' ; import { ActivatedRoute , ParamMap , Router } from '@angular/router' ; import { AppRoutes } from 'app/routes' ; @ Component ( { selector : 'app-view-language' , templateUrl : './view-language.html' , styleUrls : [ './view-language.scss' ] } ) export class ViewLanguagePageComponent { public get endangeredLanguages ( ) : EndangeredLanguage [ ] { return this . endangeredLanguageService . languages ; } public get otherLanguages ( ) : EndangeredLanguage [ ] { const currentLang = this . language ; if ( ! currentLang ) { return this . endangeredLanguageService . languages ; } return this . endangeredLanguageService . languages . filter ( lang => lang . code !== currentLang . code ) ; } public language : EndangeredLanguage | null ; constructor ( private route , private router , private i18nService , private endangeredLanguageService ) { this . language = null ; this . route . paramMap . subscribe ( ( params ) => { this . language = this . endangeredLanguageService . languages . find ( lang => lang . code === params . get ( 'id' ) ) || null ; } ) ; } onExploreLanguageClick ( ) { const lang = this . language ; if ( lang ) { window . open ( lang . organizationURL ) ; } } onLanguageClick ( code ) { window . scrollTo ( 0 , 0 ) ; this . router . navigate ( [ AppRoutes . ListLanguages , code ] ) ; } onBackClick ( ev ) { ev . stopPropagation ( ) ; history . back ( ) ; } }