From 0dc879038ab86018127dc9deb967168a15106cfc Mon Sep 17 00:00:00 2001 From: ShahanaFarooqui Date: Thu, 3 Nov 2022 09:49:10 -0700 Subject: [PATCH] ECL Filter by selected columns --- .../on-chain-transaction-history.component.ts | 40 ++++++--------- .../channel-inactive-table.component.ts | 41 ++++++--------- .../channel-open-table.component.ts | 41 ++++++--------- .../channel-pending-table.component.ts | 41 ++++++--------- .../peers-channels/peers/peers.component.ts | 37 ++++++-------- .../forwarding-history.component.ts | 44 +++++++--------- .../invoices/lightning-invoices.component.ts | 51 ++++++++++--------- .../payments/lightning-payments.component.ts | 40 ++++++--------- 8 files changed, 135 insertions(+), 200 deletions(-) diff --git a/src/app/eclair/on-chain/on-chain-transaction-history/on-chain-transaction-history.component.ts b/src/app/eclair/on-chain/on-chain-transaction-history/on-chain-transaction-history.component.ts index 1fda879a..50773e6d 100644 --- a/src/app/eclair/on-chain/on-chain-transaction-history/on-chain-transaction-history.component.ts +++ b/src/app/eclair/on-chain/on-chain-transaction-history/on-chain-transaction-history.component.ts @@ -100,32 +100,22 @@ export class ECLOnChainTransactionHistoryComponent implements OnInit, OnDestroy setFilterPredicate() { this.listTransactions.filterPredicate = (rowData: Transaction, fltr: string) => { - const newRowData = ((rowData.timestamp) ? this.datePipe.transform(new Date(rowData.timestamp * 1000), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); - return newRowData.includes(fltr); + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = ((rowData.timestamp) ? this.datePipe.transform(new Date(rowData.timestamp * 1000), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); + break; + + case 'timestamp': + rowToFilter = this.datePipe.transform(new Date((rowData[this.selFilterBy] || 0) * 1000), 'dd/MMM/YYYY HH:mm')?.toLowerCase() || ''; + break; + + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return rowToFilter.includes(fltr); }; - // this.listTransactions.filterPredicate = (rowData: Transaction, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; - - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; } onTransactionClick(selTransaction: Transaction, event: any) { diff --git a/src/app/eclair/peers-channels/channels/channels-tables/channel-inactive-table/channel-inactive-table.component.ts b/src/app/eclair/peers-channels/channels/channels-tables/channel-inactive-table/channel-inactive-table.component.ts index 03e59e28..95189be3 100644 --- a/src/app/eclair/peers-channels/channels/channels-tables/channel-inactive-table/channel-inactive-table.component.ts +++ b/src/app/eclair/peers-channels/channels/channels-tables/channel-inactive-table/channel-inactive-table.component.ts @@ -166,34 +166,23 @@ export class ECLChannelInactiveTableComponent implements OnInit, AfterViewInit, } setFilterPredicate() { - this.channels.filterPredicate = (rowData: Channel, fltr: string) => JSON.stringify(rowData).toLowerCase().includes(fltr); - // this.invoices.filterPredicate = (rowData: Invoice, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; + this.channels.filterPredicate = (rowData: Channel, fltr: string) => { + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = JSON.stringify(rowData).toLowerCase(); + break; - // case 'announceChannel': - // rowToFilter = rowData?.private ? 'private' : 'public'; - // break; + case 'announceChannel': + rowToFilter = rowData?.announceChannel ? 'public' : 'private'; + break; - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return rowToFilter.includes(fltr); + }; } loadChannelsTable() { diff --git a/src/app/eclair/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts b/src/app/eclair/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts index c68be8d6..8a0ec2b5 100644 --- a/src/app/eclair/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts +++ b/src/app/eclair/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts @@ -236,34 +236,23 @@ export class ECLChannelOpenTableComponent implements OnInit, AfterViewInit, OnDe } setFilterPredicate() { - this.channels.filterPredicate = (rowData: Channel, fltr: string) => JSON.stringify(rowData).toLowerCase().includes(fltr); - // this.invoices.filterPredicate = (rowData: Invoice, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; + this.channels.filterPredicate = (rowData: Channel, fltr: string) => { + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = JSON.stringify(rowData).toLowerCase(); + break; - // case 'announceChannel': - // rowToFilter = rowData?.private ? 'private' : 'public'; - // break; + case 'announceChannel': + rowToFilter = rowData?.announceChannel ? 'public' : 'private'; + break; - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return rowToFilter.includes(fltr); + }; } loadChannelsTable() { diff --git a/src/app/eclair/peers-channels/channels/channels-tables/channel-pending-table/channel-pending-table.component.ts b/src/app/eclair/peers-channels/channels/channels-tables/channel-pending-table/channel-pending-table.component.ts index 465e775e..39543c61 100644 --- a/src/app/eclair/peers-channels/channels/channels-tables/channel-pending-table/channel-pending-table.component.ts +++ b/src/app/eclair/peers-channels/channels/channels-tables/channel-pending-table/channel-pending-table.component.ts @@ -136,34 +136,23 @@ export class ECLChannelPendingTableComponent implements OnInit, AfterViewInit, O } setFilterPredicate() { - this.channels.filterPredicate = (rowData: Channel, fltr: string) => JSON.stringify(rowData).toLowerCase().includes(fltr); - // this.channels.filterPredicate = (rowData: Channel, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; + this.channels.filterPredicate = (rowData: Channel, fltr: string) => { + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = JSON.stringify(rowData).toLowerCase(); + break; - // case 'announceChannel': - // rowToFilter = rowData?.private ? 'private' : 'public'; - // break; + case 'announceChannel': + rowToFilter = rowData?.announceChannel ? 'public' : 'private'; + break; - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return rowToFilter.includes(fltr); + }; } loadChannelsTable() { diff --git a/src/app/eclair/peers-channels/peers/peers.component.ts b/src/app/eclair/peers-channels/peers/peers.component.ts index 2278ca49..e3b997b9 100644 --- a/src/app/eclair/peers-channels/peers/peers.component.ts +++ b/src/app/eclair/peers-channels/peers/peers.component.ts @@ -213,30 +213,23 @@ export class ECLPeersComponent implements OnInit, AfterViewInit, OnDestroy { } setFilterPredicate() { - this.peers.filterPredicate = (rowData: Peer, fltr: string) => JSON.stringify(rowData).toLowerCase().includes(fltr); - // this.peers.filterPredicate = (rowData: Peer, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; + this.peers.filterPredicate = (rowData: Peer, fltr: string) => { + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = JSON.stringify(rowData).toLowerCase(); + break; - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; + case 'state': + rowToFilter = rowData?.state?.toLowerCase() || ''; + break; - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return this.selFilterBy === 'state' ? rowToFilter.indexOf(fltr) === 0 : rowToFilter.includes(fltr); + }; } loadPeersTable(peers: Peer[]) { diff --git a/src/app/eclair/routing/forwarding-history/forwarding-history.component.ts b/src/app/eclair/routing/forwarding-history/forwarding-history.component.ts index f83e91c2..893b4289 100644 --- a/src/app/eclair/routing/forwarding-history/forwarding-history.component.ts +++ b/src/app/eclair/routing/forwarding-history/forwarding-history.component.ts @@ -152,32 +152,26 @@ export class ECLForwardingHistoryComponent implements OnInit, OnChanges, AfterVi setFilterPredicate() { this.forwardingHistoryEvents.filterPredicate = (rowData: PaymentRelayed, fltr: string) => { - const newRowData = ((rowData.timestamp) ? this.datePipe.transform(new Date(rowData.timestamp), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); - return newRowData.includes(fltr); + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = ((rowData.timestamp) ? this.datePipe.transform(new Date(rowData.timestamp), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); + break; + + case 'timestamp': + rowToFilter = this.datePipe.transform(new Date((rowData.timestamp || 0)), 'dd/MMM/YYYY HH:mm')?.toLowerCase() || ''; + break; + + case 'fee': + rowToFilter = (rowData.amountIn - rowData.amountOut).toString() || '0'; + break; + + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return rowToFilter.includes(fltr); }; - // this.forwardingHistoryEvents.filterPredicate = (rowData: PaymentRelayed, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; - - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; } loadForwardingEventsTable(forwardingEvents: PaymentRelayed[]) { diff --git a/src/app/eclair/transactions/invoices/lightning-invoices.component.ts b/src/app/eclair/transactions/invoices/lightning-invoices.component.ts index a680e3f1..f3b5f31d 100644 --- a/src/app/eclair/transactions/invoices/lightning-invoices.component.ts +++ b/src/app/eclair/transactions/invoices/lightning-invoices.component.ts @@ -188,32 +188,33 @@ export class ECLLightningInvoicesComponent implements OnInit, AfterViewInit, OnD setFilterPredicate() { this.invoices.filterPredicate = (rowData: Invoice, fltr: string) => { - const newRowData = ((rowData.timestamp) ? this.datePipe.transform(new Date(rowData.timestamp * 1000), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); - return newRowData.includes(fltr); + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = ((rowData.timestamp) ? this.datePipe.transform(new Date(rowData.timestamp * 1000), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); + break; + + case 'status': + rowToFilter = !rowData?.status || rowData?.status === 'expired' || rowData?.status === 'unknown' ? 'expired/unknown' : rowData.status?.toLowerCase(); + break; + + case 'timestamp': + case 'expiresAt': + case 'receivedAt': + rowToFilter = this.datePipe.transform(new Date((rowData[this.selFilterBy] || 0) * 1000), 'dd/MMM/YYYY HH:mm')?.toLowerCase() || ''; + break; + + case 'amount': + case 'amountSettled': + rowToFilter = rowData[this.selFilterBy]?.toString() || '-'; + break; + + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return this.selFilterBy === 'status' ? rowToFilter.indexOf(fltr) === 0 : rowToFilter.includes(fltr); }; - // this.invoices.filterPredicate = (rowData: Invoice, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; - - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; } loadInvoicesTable(invs: Invoice[]) { diff --git a/src/app/eclair/transactions/payments/lightning-payments.component.ts b/src/app/eclair/transactions/payments/lightning-payments.component.ts index 7d58d997..6ac0f4dc 100644 --- a/src/app/eclair/transactions/payments/lightning-payments.component.ts +++ b/src/app/eclair/transactions/payments/lightning-payments.component.ts @@ -132,32 +132,22 @@ export class ECLLightningPaymentsComponent implements OnInit, AfterViewInit, OnD setFilterPredicate() { this.payments.filterPredicate = (rowData: PaymentSent, fltr: string) => { - const newRowData = ((rowData.firstPartTimestamp) ? this.datePipe.transform(new Date(rowData.firstPartTimestamp), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); - return newRowData.includes(fltr); + let rowToFilter = ''; + switch (this.selFilterBy) { + case 'all': + rowToFilter = ((rowData.firstPartTimestamp) ? this.datePipe.transform(new Date(rowData.firstPartTimestamp), 'dd/MMM/YYYY HH:mm')?.toLowerCase() : '') + JSON.stringify(rowData).toLowerCase(); + break; + + case 'firstPartTimestamp': + rowToFilter = this.datePipe.transform(new Date(rowData.firstPartTimestamp || 0), 'dd/MMM/YYYY HH:mm')?.toLowerCase() || ''; + break; + + default: + rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); + break; + } + return rowToFilter.includes(fltr); }; - // this.payments.filterPredicate = (rowData: PaymentSent, fltr: string) => { - // let rowToFilter = ''; - // switch (this.selFilterBy) { - // case 'all': - // for (let i = 0; i < this.displayedColumns.length - 1; i++) { - // rowToFilter = rowToFilter + ( - // (this.displayedColumns[i] === '') ? - // (rowData ? rowData..toLowerCase() : '') : - // (rowData[this.displayedColumns[i]] ? rowData[this.displayedColumns[i]].toLowerCase() : '') - // ) + ', '; - // } - // break; - - // case '': - // rowToFilter = rowData?..toLowerCase() || ''; - // break; - - // default: - // rowToFilter = typeof rowData[this.selFilterBy] === 'string' ? rowData[this.selFilterBy].toLowerCase() : typeof rowData[this.selFilterBy] === 'boolean' ? (rowData[this.selFilterBy] ? 'yes' : 'no') : rowData[this.selFilterBy].toString(); - // break; - // } - // return rowToFilter.includes(fltr); - // }; } loadPaymentsTable(payms: PaymentSent[]) {