import { BroadcastEvent } from './../../shared/models/broadcast-event' ; import { BottomTabEvent } from './bottom-tab-event' ; import { Subject } from 'rxjs/Subject' ; import { Component , Output , Input , OnDestroy , ContentChild } from '@angular/core' ; import { BottomTabComponent } from 'app/controls/bottom-tabs/bottom-tab.component' ; import { EmbeddedFunctionLogsTabComponent } from 'app/function/embedded/embedded-function-logs-tab/embedded-function-logs-tab.component' ; import { BroadcastService } from 'app/shared/services/broadcast.service' ; export interface BottomTabCommand { iconUrl : string ; text : string ; click : ( ) => void ; } export interface BottomTab { commands : BottomTabCommand [ ] ; } @ Component ( { selector : 'bottom-tabs' , templateUrl : './bottom-tabs.component.html' , styleUrls : [ './bottom-tabs.component.scss' ] , } ) export class BottomTabsComponent implements OnDestroy { @ Input ( ) resourceId : string ; @ Output ( ) onExpanded = new Subject < boolean > ( ) ; @ ContentChild ( EmbeddedFunctionLogsTabComponent ) logsTab : EmbeddedFunctionLogsTabComponent ; public activeTab : BottomTabComponent ; public expanded = false ; private _ngUnsubscribe = new Subject ( ) ; constructor ( private _broadcastService ) { this . _broadcastService . getEvents < BottomTabEvent < boolean > > ( BroadcastEvent . BottomTabsEvent ) . takeUntil ( this . _ngUnsubscribe ) . filter ( e => e . type === 'isExpanded' ) . subscribe ( e => { this . setTabState ( e . value ) ; } ) ; } ngOnDestroy ( ) { this . _ngUnsubscribe . next ( ) ; } toggleExpanded ( ) { this . setTabState ( ! this . expanded ) ; } setTabState ( expanded ) { this . expanded = expanded ; this . onExpanded . next ( this . expanded ) ; setTimeout ( ( ) => { this . activeTab = this . expanded ? this . logsTab : null ; } ) ; } }