Skip to content

Commit

Permalink
fix(transferring): format eta
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 31, 2020
1 parent 1b227a9 commit e1dc691
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
21 changes: 3 additions & 18 deletions src/app/pages/jobs/summary/summary.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, Input } from '@angular/core';
import { CoreStatsFlow, CoreStatsFlowOutItemNode } from 'src/app/@dataflow/rclone';
import { FormatBytes } from 'src/app/utils/format-bytes';
import { HumanizeDurationLanguage, HumanizeDuration } from 'humanize-duration-ts';
import { ForamtDuration } from 'src/app/utils/format-duration';

@Component({
selector: 'jobs-summary',
Expand Down Expand Up @@ -51,22 +51,7 @@ export class SummaryComponent implements OnInit {
durationHumanReadable: string;
} = {} as any;

private langService: HumanizeDurationLanguage = new HumanizeDurationLanguage();
private Duration: HumanizeDuration;
constructor() {
this.langService.addLanguage('shortEn', {
y: () => 'y',
mo: () => 'mo',
w: () => 'w',
d: () => 'd',
h: () => 'h',
m: () => 'm',
s: () => 's',
ms: () => 'ms',
decimal: '',
});
this.Duration = new HumanizeDuration(this.langService);
}
constructor() {}
isDefine(val: any) {
return typeof val !== 'undefined';
}
Expand All @@ -77,7 +62,7 @@ export class SummaryComponent implements OnInit {
this.values = JSON.parse(JSON.stringify(x['core-stats']));
this.values.bytesHumanReadable = FormatBytes(this.values.bytes, 4);
this.values.speedHumanReadable = FormatBytes(this.values.speed, 4) + '/s';
this.values.durationHumanReadable = this.Duration.humanize(this.values.elapsedTime * 1000, {
this.values.durationHumanReadable = ForamtDuration.humanize(this.values.elapsedTime * 1000, {
language: 'shortEn',
round: true,
});
Expand Down
12 changes: 10 additions & 2 deletions src/app/pages/jobs/transferring/transferring.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit, Input } from '@angular/core';
import { Columns, Config, DefaultConfig } from 'ngx-easy-table';
import { CoreStatsFlow, ITransferring } from 'src/app/@dataflow/rclone';
import { FormatBytes } from 'src/app/utils/format-bytes';
import { ForamtDuration } from 'src/app/utils/format-duration';

@Component({
selector: 'jobs-transferring',
Expand All @@ -20,9 +21,13 @@ export class TransfersComponent implements OnInit {
{ key: 'sizeHumanReadable', title: 'Size' },
{ key: 'percentage', title: 'Percentage' },
{ key: 'speedHumanReadable', title: 'Speed' },
{ key: 'eta', title: 'eta' },
{ key: 'etaHumanReadable', title: 'eta' },
];
public data: (ITransferring & { sizeHumanReadable: string; speedHumanReadable: string })[] = [];
public data: (ITransferring & {
sizeHumanReadable: string;
speedHumanReadable: string;
etaHumanReadable: string;
})[] = [];

constructor() {}

Expand All @@ -34,6 +39,9 @@ export class TransfersComponent implements OnInit {
this.data.forEach((x) => {
x.sizeHumanReadable = FormatBytes(x.size, 3);
x.speedHumanReadable = FormatBytes(x.speed) + '/s';
if (typeof x.eta === 'number')
x.etaHumanReadable = ForamtDuration.humanize(x.eta * 1000, { largest: 3 });
else x.etaHumanReadable = '-';
});
});

Expand Down
16 changes: 16 additions & 0 deletions src/app/utils/format-duration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HumanizeDurationLanguage, HumanizeDuration } from 'humanize-duration-ts';

const langService = new HumanizeDurationLanguage();
langService.addLanguage('shortEn', {
y: () => 'y',
mo: () => 'mo',
w: () => 'w',
d: () => 'd',
h: () => 'h',
m: () => 'm',
s: () => 's',
ms: () => 'ms',
decimal: '',
});
export const ForamtDuration = new HumanizeDuration(langService);
ForamtDuration.setOptions({ language: 'shortEn', round: true });

0 comments on commit e1dc691

Please sign in to comment.