import { Component , ComponentFactoryResolver , ViewRef , ChangeDetectorRef , Input , ViewChild , ViewContainerRef , } from '@angular/core' ; import { ActivatedRoute } from '@angular/router' ; import { FeedsService } from '../../../../common/services/feeds.service' ; import { BoostConsoleType } from '../console.component' ; import { Client } from '../../../../services/api' ; import { Session } from '../../../../services/session' ; import { BehaviorSubject , Observable } from 'rxjs' ; /**
 * The component for the boost console.
 */ @ Component ( { selector : 'm-boost-console-booster' , templateUrl : 'booster.component.html' , providers : [ FeedsService ] , } ) export class BoostConsoleBooster { @ Input ( 'type' ) type : BoostConsoleType ; @ ViewChild ( 'poster' , { read : ViewContainerRef } ) poster : ViewContainerRef ; feed$ : Observable < BehaviorSubject < Object > [ ] > ; componentRef ; inProgress = true ; loaded = false ; noContent = true ; constructor ( public client , public session , private route , public feedsService , private cd , private componentFactoryResolver ) { } /**
     * subscribes to route parent url and loads component.
     */ ngOnInit ( ) { this . loaded = false ; this . route . parent . url . subscribe ( segments => { this . type = < BoostConsoleType > segments [ 0 ] . path ; this . load ( true ) ; this . loaded = true ; } ) ; } param { boolean } refresh load ( refresh ? ) { if ( ! refresh ) { return ; } if ( refresh ) { this . feedsService . clear ( ) ; } this . inProgress = true ; this . feedsService . setEndpoint ( this . type === 'content' ? `api/v2/feeds/container/${ this . session . getLoggedInUser ( ) . guid }/objects` : `api/v2/feeds/container/${ this . session . getLoggedInUser ( ) . guid }/activities` ) . setParams ( { sync : true } ) . setLimit ( 12 ) . fetch ( ) ; this . feed$ = this . feedsService . feed ; this . inProgress = false ; this . loaded = true ; this . feed$ . subscribe ( feed => ( this . noContent = feed . length > 0 ) ) ; } param feed loadNext ( ) { if ( this . feedsService . canFetchMore && ! this . feedsService . inProgress . getValue ( ) && this . feedsService . offset . getValue ( ) ) { this . feedsService . fetch ( ) ; } this . feedsService . loadMore ( ) ; } /**
     * Detects changes if view is not destroyed.
     */ detectChanges ( ) { if ( ! ( this . cd as ViewRef ) . destroyed ) { this . cd . markForCheck ( ) ; this . cd . detectChanges ( ) ; } } /**
     * Detaches change detector on destroy
     */ ngOnDestroy = ( ) => this . cd . detach ( ) ; }