Skip to content

Commit

Permalink
refactor: move common components to RngModule
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed Jun 2, 2020
1 parent 1ac3d3a commit 58c8201
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
17 changes: 17 additions & 0 deletions src/app/components/rng.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NbIconModule } from '@nebular/theme';
import { ChartsModule } from 'ng2-charts';
import { TableModule } from 'ngx-easy-table';
import { RngSpeedChartComponent } from './speed-chart/speed-chart.component';
import { RngDiffComponent } from './speed-chart/speed-diff.component';
import { RngSummaryComponent } from './summary/summary.component';

const RngComponents = [RngSpeedChartComponent, RngDiffComponent, RngSummaryComponent];

@NgModule({
declarations: RngComponents,
imports: [CommonModule, TableModule, ChartsModule, NbIconModule],
exports: RngComponents,
})
export class RngModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { ChartDataSets, ChartOptions, ChartPoint } from 'chart.js';
import * as moment from 'moment';
import { BaseChartDirective, Color } from 'ng2-charts';
import { pairwise } from 'rxjs/operators';
import { CoreStatsFlow } from '../../../@dataflow/rclone';
import { FormatBytes } from '../../../utils/format-bytes';
import { CoreStatsFlow } from '../../@dataflow/rclone';
import { FormatBytes } from '../../utils/format-bytes';

@Component({
selector: 'app-jobs-speed-chart',
selector: 'app-rng-speed-chart',
template: `
<div class="chart-container">
<canvas
Expand All @@ -17,7 +17,7 @@ import { FormatBytes } from '../../../utils/format-bytes';
[colors]="lineChartColors"
chartType="line"
></canvas>
<app-jobs-speed-diff [val]="speedDiff"> </app-jobs-speed-diff>
<app-rng-diff [val]="speedDiff"> </app-rng-diff>
</div>
`,
styles: [
Expand All @@ -31,15 +31,15 @@ import { FormatBytes } from '../../../utils/format-bytes';
width: 100%;
height: 100%;
}
.chart-container jobs-speed-diff {
.chart-container app-rng-diff {
position: absolute;
right: 1rem;
top: 0.25rem;
}
`,
],
})
export class SpeedChartComponent implements OnInit {
export class RngSpeedChartComponent implements OnInit {
constructor() {}
public lineChartData: ChartDataSets[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, Input, OnInit } from '@angular/core';
import { FormatBytes } from '../../../utils/format-bytes';
import { FormatBytes } from '../../utils/format-bytes';

@Component({
selector: 'app-jobs-speed-diff',
selector: 'app-rng-diff',
template: `
<span> {{ (val < 0 ? '-' + FormatBytes(-val) : FormatBytes(val)) + '/s' }} </span>
<nb-icon
Expand All @@ -20,7 +20,7 @@ import { FormatBytes } from '../../../utils/format-bytes';
`,
],
})
export class SpeedDiffComponent implements OnInit {
export class RngDiffComponent implements OnInit {
@Input()
val = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { SummaryComponent } from './summary.component';
import { RngSummaryComponent } from './summary.component';

describe('SummaryComponent', () => {
let component: SummaryComponent;
let fixture: ComponentFixture<SummaryComponent>;
let component: RngSummaryComponent;
let fixture: ComponentFixture<RngSummaryComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SummaryComponent],
declarations: [RngSummaryComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(SummaryComponent);
fixture = TestBed.createComponent(RngSummaryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, Input, OnInit } from '@angular/core';
import { CoreStatsFlow, CoreStatsFlowOutItemNode } from '../../../@dataflow/rclone';
import { FormatBytes } from '../../../utils/format-bytes';
import { ForamtDuration } from '../../../utils/format-duration';
import { CoreStatsFlow, CoreStatsFlowOutItemNode } from '../../@dataflow/rclone';
import { FormatBytes } from '../../utils/format-bytes';
import { ForamtDuration } from '../../utils/format-duration';

@Component({
selector: 'app-jobs-summary',
selector: 'app-rng-summary',
template: `
<dl>
<ng-container *ngFor="let item of keys">
Expand All @@ -29,7 +29,7 @@ import { ForamtDuration } from '../../../utils/format-duration';
`,
],
})
export class SummaryComponent implements OnInit {
export class RngSummaryComponent implements OnInit {
@Input()
stats$: CoreStatsFlow;

Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { ConnectionService } from '../connection.service';
</button>
</nb-card-header>
<nb-card-body>
<app-jobs-speed-chart [stats$]="stats$"> </app-jobs-speed-chart>
<app-rng-speed-chart [stats$]="stats$"> </app-rng-speed-chart>
</nb-card-body>
</nb-card>
</nb-card-front>
Expand Down Expand Up @@ -61,7 +61,7 @@ import { ConnectionService } from '../connection.service';
<nb-card-body>
<nb-tabset fullWidth>
<nb-tab tabTitle="Summary">
<app-jobs-summary [stats$]="stats$"> </app-jobs-summary>
<app-rng-summary [stats$]="stats$"> </app-rng-summary>
</nb-tab>
<nb-tab tabTitle="Memory">
Memory stats
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NbTabsetModule,
} from '@nebular/theme';
import { ChartsModule } from 'ng2-charts';
import { JobsModule } from '../jobs/jobs.module';
import { RngModule } from '../../components/rng.module';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { DashboardComponent } from './dashboard.component';

Expand All @@ -23,7 +23,7 @@ import { DashboardComponent } from './dashboard.component';
NbIconModule,
ChartsModule,
NbListModule,
JobsModule,
RngModule,
NbTabsetModule,
],
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/jobs/jobs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import { ConnectionService } from '../connection.service';
<nb-card size="small">
<nb-card-header> Speed </nb-card-header>
<nb-card-body class="speed-body">
<app-jobs-speed-chart [stats$]="stats$"> </app-jobs-speed-chart>
<app-rng-speed-chart [stats$]="stats$"> </app-rng-speed-chart>
</nb-card-body>
</nb-card>
</div>
<div class="col-6">
<nb-card>
<nb-card-header> Summary </nb-card-header>
<nb-card-body>
<app-jobs-summary [stats$]="stats$"> </app-jobs-summary>
<app-rng-summary [stats$]="stats$"> </app-rng-summary>
</nb-card-body>
</nb-card>
</div>
Expand Down
14 changes: 3 additions & 11 deletions src/app/pages/jobs/jobs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@ import {
} from '@nebular/theme';
import { ChartsModule } from 'ng2-charts';
import { TableModule } from 'ngx-easy-table';
import { RngModule } from '../../components/rng.module';
import { JobsRoutingModule } from './jobs-routing.module';
import { JobsComponent } from './jobs.component';
import { SpeedChartComponent } from './speed-chart/speed-chart.component';
import { SpeedDiffComponent } from './speed-chart/speed-diff.component';
import { SummaryComponent } from './summary/summary.component';
import { TransfersComponent } from './transferring/transferring.component';

@NgModule({
declarations: [
JobsComponent,
SpeedChartComponent,
SummaryComponent,
TransfersComponent,
SpeedDiffComponent,
],
declarations: [JobsComponent, TransfersComponent],
imports: [
CommonModule,
JobsRoutingModule,
Expand All @@ -35,7 +27,7 @@ import { TransfersComponent } from './transferring/transferring.component';
NbListModule,
NbIconModule,
ChartsModule,
RngModule,
],
exports: [SpeedChartComponent, SummaryComponent],
})
export class JobsModule {}

0 comments on commit 58c8201

Please sign in to comment.