mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 09:26:45 +00:00
[Time Conductor] Use dateService from TimeRangeController
This commit is contained in:
parent
0d47b7c47d
commit
117470068a
@ -66,7 +66,7 @@
|
||||
{
|
||||
"key": "TimeRangeController",
|
||||
"implementation": "controllers/TimeRangeController.js",
|
||||
"depends": [ "$scope", "now" ]
|
||||
"depends": [ "$scope", "dateService", "now" ]
|
||||
},
|
||||
{
|
||||
"key": "DateTimePickerController",
|
||||
|
@ -30,23 +30,28 @@ define(
|
||||
TICK_SPACING_PX = 150;
|
||||
|
||||
/**
|
||||
* Controller used by the `time-controller` template.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function TimeConductorController($scope, now) {
|
||||
function TimeRangeController($scope, dateService, now) {
|
||||
var tickCount = 2,
|
||||
innerMinimumSpan = 1000, // 1 second
|
||||
outerMinimumSpan = 1000 * 60 * 60, // 1 hour
|
||||
initialDragValue;
|
||||
|
||||
function timeSystemKey() {
|
||||
return ($scope.parameters || {}).domain;
|
||||
}
|
||||
|
||||
function formatTimestamp(ts) {
|
||||
return moment.utc(ts).format(DATE_FORMAT);
|
||||
return dateService.format(ts, timeSystemKey());
|
||||
}
|
||||
|
||||
function parseTimestamp(text) {
|
||||
var m = moment.utc(text, DATE_FORMAT);
|
||||
if (m.isValid()) {
|
||||
return m.valueOf();
|
||||
var key = timeSystemKey();
|
||||
if (dateService.validate(text, key)) {
|
||||
return dateService.parse(text, key);
|
||||
} else {
|
||||
throw new Error("Could not parse " + text);
|
||||
}
|
||||
@ -297,6 +302,6 @@ define(
|
||||
$scope.$watch("boundsModel.end", updateEndFromText);
|
||||
}
|
||||
|
||||
return TimeConductorController;
|
||||
return TimeRangeController;
|
||||
}
|
||||
);
|
||||
|
@ -33,6 +33,7 @@ define(
|
||||
|
||||
describe("The TimeRangeController", function () {
|
||||
var mockScope,
|
||||
mockDateService,
|
||||
mockNow,
|
||||
controller;
|
||||
|
||||
@ -57,8 +58,26 @@ define(
|
||||
"$scope",
|
||||
[ "$apply", "$watch", "$watchCollection" ]
|
||||
);
|
||||
mockDateService = jasmine.createSpyObj(
|
||||
"dateService",
|
||||
[ "validate", "format", "parse" ]
|
||||
);
|
||||
mockDateService.validate.andCallFake(function (text) {
|
||||
return moment.utc(text).isValid();
|
||||
});
|
||||
mockDateService.parse.andCallFake(function (text) {
|
||||
return moment.utc(text).valueOf();
|
||||
});
|
||||
mockDateService.format.andCallFake(function (value) {
|
||||
return moment.utc(value).format("YYYY-MM-DD HH:mm:ss");
|
||||
});
|
||||
mockNow = jasmine.createSpy('now');
|
||||
controller = new TimeRangeController(mockScope, mockNow);
|
||||
|
||||
controller = new TimeRangeController(
|
||||
mockScope,
|
||||
mockDateService,
|
||||
mockNow
|
||||
);
|
||||
});
|
||||
|
||||
it("watches the model that was passed in", function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user