import { Component , OnDestroy , OnInit } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { Observable , Subscription } from 'rxjs' ; import { UploadFileData } from 'uhk-common' ; import { faSlidersH } from '@fortawesome/free-solid-svg-icons' ; import { AppState , getConfigSizesState , getUserConfigHistoryComponentState , isUserConfigSaving } from '../../../store' ; import { ResetUserConfigurationAction } from '../../../store/actions/device' ; import { LoadUserConfigurationFromFileAction , SaveUserConfigInBinaryFileAction , SaveUserConfigInJsonFileAction } from '../../../store/actions/user-config' ; import { UhkProgressBarState , UserConfigHistoryComponentState } from '../../../models' ; import { GetUserConfigurationFromHistoryAction , LoadUserConfigurationHistoryAction } from '../../../store/actions/user-configuration-history.actions' ; @ Component ( { selector : 'device-settings' , templateUrl : './device-configuration.component.html' , styleUrls : [ './device-configuration.component.scss' ] , host : { 'class' : 'container-fluid full-screen-component' } } ) export class DeviceConfigurationComponent implements OnInit , OnDestroy { configSizesState$ : Observable < UhkProgressBarState > ; userConfigHistoryState$ : Observable < UserConfigHistoryComponentState > ; savingUserConfig : boolean ; faSlidersH = faSlidersH ; private subscription = new Subscription ( ) ; constructor ( private store ) { this . configSizesState$ = this . store . select ( getConfigSizesState ) ; this . userConfigHistoryState$ = this . store . select ( getUserConfigHistoryComponentState ) ; this . subscription . add ( this . store . select ( isUserConfigSaving ) . subscribe ( x => this . savingUserConfig = x ) ) ; } ngOnInit ( ) { this . store . dispatch ( new LoadUserConfigurationHistoryAction ( ) ) ; } ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } resetUserConfiguration ( ) { this . store . dispatch ( new ResetUserConfigurationAction ( ) ) ; } saveConfigurationInJSONFormat ( ) { this . store . dispatch ( new SaveUserConfigInJsonFileAction ( ) ) ; } saveConfigurationInBINFormat ( ) { this . store . dispatch ( new SaveUserConfigInBinaryFileAction ( ) ) ; } exportUserConfiguration ( event ) { if ( event . shiftKey ) { this . saveConfigurationInBINFormat ( ) ; } else { this . saveConfigurationInJSONFormat ( ) ; } } changeFile ( data ) { this . store . dispatch ( new LoadUserConfigurationFromFileAction ( { uploadFileData : { ... data , saveInHistory : true } , autoSave : false } ) ) ; } getUserConfigFromHistory ( fileName ) { this . store . dispatch ( new GetUserConfigurationFromHistoryAction ( fileName ) ) ; } }