[Time Conductor] Begin using date-time controls

WTD-1515
This commit is contained in:
Victor Woeltjen 2015-09-15 10:00:41 -07:00
parent cd98886a43
commit d0b5bb2d21
4 changed files with 77 additions and 18 deletions

View File

@ -22,12 +22,8 @@
<div class="l-time-controller" ng-controller="TimeRangeController">
<div class="l-time-range-inputs-holder">
Start: <input type="textfield"
placeholder="YYYY-MM-DD HH:mm:ss"
ng-model="startOuterDate"/>
End: <input type="textfield"
placeholder="YYYY-MM-DD HH:mm:ss"
ng-model="endOuterDate"/>
Start: <input type="date" ng-model="startOuterDate"/>
End: <input type="date" ng-model="endOuterDate"/>
</div>
<div class="l-time-range-slider-holder">

View File

@ -40,11 +40,6 @@ define(
return moment.utc(ts).format(DATE_FORMAT);
}
function parseTimestamp(text, fallback) {
var m = moment.utc(text, DATE_FORMAT);
return m.isValid() ? m.valueOf() : fallback;
}
// From 0.0-1.0 to "0%"-"1%"
function toPercent(p) {
return (100 * p) + "%";
@ -103,8 +98,8 @@ define(
ngModel.inner = ngModel.inner || copyBounds(ngModel.outer);
// First, dates for the date pickers for outer bounds
$scope.startOuterDate = formatTimestamp(ngModel.outer.start);
$scope.endOuterDate = formatTimestamp(ngModel.outer.end);
$scope.startOuterDate = new Date(ngModel.outer.start);
$scope.endOuterDate = new Date(ngModel.outer.end);
// Then various updates for the inner span
updateViewForInnerSpanFromModel(ngModel);
@ -177,10 +172,10 @@ define(
updateViewFromModel($scope.ngModel);
}
function updateOuterStart(text) {
function updateOuterStart(date) {
var ngModel = $scope.ngModel;
ngModel.outer.start =
parseTimestamp(text, ngModel.outer.start);
date.getTime();
ngModel.outer.end =
Math.max(ngModel.outer.start, ngModel.outer.end);
ngModel.inner.start =
@ -190,10 +185,10 @@ define(
updateViewForInnerSpanFromModel(ngModel);
}
function updateOuterEnd(text) {
function updateOuterEnd(date) {
var ngModel = $scope.ngModel;
ngModel.outer.end =
parseTimestamp(text, ngModel.outer.end);
date.getTime();
ngModel.outer.start =
Math.min(ngModel.outer.end, ngModel.outer.start);
ngModel.inner.start =

View File

@ -0,0 +1,67 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/TimeRangeController"],
function (TimeRangeController) {
"use strict";
describe("The TimeRangeController", function () {
var mockScope,
mockNow,
controller;
function fireWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) {
if (call.args[0] === expr) {
call.args[1](value);
}
});
}
function fireWatchCollection(expr, value) {
mockScope.$watchCollection.calls.forEach(function (call) {
if (call.args[0] === expr) {
call.args[1](value);
}
});
}
beforeEach(function () {
mockScope = jasmine.createSpyObj(
"$scope",
[ "$apply", "$watch", "$watchCollection" ]
);
mockNow = jasmine.createSpy('now');
controller = new TimeRangeController(mockScope, mockNow);
});
it("watches the model that was passed in", function () {
expect(mockScope.$watchCollection)
.toHaveBeenCalledWith("ngModel", jasmine.any(Function));
});
});
}
);

View File

@ -6,6 +6,7 @@
"controllers/GetterSetterController",
"controllers/SelectorController",
"controllers/SplitPaneController",
"controllers/TimeRangeController",
"controllers/ToggleController",
"controllers/TreeNodeController",
"controllers/ViewSwitcherController",
@ -15,4 +16,4 @@
"directives/MCTScroll",
"services/UrlService",
"StyleSheetLoader"
]
]