Merge pull request #2168 from mempool/nymkappa/feature/node-channels-list-count

[Node page] Update channels count when switching between open/closed
This commit is contained in:
wiz 2022-07-24 16:26:39 +02:00 committed by GitHub
commit 8316c37a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View File

@ -9,7 +9,10 @@ class NodesApi {
geo_names_country.names as country, geo_names_subdivision.names as subdivision, geo_names_country.names as country, geo_names_subdivision.names as subdivision,
(SELECT Count(*) (SELECT Count(*)
FROM channels FROM channels
WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_count, WHERE channels.status = 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_closed_count,
(SELECT Count(*)
FROM channels
WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_active_count,
(SELECT Sum(capacity) (SELECT Sum(capacity)
FROM channels FROM channels
WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS capacity, WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS capacity,
@ -23,7 +26,7 @@ class NodesApi {
LEFT JOIN geo_names geo_names_country on geo_names_country.id = country_id LEFT JOIN geo_names geo_names_country on geo_names_country.id = country_id
WHERE public_key = ? WHERE public_key = ?
`; `;
const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key]); const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key, public_key, public_key]);
if (rows.length > 0) { if (rows.length > 0) {
rows[0].as_organization = JSON.parse(rows[0].as_organization); rows[0].as_organization = JSON.parse(rows[0].as_organization);
rows[0].subdivision = JSON.parse(rows[0].subdivision); rows[0].subdivision = JSON.parse(rows[0].subdivision);

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup } from '@angular/forms';
import { BehaviorSubject, combineLatest, merge, Observable, of } from 'rxjs'; import { BehaviorSubject, combineLatest, merge, Observable, of } from 'rxjs';
import { map, startWith, switchMap } from 'rxjs/operators'; import { map, startWith, switchMap } from 'rxjs/operators';
@ -12,6 +12,7 @@ import { LightningApiService } from '../lightning-api.service';
}) })
export class ChannelsListComponent implements OnInit, OnChanges { export class ChannelsListComponent implements OnInit, OnChanges {
@Input() publicKey: string; @Input() publicKey: string;
@Output() channelsStatusChangedEvent = new EventEmitter<string>();
channels$: Observable<any>; channels$: Observable<any>;
// @ts-ignore // @ts-ignore
@ -41,13 +42,17 @@ export class ChannelsListComponent implements OnInit, OnChanges {
ngOnChanges(): void { ngOnChanges(): void {
this.channelStatusForm.get('status').setValue(this.defaultStatus, { emitEvent: false }) this.channelStatusForm.get('status').setValue(this.defaultStatus, { emitEvent: false })
this.channelsStatusChangedEvent.emit(this.defaultStatus);
this.channels$ = combineLatest([ this.channels$ = combineLatest([
this.channelsPage$, this.channelsPage$,
this.channelStatusForm.get('status').valueChanges.pipe(startWith(this.defaultStatus)) this.channelStatusForm.get('status').valueChanges.pipe(startWith(this.defaultStatus))
]) ])
.pipe( .pipe(
switchMap(([page, status]) =>this.lightningApiService.getChannelsByNodeId$(this.publicKey, (page -1) * this.itemsPerPage, status)), switchMap(([page, status]) => {
this.channelsStatusChangedEvent.emit(status);
return this.lightningApiService.getChannelsByNodeId$(this.publicKey, (page -1) * this.itemsPerPage, status);
}),
map((response) => { map((response) => {
return { return {
channels: response.body, channels: response.body,

View File

@ -24,7 +24,7 @@
<tr> <tr>
<td i18n="address.total-sent">Total channels</td> <td i18n="address.total-sent">Total channels</td>
<td> <td>
{{ node.channel_count }} {{ node.channel_active_count }}
</td> </td>
</tr> </tr>
<tr> <tr>
@ -108,7 +108,7 @@
<br> <br>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<h2>Channels ({{ node.channel_count }})</h2> <h2>Channels ({{ channelsListStatus === 'open' ? node.channel_active_count : node.channel_closed_count }})</h2>
<div class="d-flex align-items-center justify-content-end"> <div class="d-flex align-items-center justify-content-end">
<span style="margin-bottom: 0.5rem">List</span>&nbsp; <span style="margin-bottom: 0.5rem">List</span>&nbsp;
<label class="switch"> <label class="switch">
@ -120,7 +120,8 @@
</div> </div>
<app-nodes-channels-map *ngIf="channelsListMode === 'map'" [style]="'nodepage'" [publicKey]="node.public_key"></app-nodes-channels-map> <app-nodes-channels-map *ngIf="channelsListMode === 'map'" [style]="'nodepage'" [publicKey]="node.public_key"></app-nodes-channels-map>
<app-channels-list *ngIf="channelsListMode === 'list'" [publicKey]="node.public_key"></app-channels-list> <app-channels-list *ngIf="channelsListMode === 'list'" [publicKey]="node.public_key"
(channelsStatusChangedEvent)="onChannelsListStatusChanged($event)"></app-channels-list>
</div> </div>

View File

@ -18,6 +18,7 @@ export class NodeComponent implements OnInit {
selectedSocketIndex = 0; selectedSocketIndex = 0;
qrCodeVisible = false; qrCodeVisible = false;
channelsListMode = 'list'; channelsListMode = 'list';
channelsListStatus: string;
constructor( constructor(
private lightningApiService: LightningApiService, private lightningApiService: LightningApiService,
@ -69,4 +70,8 @@ export class NodeComponent implements OnInit {
this.channelsListMode = 'list'; this.channelsListMode = 'list';
} }
} }
onChannelsListStatusChanged(e) {
this.channelsListStatus = e;
}
} }