From 1c670329dc6daff2914fb6a590fbd6a1d750580d Mon Sep 17 00:00:00 2001 From: AllForNothing Date: Wed, 13 May 2020 12:38:23 +0800 Subject: [PATCH] Fix duration and log bugs for replication task UI Signed-off-by: AllForNothing --- .../replication-tasks.component.html | 2 +- .../replication/replication.component.spec.ts | 34 +++++++++++++++++++ .../replication/replication.component.ts | 5 ++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/portal/src/lib/components/replication/replication-tasks/replication-tasks.component.html b/src/portal/src/lib/components/replication/replication-tasks/replication-tasks.component.html index 13ae0193b..8ee032bc5 100644 --- a/src/portal/src/lib/components/replication/replication-tasks/replication-tasks.component.html +++ b/src/portal/src/lib/components/replication/replication-tasks/replication-tasks.component.html @@ -112,7 +112,7 @@ {{t.start_time | date: 'short'}} {{t.end_time && t.end_time != '0001-01-01T00:00:00Z' ? (t.end_time | date: 'short') : "-"}} - + diff --git a/src/portal/src/lib/components/replication/replication.component.spec.ts b/src/portal/src/lib/components/replication/replication.component.spec.ts index 48f3b44a3..ac2e1a2bc 100644 --- a/src/portal/src/lib/components/replication/replication.component.spec.ts +++ b/src/portal/src/lib/components/replication/replication.component.spec.ts @@ -286,4 +286,38 @@ describe('Replication Component (inline template)', () => { expect(el.textContent.trim()).toEqual('library/nginx'); }); })); + + it('function "getDuration" should work', () => { + // ms level + const item: ReplicationJobItem = { + start_time: 1589340503637, + end_time: 1589340503638, + id: 3, + status: "stopped", + policy_id: 2, + trigger: "Manual", + total: 1, + failed: 1, + succeed: 0, + in_progress: 0, + stopped: 0 + }; + expect(comp.getDuration(item)).toEqual('1ms'); + // sec level + item.start_time = 1589340503637; + item.end_time = 1589340504638; + expect(comp.getDuration(item)).toEqual('1s'); + // min level + item.start_time = 1589340503637; + item.end_time = 1589340564638; + expect(comp.getDuration(item)).toEqual('1m1s'); + // hour level + item.start_time = 1589340503637; + item.end_time = 1589344164638; + expect(comp.getDuration(item)).toEqual('61m1s'); + // day level + item.start_time = "5/8/20,11:20 AM"; + item.end_time = "5/9/20,11:24 AM"; + expect(comp.getDuration(item)).toEqual('1444m'); + }); }); diff --git a/src/portal/src/lib/components/replication/replication.component.ts b/src/portal/src/lib/components/replication/replication.component.ts index ed03b5a10..43e61d4e0 100644 --- a/src/portal/src/lib/components/replication/replication.component.ts +++ b/src/portal/src/lib/components/replication/replication.component.ts @@ -499,9 +499,12 @@ export class ReplicationComponent implements OnInit, OnDestroy { let end_time = new Date(j.end_time).getTime(); let timesDiff = end_time - start_time; let timesDiffSeconds = timesDiff / 1000; - let minutes = Math.floor(((timesDiffSeconds % ONE_DAY_SECONDS) % ONE_HOUR_SECONDS) / ONE_MINUTE_SECONDS); + let minutes = Math.floor(timesDiffSeconds / ONE_MINUTE_SECONDS); let seconds = Math.floor(timesDiffSeconds % ONE_MINUTE_SECONDS); if (minutes > 0) { + if (seconds === 0) { + return minutes + "m"; + } return minutes + "m" + seconds + "s"; }