/**
 * Base for blogs v2
 * Houses banner, content and title.
 */ import { Component , OnDestroy , OnInit , ViewChild } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; import { Subscription , Observable } from 'rxjs' ; import { Session } from '../../../../services/session' ; import { InlineEditorComponent } from '../../../../common/components/editors/inline-editor.component' ; import { DialogService } from '../../../../common/services/confirm-leave-dialog.service' ; import { ConfigsService } from '../../../../common/services/configs.service' ; import { FormToastService } from '../../../../common/services/form-toast.service' ; import { BlogsEditService } from './blog-edit.service' ; import { take } from 'rxjs/operators' ; import { Location } from '@angular/common' ; import { ComposerService } from '../../../composer/services/composer.service' ; import { PopupService } from '../../../composer/components/popup/popup.service' ; @ Component ( { selector : 'm-blogEditor--v2' , host : { class : 'm-blog' , } , templateUrl : 'editor-base.component.html' , styleUrls : [ './editor-base.component.ng.scss' ] , providers : [ BlogsEditService , ComposerService , PopupService ] , } ) export class BlogEditorV2Component implements OnInit , OnDestroy { readonly cdnUrl : string ; private paramsSubscription : Subscription ; private errorSubscription : Subscription ; wideBannerDate : number = 1620000000 ; @ ViewChild ( 'inlineEditor' ) inlineEditor : InlineEditorComponent ; protected time_created : any ; constructor ( public session , public router , public route , private dialogService , configs , protected location , private toasterService , public service ) { this . cdnUrl = configs . get ( 'cdn_url' ) ; } ngOnInit ( ) { if ( ! this . session . isLoggedIn ( ) ) { this . router . navigate ( [ '/login' ] ) ; return ; } if ( ! this . canCreateBlog ( ) ) { this . toasterService . error ( 'Please confirm your email address before creating a blog' ) ; this . location . back ( ) ; return ; } this . paramsSubscription = this . route . params . pipe ( take ( 1 ) ) . subscribe ( params => { if ( params [ 'guid' ] && params [ 'guid' ] !== 'new' ) { this . service . load ( params [ 'guid' ] ) ; } } ) ; this . errorSubscription = this . service . error$ . subscribe ( val => { this . toasterService . error ( val ) ; } ) ; } ngOnDestroy ( ) { if ( this . paramsSubscription ) { this . paramsSubscription . unsubscribe ( ) ; } if ( this . errorSubscription ) { this . errorSubscription . unsubscribe ( ) ; } } returns { Observable < boolean > } canDeactivate ( ) { if ( ! this . canCreateBlog ( ) || ! this . session . getLoggedInUser ( ) || this . service . inProgress$ . getValue ( ) || this . service . isContentSaved ( ) ) { return true ; } return this . dialogService . confirm ( 'Discard changes?' ) ; } returns { boolean } canCreateBlog ( ) { return this . session . getLoggedInUser ( ) . email_confirmed ; } param banner uploadBanner ( banner ) { this . service . addBanner ( banner . files [ 0 ] ) ; } param { string } val onContentChange ( val ) { this . service . content$ . next ( val ) ; } param { string } onTitleChange ( val ) { this . service . title$ . next ( val ) ; } }