import { Component , OnDestroy } from '@angular/core' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { ConfigsService } from '../../../common/services/configs.service' ; import { FormToastService } from '../../../common/services/form-toast.service' ; import { LazyComponent } from '../../../common/services/modal-lazy-load.service' ; import { Session } from '../../../services/session' ; import { BoostModalService , BoostSubject , BoostTab , } from './boost-modal.service' ; /**
 * Boost modal component. Designed to be lazy loaded in through stackable modal service.
 */ @ Component ( { selector : 'm-boostModal' , templateUrl : './boost-modal.component.html' , styleUrls : [ './boost-modal.component.ng.scss' ] , } ) export class BoostModalComponent implements LazyComponent , OnDestroy { /**
     * Asset url
     */ public readonly cdnAssetsUrl : string ; constructor ( private service , private session , private toast , configs ) { this . cdnAssetsUrl = configs . get ( 'cdn_assets_url' ) ; } ngOnDestroy ( ) { this . service . reset ( ) ; } /**
     * Entity type from service
     */ get entityType$ ( ) : Observable < BoostSubject > { return this . service . entityType$ ; } /**
     * Is in progress
     */ public readonly inProgress$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ; returns { Observable < boolean > } get disabled$ ( ) : Observable < boolean > { return this . service . disabled$ ; } returns { BehaviorSubject < BoostTab > } get activeTab$ ( ) : BehaviorSubject < BoostTab > { return this . service . activeTab$ ; } returns { string } get username ( ) : string { return this . session . getLoggedInUser ( ) . username ; } /**
     * Dismiss intent.
     */ onDismissIntent : ( ) => void = ( ) => { } ; /**
     * Save intent.
     */ onSaveIntent : ( ) => void = ( ) => { } ; param { Function } onDismissIntent param { Function } onSaveIntent param { BoostableEntity } entity set opts ( { onDismissIntent , onSaveIntent , entity } ) { this . onDismissIntent = onDismissIntent || ( ( ) => { } ) ; this . onSaveIntent = onSaveIntent || ( ( ) => { } ) ; this . service . entity$ . next ( entity || ( ( ) => { } ) ) ; } returns { { backgroundImage : string } } get bannerSrc ( ) : { backgroundImage : string ; } { return { backgroundImage : `url('${ this . cdnAssetsUrl }assets/photos/red-blue-gradient-banner.jpg')` , } ; } returns { Promise < void > } public async submitBoost ( ) { this . inProgress$ . next ( true ) ; const response = await this . service . submitBoostAsync ( ) ; this . inProgress$ . next ( false ) ; if ( response && response . status !== undefined && response . status === 'success' ) { this . toast . success ( 'Success! Your boost request is being processed.' ) ; this . onSaveIntent ( ) ; } } }