Fix duration and log bugs for replication task UI

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
AllForNothing 2020-05-13 12:38:23 +08:00
parent 6f04b59aa5
commit 1c670329dc
3 changed files with 39 additions and 2 deletions

View File

@ -112,7 +112,7 @@
<clr-dg-cell>{{t.start_time | date: 'short'}}</clr-dg-cell>
<clr-dg-cell>{{t.end_time && t.end_time != '0001-01-01T00:00:00Z' ? (t.end_time | date: 'short') : "-"}}</clr-dg-cell>
<clr-dg-cell>
<a target="_blank" [href]="viewLog(t.id)">
<a target="_blank" [href]="viewLog(t.id)" *ngIf="t.status !== 'Initialized'">
<clr-icon shape="list"></clr-icon>
</a>
</clr-dg-cell>

View File

@ -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');
});
});

View File

@ -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";
}