Whole Setup Validation

Whole Setup Validation
pull/1127/head
ShahanaFarooqui 2 years ago
parent a72f00a97b
commit d6185dd409

@ -1,7 +1,7 @@
import { Database } from '../../utils/database.js';
import { Logger } from '../../utils/logger.js';
import { Common } from '../../utils/common.js';
import { CollectionsEnum } from '../../models/database.model.js';
import { CollectionFieldsEnum, CollectionsEnum } from '../../models/database.model.js';
const logger = Logger;
const common = Common;
const databaseService = Database;
@ -17,11 +17,86 @@ export const getPageSettings = (req, res, next) => {
};
export const savePageSettings = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Page Settings', msg: 'Saving Page Settings..' });
return databaseService.insert(req.session.selectedNode, CollectionsEnum.PAGE_SETTINGS, req.updatedSettings).then((insertedSettings) => {
logger.log({ level: 'DEBUG', fileName: 'Page Settings', msg: 'Page Settings Updated', data: insertedSettings });
return res.status(201).json(true);
}).catch((errRes) => {
req.body = [
{
pageId: "payments",
tables: [
{
recordsPerPage: 25,
sortBy: "created_at",
sortOrder: "Ascending",
showColumns: [
"created_at",
"type",
"payment_hash",
"msatoshi_sent",
"msatoshi",
],
},
],
},
{
pageId: "invoices1",
tables: [
{
tableId: "invoices1",
recordsPerPage: 10,
showColumns: [
"msatoshi_received",
],
},
],
},
{
tables: [
{
tableId: "invoices2",
sortBy: "expires_at",
sortOrder: "Descending",
showColumns: [
"expires_at",
"paid_at",
"type",
"description",
"msatoshi",
"msatoshi_received",
],
},
],
},
{
pageId: "invoices3",
tables: [
{
tableId: "invoices3",
sortBy: "expires_at",
sortOrder: "Descending",
showColumns: [
"expires_at",
"paid_at",
"type",
"description",
"msatoshi",
"msatoshi_received",
],
},
],
}
];
return Promise.all(req.body.map((page) => databaseService.update(req.session.selectedNode, CollectionsEnum.PAGE_SETTINGS, page, CollectionFieldsEnum.PAGE_ID, page.pageId))).
then((values) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Payment List Decoded', data: values });
res.status(201).json(values);
}).
catch((errRes) => {
const err = common.handleError(errRes, 'Page Settings', 'Page Settings Update Error', req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error });
});
// return databaseService.insert(req.session.selectedNode, CollectionsEnum.PAGE_SETTINGS, req.body).then((insertedSettings) => {
// logger.log({ level: 'DEBUG', fileName: 'Page Settings', msg: 'Page Settings Updated', data: insertedSettings });
// return res.status(201).json(true);
// }).catch((errRes) => {
// const err = common.handleError(errRes, 'Page Settings', 'Page Settings Update Error', req.session.selectedNode);
// return res.status(err.statusCode).json({ message: err.message, error: err.error });
// });
};

@ -16,6 +16,16 @@ export class Offer {
this.lastUpdatedAt = lastUpdatedAt;
}
}
export const validateDocument = (collectionName, documentToValidate) => {
switch (collectionName) {
case CollectionsEnum.OFFERS:
return validateOffer(documentToValidate);
case CollectionsEnum.PAGE_SETTINGS:
return validatePageSettings(documentToValidate);
default:
return ({ isValid: false, error: 'Collection does not exist' });
}
};
export const validateOffer = (documentToValidate) => {
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.BOLT12)) {
return ({ isValid: false, error: CollectionFieldsEnum.BOLT12 + ' is mandatory.' });
@ -38,8 +48,7 @@ export var SortOrderEnum;
})(SortOrderEnum || (SortOrderEnum = {}));
export var PageSettingsFieldsEnum;
(function (PageSettingsFieldsEnum) {
PageSettingsFieldsEnum["PAYMENTS"] = "payments";
PageSettingsFieldsEnum["INVOICES"] = "invoices";
PageSettingsFieldsEnum["PAGE_ID"] = "pageId";
PageSettingsFieldsEnum["TABLES"] = "tables";
})(PageSettingsFieldsEnum || (PageSettingsFieldsEnum = {}));
export var TableSettingsFieldsEnum;
@ -60,28 +69,49 @@ export class TableSetting {
}
}
export class PageSettings {
constructor(pages) {
this.pages = pages;
constructor(pageId, tables) {
this.pageId = pageId;
this.tables = tables;
}
}
export const validatePageSettings = (documentToValidate) => {
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.PAYMENTS)) {
return ({ isValid: false, error: CollectionFieldsEnum.PAYMENTS + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.INVOICES)) {
return ({ isValid: false, error: CollectionFieldsEnum.INVOICES + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.TABLES)) {
return ({ isValid: false, error: CollectionFieldsEnum.TABLES + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.TABLE_ID)) {
return ({ isValid: false, error: CollectionFieldsEnum.TABLE_ID + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.SHOW_COLUMNS)) {
return ({ isValid: false, error: CollectionFieldsEnum.SHOW_COLUMNS + ' is mandatory.' });
}
if (documentToValidate[CollectionFieldsEnum.SHOW_COLUMNS].length < 3) {
return ({ isValid: false, error: CollectionFieldsEnum.SHOW_COLUMNS + ' should have at least 2 fields.' });
const errorMessages = documentToValidate.reduce((docAcc, doc, pageIdx) => {
let newDocMsgs = '';
if (!doc.hasOwnProperty(CollectionFieldsEnum.PAGE_ID)) {
newDocMsgs = newDocMsgs + ' ' + CollectionFieldsEnum.PAGE_ID + ' is mandatory.';
}
if (!doc.hasOwnProperty(CollectionFieldsEnum.TABLES)) {
newDocMsgs = newDocMsgs + ' ' + CollectionFieldsEnum.TABLES + ' is mandatory.';
}
newDocMsgs = newDocMsgs + ' ' + doc.tables.reduce((tableAcc, table, tableIdx) => {
if (!table.hasOwnProperty(CollectionFieldsEnum.TABLE_ID)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.TABLE_ID + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.SORT_BY)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SORT_BY + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.SORT_ORDER)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SORT_ORDER + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.RECORDS_PER_PAGE)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.RECORDS_PER_PAGE + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.SHOW_COLUMNS)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SHOW_COLUMNS + ' is mandatory.';
}
if (table[CollectionFieldsEnum.SHOW_COLUMNS].length < 2) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SHOW_COLUMNS + ' should have at least 2 fields.';
}
tableAcc = tableAcc.trim() !== '' ? ('table ' + (table.hasOwnProperty(CollectionFieldsEnum.TABLE_ID) ? table[CollectionFieldsEnum.TABLE_ID] : (tableIdx + 1)) + tableAcc) : '';
return tableAcc;
}, '');
if (newDocMsgs.trim() !== '') {
docAcc = docAcc + '\nFor page ' + (doc.hasOwnProperty(CollectionFieldsEnum.PAGE_ID) ? doc[CollectionFieldsEnum.PAGE_ID] : (pageIdx + 1)) + newDocMsgs;
}
return docAcc;
}, '');
if (errorMessages !== '') {
return ({ isValid: false, error: errorMessages });
}
return ({ isValid: true });
};

@ -3,7 +3,7 @@ import { join, dirname, sep } from 'path';
import { fileURLToPath } from 'url';
import { Common } from '../utils/common.js';
import { Logger } from '../utils/logger.js';
import { CollectionsEnum, validateOffer } from '../models/database.model.js';
import { validateDocument } from '../models/database.model.js';
export class DatabaseService {
constructor() {
this.common = Common;
@ -33,7 +33,7 @@ export class DatabaseService {
if (!selectedNode || !selectedNode.index) {
reject(new Error('Selected Node Config Not Found.'));
}
const validationRes = this.validateDocument(CollectionsEnum.OFFERS, newDocument);
const validationRes = validateDocument(collectionName, newDocument);
if (!validationRes.isValid) {
reject(validationRes.error);
}
@ -68,7 +68,7 @@ export class DatabaseService {
}
updatedDocument = foundDoc;
}
const validationRes = this.validateDocument(CollectionsEnum.OFFERS, updatedDocument);
const validationRes = validateDocument(collectionName, updatedDocument);
if (!validationRes.isValid) {
reject(validationRes.error);
}
@ -130,14 +130,6 @@ export class DatabaseService {
}
});
}
validateDocument(collectionName, documentToValidate) {
switch (collectionName) {
case CollectionsEnum.OFFERS:
return validateOffer(documentToValidate);
default:
return ({ isValid: false, error: 'Collection does not exist' });
}
}
saveDatabase(nodeIndex) {
try {
if (+nodeIndex < 1) {

@ -1,7 +1,7 @@
import { Database, DatabaseService } from '../../utils/database.js';
import { Logger, LoggerService } from '../../utils/logger.js';
import { Common, CommonService } from '../../utils/common.js';
import { CollectionsEnum, PageSettings } from '../../models/database.model.js';
import { CollectionFieldsEnum, CollectionsEnum, PageSettings } from '../../models/database.model.js';
const logger: LoggerService = Logger;
const common: CommonService = Common;
@ -20,11 +20,86 @@ export const getPageSettings = (req, res, next) => {
export const savePageSettings = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Page Settings', msg: 'Saving Page Settings..' });
return databaseService.insert(req.session.selectedNode, CollectionsEnum.PAGE_SETTINGS, req.updatedSettings).then((insertedSettings) => {
logger.log({ level: 'DEBUG', fileName: 'Page Settings', msg: 'Page Settings Updated', data: insertedSettings });
return res.status(201).json(true);
}).catch((errRes) => {
const err = common.handleError(errRes, 'Page Settings', 'Page Settings Update Error', req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error });
});
req.body = [
{
pageId: "payments",
tables: [
{
recordsPerPage: 25,
sortBy: "created_at",
sortOrder: "Ascending",
showColumns: [
"created_at",
"type",
"payment_hash",
"msatoshi_sent",
"msatoshi",
],
},
],
},
{
pageId: "invoices1",
tables: [
{
tableId: "invoices1",
recordsPerPage: 10,
showColumns: [
"msatoshi_received",
],
},
],
},
{
tables: [
{
tableId: "invoices2",
sortBy: "expires_at",
sortOrder: "Descending",
showColumns: [
"expires_at",
"paid_at",
"type",
"description",
"msatoshi",
"msatoshi_received",
],
},
],
},
{
pageId: "invoices3",
tables: [
{
tableId: "invoices3",
sortBy: "expires_at",
sortOrder: "Descending",
showColumns: [
"expires_at",
"paid_at",
"type",
"description",
"msatoshi",
"msatoshi_received",
],
},
],
}
];
return Promise.all(req.body.map((page) => databaseService.update(req.session.selectedNode, CollectionsEnum.PAGE_SETTINGS, page, CollectionFieldsEnum.PAGE_ID, page.pageId))).
then((values) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Payment List Decoded', data: values });
res.status(201).json(values);
}).
catch((errRes) => {
const err = common.handleError(errRes, 'Page Settings', 'Page Settings Update Error', req.session.selectedNode);
return res.status(err.statusCode).json({ message: err.message, error: err.error });
});
// return databaseService.insert(req.session.selectedNode, CollectionsEnum.PAGE_SETTINGS, req.body).then((insertedSettings) => {
// logger.log({ level: 'DEBUG', fileName: 'Page Settings', msg: 'Page Settings Updated', data: insertedSettings });
// return res.status(201).json(true);
// }).catch((errRes) => {
// const err = common.handleError(errRes, 'Page Settings', 'Page Settings Update Error', req.session.selectedNode);
// return res.status(err.statusCode).json({ message: err.message, error: err.error });
// });
};

@ -19,6 +19,17 @@ export class Offer {
}
export const validateDocument = (collectionName: CollectionsEnum, documentToValidate: any): any => {
switch (collectionName) {
case CollectionsEnum.OFFERS:
return validateOffer(documentToValidate);
case CollectionsEnum.PAGE_SETTINGS:
return validatePageSettings(documentToValidate);
default:
return ({ isValid: false, error: 'Collection does not exist' });
}
};
export const validateOffer = (documentToValidate): any => {
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.BOLT12)) {
return ({ isValid: false, error: CollectionFieldsEnum.BOLT12 + ' is mandatory.' });
@ -41,8 +52,7 @@ export enum SortOrderEnum {
}
export enum PageSettingsFieldsEnum {
PAYMENTS = 'payments',
INVOICES = 'invoices',
PAGE_ID = 'pageId',
TABLES = 'tables'
}
@ -69,32 +79,50 @@ export class TableSetting {
export class PageSettings {
constructor(
public pages: {
payments: { tables: TableSetting[] };
invoices: { tables: TableSetting[] };
}
public pageId: string,
public tables: TableSetting[]
) { }
}
export const validatePageSettings = (documentToValidate): any => {
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.PAYMENTS)) {
return ({ isValid: false, error: CollectionFieldsEnum.PAYMENTS + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.INVOICES)) {
return ({ isValid: false, error: CollectionFieldsEnum.INVOICES + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.TABLES)) {
return ({ isValid: false, error: CollectionFieldsEnum.TABLES + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.TABLE_ID)) {
return ({ isValid: false, error: CollectionFieldsEnum.TABLE_ID + ' is mandatory.' });
}
if (!documentToValidate.hasOwnProperty(CollectionFieldsEnum.SHOW_COLUMNS)) {
return ({ isValid: false, error: CollectionFieldsEnum.SHOW_COLUMNS + ' is mandatory.' });
}
if (documentToValidate[CollectionFieldsEnum.SHOW_COLUMNS].length < 3) {
return ({ isValid: false, error: CollectionFieldsEnum.SHOW_COLUMNS + ' should have at least 2 fields.' });
const errorMessages = documentToValidate.reduce((docAcc, doc: PageSettings, pageIdx) => {
let newDocMsgs = '';
if (!doc.hasOwnProperty(CollectionFieldsEnum.PAGE_ID)) {
newDocMsgs = newDocMsgs + ' ' + CollectionFieldsEnum.PAGE_ID + ' is mandatory.';
}
if (!doc.hasOwnProperty(CollectionFieldsEnum.TABLES)) {
newDocMsgs = newDocMsgs + ' ' + CollectionFieldsEnum.TABLES + ' is mandatory.';
}
newDocMsgs = newDocMsgs + ' ' + doc.tables.reduce((tableAcc, table: TableSetting, tableIdx) => {
if (!table.hasOwnProperty(CollectionFieldsEnum.TABLE_ID)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.TABLE_ID + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.SORT_BY)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SORT_BY + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.SORT_ORDER)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SORT_ORDER + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.RECORDS_PER_PAGE)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.RECORDS_PER_PAGE + ' is mandatory.';
}
if (!table.hasOwnProperty(CollectionFieldsEnum.SHOW_COLUMNS)) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SHOW_COLUMNS + ' is mandatory.';
}
if (table[CollectionFieldsEnum.SHOW_COLUMNS].length < 2) {
tableAcc = tableAcc + ' ' + CollectionFieldsEnum.SHOW_COLUMNS + ' should have at least 2 fields.';
}
tableAcc = tableAcc.trim() !== '' ? ('table ' + (table.hasOwnProperty(CollectionFieldsEnum.TABLE_ID) ? table[CollectionFieldsEnum.TABLE_ID] : (tableIdx + 1)) + tableAcc) : '';
return tableAcc;
}, '');
if (newDocMsgs.trim() !== '') {
docAcc = docAcc + '\nFor page ' + (doc.hasOwnProperty(CollectionFieldsEnum.PAGE_ID) ? doc[CollectionFieldsEnum.PAGE_ID] : (pageIdx + 1)) + newDocMsgs;
}
return docAcc;
}, '');
if (errorMessages !== '') {
return ({ isValid: false, error: errorMessages });
}
return ({ isValid: true });
};
@ -106,7 +134,7 @@ export enum CollectionsEnum {
export type Collections = {
Offers: Offer[];
PageSettings: PageSettings;
PageSettings: PageSettings[];
}
export const CollectionFieldsEnum = { ...OfferFieldsEnum, ...PageSettingsFieldsEnum, ...TableSettingsFieldsEnum };

@ -3,7 +3,7 @@ import { join, dirname, sep } from 'path';
import { fileURLToPath } from 'url';
import { Common, CommonService } from '../utils/common.js';
import { Logger, LoggerService } from '../utils/logger.js';
import { Collections, CollectionsEnum, validateOffer } from '../models/database.model.js';
import { Collections, CollectionsEnum, validateDocument } from '../models/database.model.js';
import { CommonSelectedNode } from '../models/config.model.js';
export class DatabaseService {
@ -36,7 +36,7 @@ export class DatabaseService {
if (!selectedNode || !selectedNode.index) {
reject(new Error('Selected Node Config Not Found.'));
}
const validationRes = this.validateDocument(CollectionsEnum.OFFERS, newDocument);
const validationRes = validateDocument(collectionName, newDocument);
if (!validationRes.isValid) {
reject(validationRes.error);
} else {
@ -70,7 +70,7 @@ export class DatabaseService {
}
updatedDocument = foundDoc;
}
const validationRes = this.validateDocument(CollectionsEnum.OFFERS, updatedDocument);
const validationRes = validateDocument(collectionName, updatedDocument);
if (!validationRes.isValid) {
reject(validationRes.error);
} else {
@ -128,16 +128,6 @@ export class DatabaseService {
});
}
validateDocument(collectionName: CollectionsEnum, documentToValidate: any) {
switch (collectionName) {
case CollectionsEnum.OFFERS:
return validateOffer(documentToValidate);
default:
return ({ isValid: false, error: 'Collection does not exist' });
}
}
saveDatabase(nodeIndex: number) {
try {
if (+nodeIndex < 1) {

@ -14,9 +14,9 @@ export const setChildNodeSettingsCL = createAction(CLNActions.SET_CHILD_NODE_SET
export const fetchPageSettingsCL = createAction(CLNActions.FETCH_PAGE_SETTINGS_CLN);
export const setPageSettings = createAction(CLNActions.SET_PAGE_SETTINGS_CLN, props<{ payload: PageSettingsCLN }>());
export const setPageSettings = createAction(CLNActions.SET_PAGE_SETTINGS_CLN, props<{ payload: PageSettingsCLN[] }>());
export const savePageSettings = createAction(CLNActions.SAVE_PAGE_SETTINGS_CLN, props<{ payload: PageSettingsCLN }>());
export const savePageSettings = createAction(CLNActions.SAVE_PAGE_SETTINGS_CLN, props<{ payload: PageSettingsCLN[] }>());
export const fetchInfoCL = createAction(CLNActions.FETCH_INFO_CLN, props<{ payload: { loadPage: string } }>());

@ -219,13 +219,18 @@ export const CLNReducer = createReducer(initCLNState,
};
}),
on(setPageSettings, (state, { payload }) => {
const sortedPageSettings = Object.keys(CLN_DEFAULT_PAGE_SETTINGS).reduce((acc, page) => {
acc[page] = (payload && payload.hasOwnProperty(page)) ? payload[page] : CLN_DEFAULT_PAGE_SETTINGS[page];
return acc;
}, {});
const newPageSettings: PageSettingsCLN[] = [];
CLN_DEFAULT_PAGE_SETTINGS.forEach((page) => {
const pageIdx = payload.findIndex((p) => p.pageId === page.pageId);
if (pageIdx >= 0) {
newPageSettings.push(payload[pageIdx]);
} else {
newPageSettings.push(page);
}
});
return {
...state,
pageSettings: sortedPageSettings
pageSettings: newPageSettings
};
})
);

@ -7,7 +7,7 @@ import { PageSettingsCLN } from '../../shared/models/pageSettings';
export interface CLNState {
apisCallStatus: ApiCallsListCL;
nodeSettings: SelNodeChild | null;
pageSettings: PageSettingsCLN;
pageSettings: PageSettingsCLN[];
information: GetInfo;
fees: Fees;
feeRatesPerKB: FeeRates;

@ -4,11 +4,11 @@
<fa-icon [icon]="faPenRuler" class="page-title-img mr-1"></fa-icon>
<span class="page-title">Page Settings</span>
</div>
<mat-expansion-panel fxLayout="column" class="flat-expansion-panel mt-1" expanded="true" *ngFor="let page of pageSettings | keyvalue">
<mat-expansion-panel fxLayout="column" class="flat-expansion-panel mt-1" expanded="true" *ngFor="let page of pageSettings">
<mat-expansion-panel-header>
<mat-panel-title>{{page.key | titlecase}}</mat-panel-title>
<mat-panel-title>{{page.pageId | titlecase}}</mat-panel-title>
</mat-expansion-panel-header>
<div fxLayout="column" fxLayoutAlign="start stretch" *ngFor="let table of page.value.tables">
<div fxLayout="column" fxLayoutAlign="start stretch" *ngFor="let table of page.tables">
<div fxLayout="row" fxLayoutAlign="space-between center" class="mt-1">
<mat-form-field fxFlex="10">
<mat-select [(ngModel)]="table.recordsPerPage" placeholder="Records/Page" name="{{table.tableId}}-page-size-options" tabindex="1" required>

@ -4,12 +4,13 @@ import { takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { faPenRuler } from '@fortawesome/free-solid-svg-icons';
import { CLN_TABLE_FIELDS_DEF, PAGE_SIZE_OPTIONS, ScreenSizeEnum, SORT_ORDERS } from '../../../services/consts-enums-functions';
import { CLN_DEFAULT_PAGE_SETTINGS, CLN_TABLE_FIELDS_DEF, PAGE_SIZE_OPTIONS, ScreenSizeEnum, SORT_ORDERS } from '../../../services/consts-enums-functions';
import { LoggerService } from '../../../services/logger.service';
import { CommonService } from '../../../services/common.service';
import { RTLState } from '../../../../store/rtl.state';
import { TableSetting, PageSettingsCLN } from '../../../models/pageSettings';
import { clnPageSettings } from '../../../../cln/store/cln.selector';
import { savePageSettings } from '../../../../cln/store/cln.actions';
@Component({
selector: 'rtl-page-settings',
@ -22,7 +23,8 @@ export class PageSettingsComponent implements OnInit, OnDestroy {
public screenSize = '';
public screenSizeEnum = ScreenSizeEnum;
public pageSizeOptions = PAGE_SIZE_OPTIONS;
public pageSettings: PageSettingsCLN | null = null;
public pageSettings: PageSettingsCLN[] = [];
public initialPageSettings: PageSettingsCLN[] = CLN_DEFAULT_PAGE_SETTINGS;
public tableFieldsDef = CLN_TABLE_FIELDS_DEF;
public sortOrders = SORT_ORDERS;
unSubs: Array<Subject<void>> = [new Subject(), new Subject()];
@ -34,6 +36,7 @@ export class PageSettingsComponent implements OnInit, OnDestroy {
ngOnInit() {
this.store.select(clnPageSettings).pipe(takeUntil(this.unSubs[0])).subscribe((settings) => {
this.pageSettings = settings.pageSettings;
this.initialPageSettings = JSON.parse(JSON.stringify(settings.pageSettings));
this.logger.info(settings);
});
}
@ -44,19 +47,15 @@ export class PageSettingsComponent implements OnInit, OnDestroy {
}
}
onUpdatePageSettings() {
// if (this.selNode.settings.fiatConversion && !this.selNode.settings.currencyUnit) {
// return true;
// }
// 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
// }
// }));
onUpdatePageSettings(): boolean | void {
if (this.pageSettings.reduce((pacc, page) => pacc || (page.tables.reduce((acc, table) => !(table.recordsPerPage && table.sortBy && table.sortOrder && table.showColumns && table.showColumns.length >= 3), false)), false)) {
return true;
}
this.store.dispatch(savePageSettings({ payload: this.pageSettings }));
}
onResetPageSettings() {
// this.store.dispatch(setSelectedNode({ payload: { uiMessage: UI_MESSAGES.NO_SPINNER, prevLnNodeIndex: +prevIndex, currentLnNode: this.selNode, isInitialSetup: true } }));
this.pageSettings = this.initialPageSettings;
}
ngOnDestroy() {

@ -12,8 +12,7 @@ export class TableSetting {
export class PageSettingsCLN {
payments?: { seq?: number, tables?: TableSetting[] };
invoices?: { seq?: number, tables?: TableSetting[] };
utxos?: { seq?: number, tables?: TableSetting[] };
pageId: string;
tables: TableSetting[];
}

@ -674,18 +674,14 @@ export enum SortOrderEnum {
export const SORT_ORDERS = ['Ascending', 'Descending'];
export const CLN_DEFAULT_PAGE_SETTINGS: PageSettingsCLN = {
payments: { seq: 1, tables: [{ tableId: 'payments', recordsPerPage: 10, sortBy: 'created_at', sortOrder: SortOrderEnum.DESCENDING,
export const CLN_DEFAULT_PAGE_SETTINGS: PageSettingsCLN[] = [
{ pageId: 'payments', tables: [{ tableId: 'payments', recordsPerPage: 10, sortBy: 'created_at', sortOrder: SortOrderEnum.DESCENDING,
showColumns: ['created_at', 'type', 'payment_hash', 'msatoshi_sent', 'msatoshi'] }] },
invoices: { seq: 2, tables: [{ tableId: 'invoices', recordsPerPage: 10, sortBy: 'expires_at', sortOrder: SortOrderEnum.DESCENDING,
showColumns: ['expires_at', 'paid_at', 'type', 'description', 'msatoshi', 'msatoshi_received'] }] },
utxos: { seq: 3, tables: [{ tableId: 'utxos', recordsPerPage: 10, sortBy: 'expires_at', sortOrder: SortOrderEnum.DESCENDING,
{ pageId: 'invoices', tables: [{ tableId: 'invoices', recordsPerPage: 10, sortBy: 'expires_at', sortOrder: SortOrderEnum.DESCENDING,
showColumns: ['expires_at', 'paid_at', 'type', 'description', 'msatoshi', 'msatoshi_received'] }] }
};
];
export const CLN_TABLE_FIELDS_DEF = {
payments: ['created_at', 'type', 'payment_hash', 'msatoshi_sent', 'msatoshi', 'amount_msat', 'amount_sent_msat', 'destination', 'status', 'memo'],
invoices: ['expires_at', 'paid_at', 'type', 'description', 'msatoshi', 'msatoshi_received', 'label', 'payment_hash', 'amount_msat', 'status', 'amount_received_msat'],
utxos: ['expires_at', 'paid_at', 'type', 'description', 'msatoshi', 'msatoshi_received', 'label', 'payment_hash', 'amount_msat', 'status', 'amount_received_msat']
invoices: ['expires_at', 'paid_at', 'type', 'description', 'msatoshi', 'msatoshi_received', 'label', 'payment_hash', 'amount_msat', 'status', 'amount_received_msat']
};

Loading…
Cancel
Save