Display Human-readable timeout in Manual Task popup 66/83966/1
authorIttay Stern <ittay.stern@att.com>
Mon, 1 Apr 2019 11:58:03 +0000 (14:58 +0300)
committerIttay Stern <ittay.stern@att.com>
Tue, 2 Apr 2019 12:31:27 +0000 (15:31 +0300)
Issue-ID: VID-403

Change-Id: Iac5d7eb4ab92d967151fcf9ef439dd038f903c08
Signed-off-by: Ittay Stern <ittay.stern@att.com>
vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js
vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js
vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html
vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/mso_get_manual_task.json

index c4f8f14..38096a5 100644 (file)
@@ -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 = [];
             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,
         };
index 93bc1c2..deefca7 100644 (file)
@@ -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();
index 099a6ad..031146e 100644 (file)
@@ -20,7 +20,7 @@
 
 <div class="modal-body">
     <span id="in-progress-modal-description" ng-if="vm.description">{{vm.description}}</span>
-    <span id="in-progress-modal-timeout" ng-if="vm.timeout">({{vm.timeout}})</span>
+  <span id="in-progress-modal-timeout" ng-if="vm.timeout" class="text-danger"><strong>(task will time out in {{vm.timeoutHumanized()}})</strong></span>
 </div>
 
 <div class="modal-footer">
index 7fab6c6..9c4481e 100644 (file)
@@ -21,7 +21,7 @@
           "errorCode": "404",
           "errorMessage": "Failed in A&AI 404",
           "description": "Manually restart VM id vm8776da8-4c8cbe860422, then verify logs still contain task id daf4dd84-b77a-42da-a051-3239b7a9392c",
-          "timeout": "PT3000S",
+          "timeout": "P3DT1H1M",
           "validResponses": [
             "rollback",
             "abort",