aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-04-01 14:58:03 +0300
committerIttay Stern <ittay.stern@att.com>2019-04-02 15:31:27 +0300
commit609062f1855cef71bcdc9bdd9399cf401db20224 (patch)
tree256aa842dd90b2fd0a08ae301d0a3d8dbf852769 /vid-app-common
parent56d27d6651babd9223ee8e3a3deddda9d702dcd1 (diff)
Display Human-readable timeout in Manual Task popup
Issue-ID: VID-403 Change-Id: Iac5d7eb4ab92d967151fcf9ef439dd038f903c08 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common')
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js31
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js22
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html2
3 files changed, 52 insertions, 3 deletions
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 @@
<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">