import { Component , Input } from '@angular/core' ; import { Router } from '@angular/router' ; import { Notification } from '../models' ; import { Constants } from '../constants' ; import { AuthService , NotificationsService } from '../services' ; import { StringsService } from '../strings/strings.service' ; @ Component ( { selector : 'tb-top-nav' , templateUrl : './top-nav.component.html' } ) export class TopNavComponent { public strings : any ; @ Input ( 'page-name' ) pageName : string = '' ; @ Input ( 'show-buttons' ) showButtons : boolean = true ; version = '' ; username = '' ; constructor ( public constants , private router , public authService , private notes , public stringsService ) { this . version = constants . VERSION ; authService . userChanged . subscribe ( user => this . username = user ? user . username : '' ) ; stringsService . stringsChanged . subscribe ( newStrings => { this . strings = newStrings ; } ) ; } logout ( ) { this . authService . logout ( ) . subscribe ( res => { const alert = res . alerts [ 0 ] ; this . notes . add ( new Notification ( alert . type , alert . text ) ) ; this . router . navigate ( [ '' ] ) ; } ) ; } isActive ( route ) { return this . router . url . indexOf ( route ) !== - 1 ; } navigateTo ( target ) { this . router . navigate ( [ '/' + target ] ) ; } }