'use strict' ; import { parentView , inject , View , WorkAPI } from '../../index' ; import { IFileData , ICollectionData , IProjectData } from 'teambition' ; let projectId ; @ parentView ( 'TabsView' ) @ inject ( [ 'WorkAPI' ] ) export class PanelCollectionsView extends View { public works : IFileData [ ] ; public collections : ICollectionData [ ] ; private WorkAPI : WorkAPI ; public onInit ( ) { projectId = this . $state . params . _id ; return this . initFetch ( ) ; } public openDetail ( _id ) { if ( ! _id ) { return ; } window . location . hash = `/detail/work/${ _id }` ; } private initFetch ( ) { let collectionId = this . $state . params . _collectionId ; return this . parent . fetchProject ( projectId ) . then ( ( project ) => { let _collectionId = collectionId || project . _rootCollectionId ; return this . $q . all ( [ this . WorkAPI . fetchWorks ( projectId , _collectionId ) . then ( ( works ) => { this . works = works ; return works ; } ) , this . WorkAPI . fetchCollections ( projectId , _collectionId ) . then ( ( collections ) => { this . collections = collections ; return collections ; } ) ] ) ; } ) ; } } angular . module ( 'teambition' ) . controller ( 'PanelCollectionsView' , PanelCollectionsView ) ;