import { Component , OnDestroy , OnInit } from '@angular/core' ; import { FormControl } from '@angular/forms' ; import { Subscription } from 'rxjs' ; import { environment } from '../../../core/environment' ; import { ErrorWithMetadata } from '../../../core/error-with-metadata' ; import { logMonitor } from '../../../core/log-monitor' ; import { ThemeService , WorkspaceService } from '../../shared' ; import { ConfirmDialog } from '../../shared/confirm-dialog' ; import { Themes } from '../../ui/style' ; @ Component ( { selector : 'gd-wizard-choosing' , templateUrl : './wizard-choosing.component.html' , styleUrls : [ './wizard-choosing.component.scss' ] , } ) export class WizardChoosingComponent implements OnInit , OnDestroy { readonly appVersion = environment . version ; readonly themeFormControl = new FormControl ( ) ; readonly themeOptions = [ { name : 'Light Theme' , value : Themes . BASIC_LIGHT_THEME } , { name : 'Dark Theme' , value : Themes . BASIC_DARK_THEME } , ] ; readonly logMonitorStateControl = new FormControl ( ) ; private themeSetSubscription = Subscription . EMPTY ; private logMonitorStateUpdateSubscription = Subscription . EMPTY ; constructor ( private theme , private workspace , private confirmDialog ) { } ngOnInit ( ) { this . themeFormControl . patchValue ( this . theme . currentTheme ) ; this . themeSetSubscription = this . themeFormControl . valueChanges . subscribe ( this . theme . setTheme ) ; this . logMonitorStateControl . patchValue ( logMonitor . enabled ) ; this . logMonitorStateUpdateSubscription = this . logMonitorStateControl . valueChanges . subscribe ( ( enabled ) => { if ( enabled ) { logMonitor . enable ( ) ; } else { logMonitor . disable ( ) ; } } ) ; } ngOnDestroy ( ) { this . themeSetSubscription . unsubscribe ( ) ; this . logMonitorStateUpdateSubscription . unsubscribe ( ) ; } createNewWorkspace ( ) { this . workspace . initWorkspace ( ) . subscribe ( ( ) => { } , error => this . handleInitWorkspaceFail ( error ) ) ; } private handleInitWorkspaceFail ( error ) { this . confirmDialog . open ( { title : 'Workspace Error' , isAlert : true , body : ( error as ErrorWithMetadata ) . errorDescription ? ( error as ErrorWithMetadata ) . errorDescription : 'Unknown Error' , } ) ; } }