You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RTL/src/app/shared/components/app-settings/app-settings.component.ts

96 lines
3.4 KiB
TypeScript

import { Component, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { faTools } from '@fortawesome/free-solid-svg-icons';
import { LightningNode, RTLConfiguration, GetInfoRoot } from '../../models/RTLconfig';
import { LoggerService } from '../../services/logger.service';
import * as RTLActions from '../../../store/rtl.actions';
import * as fromRTLReducer from '../../../store/rtl.reducers';
@Component({
selector: 'rtl-app-settings',
templateUrl: './app-settings.component.html',
styleUrls: ['./app-settings.component.scss']
})
export class AppSettingsComponent implements OnInit, OnDestroy {
public faTools = faTools;
public selNode: LightningNode;
public information: GetInfoRoot = {};
public menus = ['Vertical', 'Horizontal'];
public menuTypes = ['Regular', 'Compact', 'Mini'];
public selectedMenu: string;
public selectedMenuType: string;
public currencyUnit = 'BTC';
public showSettingOption = true;
public appConfig: RTLConfiguration;
unsubs: Array<Subject<void>> = [new Subject(), new Subject()];
@Output('done') done: EventEmitter<void> = new EventEmitter();
constructor(private logger: LoggerService, private store: Store<fromRTLReducer.RTLState>) {}
ngOnInit() {
this.store.select('root')
.pipe(takeUntil(this.unsubs[0]))
.subscribe((rtlStore) => {
this.appConfig = rtlStore.appConfig;
this.selNode = rtlStore.selNode;
this.selectedMenu = this.selNode.settings.menu;
this.selectedMenuType = this.selNode.settings.menuType;
if (window.innerWidth <= 768) {
this.selNode.settings.menu = 'Vertical';
this.selNode.settings.flgSidenavOpened = false;
this.selNode.settings.flgSidenavPinned = false;
this.showSettingOption = false;
}
this.information = rtlStore.nodeData;
this.currencyUnit = (undefined !== this.information && undefined !== this.information.currency_unit) ? this.information.currency_unit : 'BTC';
this.logger.info(rtlStore);
});
}
public chooseMenu() {
this.selNode.settings.menu = this.selectedMenu;
}
public chooseMenuType() {
this.selNode.settings.menuType = this.selectedMenuType;
}
toggleSettings(toggleField: string) {
this.selNode.settings[toggleField] = !this.selNode.settings[toggleField];
if (toggleField === 'satsToBTC') {
this.store.dispatch(new RTLActions.SetChildNodeSettings({channelBackupPath: this.selNode.settings.channelBackupPath, satsToBTC: this.selNode.settings.satsToBTC}));
this.store.dispatch(new RTLActions.SetChildNodeSettingsCL({channelBackupPath: this.selNode.settings.channelBackupPath, satsToBTC: this.selNode.settings.satsToBTC}));
}
}
changeTheme(newTheme: string) {
this.selNode.settings.theme = newTheme;
}
onClose() {
this.logger.info(this.selNode.settings);
this.store.dispatch(new RTLActions.SaveSettings(this.selNode.settings));
this.done.emit();
}
onSelectionChange(selNodeValue: LightningNode) {
this.selNode = selNodeValue;
this.store.dispatch(new RTLActions.OpenSpinner('Updating Selected Node...'));
this.store.dispatch(new RTLActions.SetSelelectedNode({ lnNode: selNodeValue, isInitialSetup: false }));
}
ngOnDestroy() {
this.unsubs.forEach(unsub => {
unsub.next();
unsub.complete();
});
}
}