'use strict' ; import { inject , View , ProjectsAPI } from '../index' ; import { IProjectData } from 'teambition' ; declare var Gta ; let lastSelected ; let projectId ; @ inject ( [ 'ProjectsAPI' ] ) export class TabsView extends View { public project : IProjectData ; private projectName : string ; private $ionicTabsDelegate : ionic . tabs . IonicTabsDelegate ; private ProjectsAPI : ProjectsAPI ; private hasFetched = false ; private tabTypes : string [ ] = [ 'home' , 'tasklist' , 'post' , 'work' , 'event' ] ; public onInit ( ) { projectId = this . $state . params . _id ; return this . fetchProject ( projectId ) . then ( ( ) => this . hasFetched = true ) ; } public openView ( type ) { if ( ! this . hasFetched ) { return ; } let selectedIndex = this . $ionicTabsDelegate . selectedIndex ( ) ; let _projectId = this . $state . params . _id ; if ( projectId !== _projectId ) { projectId = _projectId ; this . fetchProject ( _projectId ) ; } if ( this . tabTypes [ selectedIndex ] !== lastSelected ) { lastSelected = type ; window . location . hash = `/project/${ _projectId }/${ type }` ; if ( typeof ( Gta ) !== undefined ) { Gta . event ( 'tab-nav' , type , 'click tab-nav' ) ; } } } public fetchProject ( projectId ) { return this . ProjectsAPI . fetchById ( projectId ) . then ( ( project ) => { this . project = project ; this . projectName = project . name ; return project ; } ) ; } } angular . module ( 'teambition' ) . controller ( 'TabsView' , TabsView ) ;