From 609062f1855cef71bcdc9bdd9399cf401db20224 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 1 Apr 2019 14:58:03 +0300 Subject: Display Human-readable timeout in Manual Task popup Issue-ID: VID-403 Change-Id: Iac5d7eb4ab92d967151fcf9ef439dd038f903c08 Signed-off-by: Ittay Stern --- .../change-management-manual-tasks.controller.js | 31 ++++++++++++++++++++-- ...ange-management-manual-tasks.controller.test.js | 22 +++++++++++++++ .../change-management-manual-tasks.html | 2 +- 3 files changed, 52 insertions(+), 3 deletions(-) (limited to 'vid-app-common/src') diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js index c4f8f14a9..38096a581 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js @@ -22,9 +22,9 @@ 'use strict'; appDS2.controller("changeManagementManualTasksController", ["$uibModalInstance", "jobInfo", "MsoService", "COMPONENT", - "$log", changeManagementManualTasksController]); + "$log", "moment", changeManagementManualTasksController]); - function changeManagementManualTasksController($uibModalInstance, jobInfo, MsoService, COMPONENT, $log) { + function changeManagementManualTasksController($uibModalInstance, jobInfo, MsoService, COMPONENT, $log, moment) { var vm = this; vm.manualTasks = []; @@ -75,6 +75,33 @@ return vm.manualTasks.includes(task); }; + vm.timeoutHumanized = function() { + // moment.duration() can parse ISO 8601 time-intervals, + // e.g. "P1Y2M10DT2H30M" + // https://en.wikipedia.org/wiki/ISO_8601#Time_intervals + let duration = moment.duration(vm.timeout); + + return isDurationValid() + ? durationAsHoursAndMinutes() + ' hours (' + vm.timeout + ')' + : vm.timeout; + + + function isDurationValid() { + return duration.isValid() && duration.toISOString() !== 'P0D'; + } + + function durationAsHoursAndMinutes() { + return '' + + Math.floor(duration.asHours()) + + ':' + + withLeadingZero(duration.minutes()); + } + + function withLeadingZero(x) { + return ("00" + Math.round(x)).slice(-2); + } + }; + vm.__test_only__ = { loadAvailableTasks: loadAvailableTasks, }; diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js index 93bc1c2de..deefca7e1 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js @@ -20,6 +20,7 @@ require('./change-management-manual-tasks.controller'); const jestMock = require('jest-mock'); +const moment = require('moment'); describe('changeManagementManualTasksController testing', () => { let $controller; @@ -41,6 +42,7 @@ describe('changeManagementManualTasksController testing', () => { "MsoService": $MsoService, "$uibModalInstance": $uibModalInstance, "$log": $log, + "moment": moment, "jobInfo": { requestState: job.requestStatus.requestState, details: job.requestStatus.statusMessage, @@ -141,6 +143,26 @@ describe('changeManagementManualTasksController testing', () => { }); }); + test('should humanize timeout if proper ISO-8601', () => { + $controller.timeout = 'PT3350S'; + expect($controller.timeoutHumanized()).toEqual('0:55 hours (PT3350S)'); + }); + + test('should humanize timeout if proper ISO-8601', () => { + $controller.timeout = 'P3DT1H1M'; + expect($controller.timeoutHumanized()).toEqual('73:01 hours (P3DT1H1M)'); + }); + + test('should drive-through timeout if not proper ISO-8601', () => { + $controller.timeout = '56 minutes'; + expect($controller.timeoutHumanized()).toEqual('56 minutes'); + }); + + test('should drive-through timeout if undefined', () => { + $controller.timeout = undefined; + expect($controller.timeoutHumanized()).toEqual(undefined); + }); + test('should find manual task using isTaskAvailable', () => { expect($controller.isTaskAvailable('abort')).toBeTruthy(); expect($controller.isTaskAvailable('resume')).toBeTruthy(); diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html index 099a6ad7b..031146e91 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html @@ -20,7 +20,7 @@