From 6d2b2fd81e0423faf7cfa0ea20bf55d30dd5e586 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 21 Oct 2015 14:46:12 -0700 Subject: [PATCH] [Time Controller] Parse user-entered timestamps nasa/openmctweb#181. --- .../src/controllers/TimeRangeController.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/platform/commonUI/general/src/controllers/TimeRangeController.js b/platform/commonUI/general/src/controllers/TimeRangeController.js index 44db087a65..b5ff59ab1a 100644 --- a/platform/commonUI/general/src/controllers/TimeRangeController.js +++ b/platform/commonUI/general/src/controllers/TimeRangeController.js @@ -43,6 +43,15 @@ define( return moment.utc(ts).format(DATE_FORMAT); } + function parseTimestamp(text) { + var m = moment.utc(text, DATE_FORMAT); + if (m.isValid()) { + return m.valueOf(); + } else { + throw new Error("Could not parse " + text); + } + } + // From 0.0-1.0 to "0%"-"1%" function toPercent(p) { return (100 * p) + "%"; @@ -214,6 +223,22 @@ define( updateViewForInnerSpanFromModel(ngModel); } + function updateStartFromText(value) { + try { + updateOuterStart(parseTimestamp(value)); + } catch (e) { + return; + } + } + + function updateEndFromText(value) { + try { + updateOuterEnd(parseTimestamp(value)); + } catch (e) { + return; + } + } + $scope.startLeftDrag = startLeftDrag; $scope.startRightDrag = startRightDrag; $scope.startMiddleDrag = startMiddleDrag; @@ -232,6 +257,8 @@ define( $scope.$watch("spanWidth", updateSpanWidth); $scope.$watch("ngModel.outer.start", updateOuterStart); $scope.$watch("ngModel.outer.end", updateOuterEnd); + $scope.$watch("boundsModel.start", updateStartFromText); + $scope.$watch("boundsModel.end", updateEndFromText); } return TimeConductorController;