parent
dd180cba25
commit
6945d084b4
@ -0,0 +1,75 @@
|
||||
<div [perfectScrollbar] fxLayout="column" fxFlex="100">
|
||||
<form fxLayout="column" fxLayoutAlign="start stretch" class="settings-container page-sub-title-container mt-1" #form="ngForm">
|
||||
<div fxLayout="row">
|
||||
<fa-icon [icon]="faPenRuler" class="page-title-img mr-1"></fa-icon>
|
||||
<span class="page-title">Page Settings</span>
|
||||
</div>
|
||||
<!-- <div fxLayout="column" fxLayoutAlign="start stretch" class="mt-1 bordered-box padding-gap-large">
|
||||
<div fxFlex="100" class="alert alert-warn">
|
||||
<fa-icon [icon]="faExclamationTriangle" class="mr-1 alert-icon"></fa-icon>
|
||||
<span>Fiat conversion calls <strong><a href="https://www.blockchain.com/api/exchange_rates_api" target="blank">Blockchain.com</a></strong> API to get conversion rates.</span>
|
||||
</div>
|
||||
<div fxLayout="row wrap" fxLayoutAlign="start center">
|
||||
<mat-slide-toggle tabindex="2" color="primary" [(ngModel)]="selNode.settings.fiatConversion" (change)="selNode.settings.currencyUnit = !$event.checked ? null : selNode.settings.currencyUnit" name="fiatConversion">Enable Fiat Conversion</mat-slide-toggle>
|
||||
<mat-form-field>
|
||||
<mat-select autoFocus [(ngModel)]="selNode.settings.currencyUnit" (selectionChange)="onCurrencyChange($event)" placeholder="Fiat Currency" [disabled]="!selNode.settings.fiatConversion" tabindex="3" [required]="selNode.settings.fiatConversion" name="currencyUnit" #currencyUnit="ngModel">
|
||||
<mat-option *ngFor="let currencyUnit of currencyUnits" [value]="currencyUnit.id">
|
||||
{{currencyUnit.id}}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="selNode.settings.fiatConversion && !selNode.settings.currencyUnit">Currency unit is required.</mat-error>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
<div fxLayout="column" fxFlex="100" fxLayoutAlign="start stretch">
|
||||
<div fxLayout="row wrap" fxLayoutAlign="start start" fxLayout.gt-sm="column" fxFlex="100" fxLayoutAlign.gt-sm="space-between stretch" class="settings-container page-sub-title-container mt-1">
|
||||
<div class="mt-1">
|
||||
<fa-icon [icon]="faPaintBrush" class="page-title-img mr-1"></fa-icon>
|
||||
<span class="page-title">Customization</span>
|
||||
</div>
|
||||
<div fxLayout="column" fxLayoutAlign="start stretch" class="mt-1 bordered-box padding-gap-large">
|
||||
<div fxLayout="column" fxLayoutAlign="start stretch" fxFlex="100">
|
||||
<div fxLayout="row" fxFlex="100" class="alert alert-info mb-0">
|
||||
<fa-icon [icon]="faInfoCircle" class="mr-1 alert-icon"></fa-icon>
|
||||
<span>Dashboard layout will be tailored based on the role selected to better serve its needs.</span>
|
||||
</div>
|
||||
<div fxLayout="column" fxLayoutAlign="start start" fxFlex="100">
|
||||
<h4>Dashboard Layout</h4>
|
||||
<mat-radio-group color="primary" [(ngModel)]="selNode.settings.userPersona" tabindex="1" name="userPersona">
|
||||
<mat-radio-button *ngFor="let userPersona of userPersonas" [value]="userPersona" [checked]="selNode.settings.userPersona === userPersona" class="mr-4">
|
||||
{{userPersona | titlecase}}
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
<mat-divider [inset]="true" class="mt-1"></mat-divider>
|
||||
<div fxLayout="column" fxLayout.gt-xs="row" fxFlex="100" fxLayoutAlign="space-between stretch" fxLayoutAlign.gt-xs="start stretch">
|
||||
<div fxFlex.gt-xs="20" fxFlex.gt-md="15" fxLayout="column" fxLayoutAlign="space-between stretch">
|
||||
<h4>Mode</h4>
|
||||
<mat-radio-group color="primary" [(ngModel)]="selectedThemeMode" (change)="chooseThemeMode()" name="themeMode">
|
||||
<mat-radio-button tabindex="5" *ngFor="let themeMode of themeModes" [value]="themeMode" [ngClass]="{'mr-4': screenSize === screenSizeEnum.XS || screenSize === screenSizeEnum.SM}">{{themeMode.name}}
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
<mat-divider [inset]="true" class="mt-1"></mat-divider>
|
||||
<div fxLayout="column" fxLayout.gt-xs="row" fxFlex="100" fxLayoutAlign="space-between stretch" fxLayoutAlign.gt-xs="start stretch">
|
||||
<div fxLayout="column" fxFlex.gt-xs="50" fxFlex.gt-md="40" fxLayoutAlign="space-between stretch">
|
||||
<h4>Themes</h4>
|
||||
<div fxLayout="row" fxFlex="100" fxLayoutAlign="space-between start">
|
||||
<span *ngFor="let themeColor of themeColors" fxLayout="row" class="theme-name">
|
||||
<div tabindex="9" [class]="themeColor.id | lowercase" [ngClass]="{'skin': true, 'selected-color': selectedThemeColor === themeColor.id}" (click)="changeThemeColor(themeColor.id)"></div>
|
||||
{{themeColor.name}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</form>
|
||||
<div fxLayout="row" class="mt-1">
|
||||
<button class="mr-1" mat-stroked-button color="primary" (click)="onResetSettings()" tabindex="10">Reset</button>
|
||||
<button mat-flat-button color="primary" (click)="onUpdateSettings()" tabindex="11">Update</button>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,51 @@
|
||||
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
|
||||
import { RootReducer } from '../../../../store/rtl.reducers';
|
||||
import { LNDReducer } from '../../../../lnd/store/lnd.reducers';
|
||||
import { CLNReducer } from '../../../../cln/store/cln.reducers';
|
||||
import { ECLReducer } from '../../../../eclair/store/ecl.reducers';
|
||||
import { CommonService } from '../../../services/common.service';
|
||||
import { LoggerService } from '../../../services/logger.service';
|
||||
|
||||
import { PageSettingsComponent } from './page-settings.component';
|
||||
import { mockDataService, mockLoggerService } from '../../../test-helpers/mock-services';
|
||||
import { SharedModule } from '../../../shared.module';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { DataService } from '../../../services/data.service';
|
||||
|
||||
describe('PageSettingsComponent', () => {
|
||||
let component: PageSettingsComponent;
|
||||
let fixture: ComponentFixture<PageSettingsComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PageSettingsComponent],
|
||||
imports: [
|
||||
BrowserAnimationsModule,
|
||||
SharedModule,
|
||||
StoreModule.forRoot({ root: RootReducer, lnd: LNDReducer, cln: CLNReducer, ecl: ECLReducer })
|
||||
],
|
||||
providers: [
|
||||
CommonService,
|
||||
{ provide: LoggerService, useClass: mockLoggerService },
|
||||
{ provide: DataService, useClass: mockDataService }
|
||||
]
|
||||
}).
|
||||
compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PageSettingsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
});
|
@ -0,0 +1,129 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { faPenRuler } from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
import { CURRENCY_UNITS, UserPersonaEnum, ScreenSizeEnum, FIAT_CURRENCY_UNITS, NODE_SETTINGS, UI_MESSAGES } from '../../../services/consts-enums-functions';
|
||||
import { ConfigSettingsNode, Settings } from '../../../models/RTLconfig';
|
||||
import { LoggerService } from '../../../services/logger.service';
|
||||
import { CommonService } from '../../../services/common.service';
|
||||
import { RTLState } from '../../../../store/rtl.state';
|
||||
import { saveSettings, setSelectedNode } from '../../../../store/rtl.actions';
|
||||
import { setChildNodeSettingsECL } from '../../../../eclair/store/ecl.actions';
|
||||
import { setChildNodeSettingsCL } from '../../../../cln/store/cln.actions';
|
||||
import { setChildNodeSettingsLND } from '../../../../lnd/store/lnd.actions';
|
||||
import { rootSelectedNode } from '../../../../store/rtl.selector';
|
||||
|
||||
@Component({
|
||||
selector: 'rtl-page-settings',
|
||||
templateUrl: './page-settings.component.html',
|
||||
styleUrls: ['./page-settings.component.scss']
|
||||
})
|
||||
export class PageSettingsComponent implements OnInit, OnDestroy {
|
||||
|
||||
public faPenRuler = faPenRuler;
|
||||
public selNode: ConfigSettingsNode | any;
|
||||
public userPersonas = [UserPersonaEnum.OPERATOR, UserPersonaEnum.MERCHANT];
|
||||
public currencyUnits = FIAT_CURRENCY_UNITS;
|
||||
public themeModes = NODE_SETTINGS.modes;
|
||||
public themeColors = NODE_SETTINGS.themes;
|
||||
public selectedThemeMode = NODE_SETTINGS.modes[0];
|
||||
public selectedThemeColor = NODE_SETTINGS.themes[0].id;
|
||||
public currencyUnit = 'BTC';
|
||||
public smallerCurrencyUnit = 'Sats';
|
||||
public showSettingOption = true;
|
||||
public previousSettings: Settings;
|
||||
public screenSize = '';
|
||||
public screenSizeEnum = ScreenSizeEnum;
|
||||
unSubs: Array<Subject<void>> = [new Subject(), new Subject()];
|
||||
|
||||
constructor(private logger: LoggerService, private commonService: CommonService, private store: Store<RTLState>) {
|
||||
this.screenSize = this.commonService.getScreenSize();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.store.select(rootSelectedNode).pipe(takeUntil(this.unSubs[0])).subscribe((selNode) => {
|
||||
this.selNode = selNode;
|
||||
this.selectedThemeMode = this.themeModes.find((themeMode) => this.selNode.settings.themeMode === themeMode.id) || this.themeModes[0];
|
||||
this.selectedThemeColor = this.selNode.settings.themeColor;
|
||||
if (!this.selNode.settings.fiatConversion) {
|
||||
this.selNode.settings.currencyUnit = '';
|
||||
}
|
||||
this.previousSettings = JSON.parse(JSON.stringify(this.selNode.settings));
|
||||
this.logger.info(selNode);
|
||||
});
|
||||
}
|
||||
|
||||
onCurrencyChange(event: any) {
|
||||
this.selNode.settings.currencyUnits = [...CURRENCY_UNITS, event.value];
|
||||
this.store.dispatch(setChildNodeSettingsLND({
|
||||
payload: {
|
||||
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: event.value, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion,
|
||||
lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
|
||||
}
|
||||
}));
|
||||
this.store.dispatch(setChildNodeSettingsCL({
|
||||
payload: {
|
||||
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: event.value, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
|
||||
}
|
||||
}));
|
||||
this.store.dispatch(setChildNodeSettingsECL({
|
||||
payload: {
|
||||
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: event.value, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
toggleSettings(toggleField: string, event?: any) {
|
||||
this.selNode.settings[toggleField] = !this.selNode.settings[toggleField];
|
||||
}
|
||||
|
||||
changeThemeColor(newThemeColor: string) {
|
||||
this.selectedThemeColor = newThemeColor;
|
||||
this.selNode.settings.themeColor = newThemeColor;
|
||||
}
|
||||
|
||||
chooseThemeMode() {
|
||||
this.selNode.settings.themeMode = this.selectedThemeMode.id;
|
||||
}
|
||||
|
||||
onUpdateSettings(): boolean | void {
|
||||
if (this.selNode.settings.fiatConversion && !this.selNode.settings.currencyUnit) {
|
||||
return true;
|
||||
}
|
||||
this.logger.info(this.selNode.settings);
|
||||
this.store.dispatch(saveSettings({ payload: { uiMessage: UI_MESSAGES.UPDATE_NODE_SETTINGS, settings: this.selNode.settings } }));
|
||||
this.store.dispatch(setChildNodeSettingsLND({
|
||||
payload: {
|
||||
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
|
||||
}
|
||||
}));
|
||||
this.store.dispatch(setChildNodeSettingsCL({
|
||||
payload: {
|
||||
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
|
||||
}
|
||||
}));
|
||||
this.store.dispatch(setChildNodeSettingsECL({
|
||||
payload: {
|
||||
userPersona: this.selNode.settings.userPersona, channelBackupPath: this.selNode.settings.channelBackupPath, selCurrencyUnit: this.selNode.settings.currencyUnit, currencyUnits: this.selNode.settings.currencyUnits, fiatConversion: this.selNode.settings.fiatConversion, lnImplementation: this.selNode.lnImplementation, swapServerUrl: this.selNode.settings.swapServerUrl, boltzServerUrl: this.selNode.settings.boltzServerUrl
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
onResetSettings() {
|
||||
const prevIndex = this.selNode.index || -1;
|
||||
this.selNode.settings = this.previousSettings;
|
||||
this.selectedThemeMode = this.themeModes.find((themeMode) => themeMode.id === this.previousSettings.themeMode) || this.themeModes[0];
|
||||
this.selectedThemeColor = this.previousSettings.themeColor;
|
||||
this.store.dispatch(setSelectedNode({ payload: { uiMessage: UI_MESSAGES.NO_SPINNER, prevLnNodeIndex: +prevIndex, currentLnNode: this.selNode, isInitialSetup: true } }));
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.unSubs.forEach((unsub) => {
|
||||
unsub.next();
|
||||
unsub.complete();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue