Skip to content

Commit

Permalink
feat(core-stats): basic framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 19, 2020
1 parent f2e4f61 commit 7cad448
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/@dataflow/rclone/core-stats-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CoreStatsFlowOutNode extends FlowOutNode {
retryError: boolean;
speed: number;
transfers: number;
transferring?: [];
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Component, OnInit } from '@angular/core';
<dashboard-speed-card> </dashboard-speed-card>
</div>
<div class="col-sm-12 col-md-6 col-xl-6">
<nb-card><nb-card-body>core/stats</nb-card-body></nb-card>
<dashboard-stats-card> </dashboard-stats-card>
</div>
<div class="col-sm-12 col-md-6 col-xl-4">
<nb-card><nb-card-body>core/memstats</nb-card-body></nb-card>
Expand Down
15 changes: 12 additions & 3 deletions src/app/pages/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ import { CommonModule } from '@angular/common';

import { DashboardRoutingModule } from './dashboard-routing.module';
import { DashboardComponent } from './dashboard.component';
import { NbCardModule, NbButtonModule, NbIconModule } from '@nebular/theme';
import { NbCardModule, NbButtonModule, NbIconModule, NbListModule } from '@nebular/theme';
import { SpeedCardComponent } from './speed-card/speed-card.component';
import { SpeedChartsComponent } from './speed-card/speed-charts.component';
import { ChartsModule } from 'ng2-charts';
import { StatsCardComponent } from './stats-card/stats-card.component';

@NgModule({
declarations: [DashboardComponent, SpeedCardComponent, SpeedChartsComponent],
imports: [CommonModule, DashboardRoutingModule, NbCardModule, NbButtonModule, NbIconModule, ChartsModule],
declarations: [DashboardComponent, SpeedCardComponent, SpeedChartsComponent, StatsCardComponent],
imports: [
CommonModule,
DashboardRoutingModule,
NbCardModule,
NbButtonModule,
NbIconModule,
ChartsModule,
NbListModule,
],
})
export class DashboardModule {}
88 changes: 88 additions & 0 deletions src/app/pages/dashboard/stats-card/stats-card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { CoreStatsService } from '../core-stats.service';
import { CombErr } from 'src/app/@dataflow/core';
import { CoreStatsFlowOutNode } from 'src/app/@dataflow/rclone';
import { Observable } from 'rxjs';
import { takeWhile } from 'rxjs/operators';

@Component({
selector: 'dashboard-stats-card',
template: `
<nb-card>
<nb-card-header> Core Status </nb-card-header>
<nb-card-body class="row">
<div class="col-4">
<nb-list>
<nb-list-item *ngFor="let N of itemName">
{{ N }}
</nb-list-item>
</nb-list>
</div>
<div class="col-8">
<nb-list>
<nb-list-item *ngFor="let val of itemValue">
{{ val }}
</nb-list-item>
</nb-list>
</div>
</nb-card-body>
</nb-card>
`,
styles: [
`
.row {
display: flex;
}
.column {
flex: 50%;
}
`,
],
})
export class StatsCardComponent implements OnInit, OnDestroy {
itemName = [
'Bytes',
'Speed',
'Transferring',
'Transfers',
'Checks',
'Delete',
'Elapsed Time',
'Errors',
'FatalError',
'RetryError',
];
itemValue: (string | number)[];

constructor(private statsService: CoreStatsService) {}

coreStats$: Observable<CombErr<CoreStatsFlowOutNode>>;

visable = false;
ngOnInit() {
this.visable = true;
this.itemValue = Array(this.itemName.length).map(() => '');
this.coreStats$ = this.statsService.coreStatsFlow$
.getOutput()
.pipe(takeWhile(() => this.visable));
this.coreStats$.subscribe((node) => {
if (node[1].length !== 0) return;
const data = node[0]['core-stats'];
this.itemValue[0] = data.bytes;
this.itemValue[1] = data.speed;
this.itemValue[2] = data.transferring ? data.transferring.length : 0;
this.itemValue[3] = data.transfers;
this.itemValue[4] = data.checks;
this.itemValue[5] = data.deletes;
this.itemValue[6] = data.elapsedTime;
this.itemValue[7] = data.errors;
this.itemValue[8] = data.fatalError ? 'true' : 'false';
this.itemValue[9] = data.retryError ? 'true' : 'false';
});
}

ngOnDestroy() {
this.visable = false;
}
}

0 comments on commit 7cad448

Please sign in to comment.