mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 14:48:13 +00:00
[Time API] Fixed static code analysis issues
This commit is contained in:
@ -19,6 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
/* global console*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
@ -107,7 +108,7 @@ define(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Construct the provided time system definitions
|
// Construct the provided time system definitions
|
||||||
this.timeSystems = config.menuOptions.map(function (menuOption){
|
this.timeSystems = config.menuOptions.map(function (menuOption) {
|
||||||
return this.getTimeSystem(menuOption.timeSystem);
|
return this.getTimeSystem(menuOption.timeSystem);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
@ -175,7 +176,7 @@ define(
|
|||||||
* @param newOption
|
* @param newOption
|
||||||
* @param oldOption
|
* @param oldOption
|
||||||
*/
|
*/
|
||||||
TimeConductorController.prototype.selectMenuOption = function (newOption, oldOption){
|
TimeConductorController.prototype.selectMenuOption = function (newOption, oldOption) {
|
||||||
if (newOption !== oldOption) {
|
if (newOption !== oldOption) {
|
||||||
var config = this.getConfig(this.timeAPI.timeSystem(), newOption.clock);
|
var config = this.getConfig(this.timeAPI.timeSystem(), newOption.clock);
|
||||||
|
|
||||||
@ -235,7 +236,7 @@ define(
|
|||||||
timeSystemsForClocks[clockKey] = timeSystemsForClocks[clockKey] || [];
|
timeSystemsForClocks[clockKey] = timeSystemsForClocks[clockKey] || [];
|
||||||
timeSystemsForClocks[clockKey].push(timeSystem);
|
timeSystemsForClocks[clockKey].push(timeSystem);
|
||||||
} else if (menuOption.clock !== undefined) {
|
} else if (menuOption.clock !== undefined) {
|
||||||
console.log('Unknown clock "' + clockKey + '", has it been registered?');
|
console.error('Unknown clock "' + clockKey + '", has it been registered?');
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
@ -378,26 +379,24 @@ define(
|
|||||||
this.menu.selected = menuOption;
|
this.menu.selected = menuOption;
|
||||||
|
|
||||||
//Try to find currently selected time system in time systems for clock
|
//Try to find currently selected time system in time systems for clock
|
||||||
var selectedTimeSystem = timeSystems.filter(function (timeSystem){
|
var selectedTimeSystem = timeSystems.filter(function (timeSystem) {
|
||||||
return timeSystem.key === this.$scope.timeSystemModel.selected.key;
|
return timeSystem.key === this.$scope.timeSystemModel.selected.key;
|
||||||
}.bind(this))[0];
|
}.bind(this))[0];
|
||||||
|
|
||||||
var config = this.getConfig(selectedTimeSystem, clock);
|
var config = this.getConfig(selectedTimeSystem, clock);
|
||||||
|
|
||||||
if (selectedTimeSystem === undefined){
|
if (selectedTimeSystem === undefined) {
|
||||||
selectedTimeSystem = timeSystems[0];
|
selectedTimeSystem = timeSystems[0];
|
||||||
config = this.getConfig(selectedTimeSystem, clock);
|
config = this.getConfig(selectedTimeSystem, clock);
|
||||||
|
|
||||||
if (clock === undefined) {
|
if (clock === undefined) {
|
||||||
var bounds = config.bounds;
|
this.timeAPI.timeSystem(selectedTimeSystem, config.bounds);
|
||||||
this.timeAPI.timeSystem(selectedTimeSystem, bounds);
|
|
||||||
} else {
|
} else {
|
||||||
//When time system changes, some start bounds need to be provided
|
//When time system changes, some start bounds need to be provided
|
||||||
var bounds = {
|
this.timeAPI.timeSystem(selectedTimeSystem, {
|
||||||
start: clock.currentValue() + config.clockOffsets.start,
|
start: clock.currentValue() + config.clockOffsets.start,
|
||||||
end: clock.currentValue() + config.clockOffsets.end
|
end: clock.currentValue() + config.clockOffsets.end
|
||||||
};
|
});
|
||||||
this.timeAPI.timeSystem(selectedTimeSystem, bounds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,9 @@ define([
|
|||||||
TelemetryAPI.prototype.addFormat = function (format) {
|
TelemetryAPI.prototype.addFormat = function (format) {
|
||||||
this.MCT.legacyExtension('formats', {
|
this.MCT.legacyExtension('formats', {
|
||||||
key: format.key,
|
key: format.key,
|
||||||
implementation: function () { return format }
|
implementation: function () {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -267,20 +267,20 @@ define(['EventEmitter'], function (EventEmitter) {
|
|||||||
throw "Please provide a time system";
|
throw "Please provide a time system";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof timeSystemOrKey === 'string'){
|
if (typeof timeSystemOrKey === 'string') {
|
||||||
timeSystem = this.timeSystems.get(timeSystemOrKey);
|
timeSystem = this.timeSystems.get(timeSystemOrKey);
|
||||||
|
|
||||||
if (timeSystem === undefined){
|
if (timeSystem === undefined) {
|
||||||
throw "Unknown time system " + timeSystemOrKey + ". Has it been registered with 'addTimeSystem'?";
|
throw "Unknown time system " + timeSystemOrKey + ". Has it been registered with 'addTimeSystem'?";
|
||||||
}
|
}
|
||||||
} else if (typeof timeSystemOrKey === 'object'){
|
} else if (typeof timeSystemOrKey === 'object') {
|
||||||
timeSystem = timeSystemOrKey;
|
timeSystem = timeSystemOrKey;
|
||||||
|
|
||||||
if (!this.timeSystems.has(timeSystem.key)){
|
if (!this.timeSystems.has(timeSystem.key)) {
|
||||||
throw "Unknown time system " + timeSystem.key + ". Has it been registered with 'addTimeSystem'?";
|
throw "Unknown time system " + timeSystem.key + ". Has it been registered with 'addTimeSystem'?";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw "Attempt to set invalid time system in Time API. Please provide a previously registered time system object or key"
|
throw "Attempt to set invalid time system in Time API. Please provide a previously registered time system object or key";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.system = timeSystem;
|
this.system = timeSystem;
|
||||||
@ -353,7 +353,7 @@ define(['EventEmitter'], function (EventEmitter) {
|
|||||||
}
|
}
|
||||||
} else if (typeof keyOrClock === 'object') {
|
} else if (typeof keyOrClock === 'object') {
|
||||||
clock = keyOrClock;
|
clock = keyOrClock;
|
||||||
if (!clocks.has(clock.key)){
|
if (!this.clocks.has(clock.key)) {
|
||||||
throw "Unknown clock '" + keyOrClock.key + "'. Has it been registered with 'addClock'?";
|
throw "Unknown clock '" + keyOrClock.key + "'. Has it been registered with 'addClock'?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,8 +379,8 @@ define(['EventEmitter'], function (EventEmitter) {
|
|||||||
*/
|
*/
|
||||||
this.emit("clock", this.activeClock);
|
this.emit("clock", this.activeClock);
|
||||||
|
|
||||||
} else if (arguments.length === 1){
|
} else if (arguments.length === 1) {
|
||||||
throw "When setting the clock, clock offsets must also be provided"
|
throw "When setting the clock, clock offsets must also be provided";
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.activeClock;
|
return this.activeClock;
|
||||||
|
@ -68,7 +68,7 @@ define(['./TimeAPI'], function (TimeAPI) {
|
|||||||
it("Allows setting of previously registered time system with bounds", function () {
|
it("Allows setting of previously registered time system with bounds", function () {
|
||||||
api.addTimeSystem(timeSystem);
|
api.addTimeSystem(timeSystem);
|
||||||
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
||||||
expect(function() {
|
expect(function () {
|
||||||
api.timeSystem(timeSystemKey, bounds);
|
api.timeSystem(timeSystemKey, bounds);
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
expect(api.timeSystem()).toBe(timeSystemKey);
|
expect(api.timeSystem()).toBe(timeSystemKey);
|
||||||
@ -78,7 +78,7 @@ define(['./TimeAPI'], function (TimeAPI) {
|
|||||||
api.addTimeSystem(timeSystem);
|
api.addTimeSystem(timeSystem);
|
||||||
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
||||||
expect(function () {
|
expect(function () {
|
||||||
api.timeSystem(timeSystemKey)
|
api.timeSystem(timeSystemKey);
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
||||||
});
|
});
|
||||||
@ -130,7 +130,7 @@ define(['./TimeAPI'], function (TimeAPI) {
|
|||||||
"off",
|
"off",
|
||||||
"currentValue"
|
"currentValue"
|
||||||
]);
|
]);
|
||||||
mockTickSource.key = 'mockTickSource'
|
mockTickSource.key = 'mockTickSource';
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(" when enabling a tick source", function () {
|
describe(" when enabling a tick source", function () {
|
||||||
@ -139,7 +139,7 @@ define(['./TimeAPI'], function (TimeAPI) {
|
|||||||
var mockOffsets = {
|
var mockOffsets = {
|
||||||
start: 0,
|
start: 0,
|
||||||
end: 0
|
end: 0
|
||||||
}
|
};
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockTickSource = jasmine.createSpyObj("clock", [
|
mockTickSource = jasmine.createSpyObj("clock", [
|
||||||
@ -205,7 +205,7 @@ define(['./TimeAPI'], function (TimeAPI) {
|
|||||||
|
|
||||||
api.on("bounds", boundsCallback);
|
api.on("bounds", boundsCallback);
|
||||||
|
|
||||||
tickCallback = mockTickSource.on.mostRecentCall.args[1]
|
tickCallback = mockTickSource.on.mostRecentCall.args[1];
|
||||||
tickCallback(1000);
|
tickCallback(1000);
|
||||||
expect(boundsCallback).toHaveBeenCalledWith({
|
expect(boundsCallback).toHaveBeenCalledWith({
|
||||||
start: 900,
|
start: 900,
|
||||||
|
@ -27,7 +27,7 @@ define(['../../../src/plugins/utcTimeSystem/LocalClock'], function (LocalClock)
|
|||||||
* It DOES NOT tick on receipt of data.
|
* It DOES NOT tick on receipt of data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function LADClock (period) {
|
function LADClock(period) {
|
||||||
LocalClock.call(this, period);
|
LocalClock.call(this, period);
|
||||||
|
|
||||||
this.key = 'test-lad';
|
this.key = 'test-lad';
|
||||||
|
@ -28,6 +28,6 @@ define([
|
|||||||
return function () {
|
return function () {
|
||||||
return function (openmct) {
|
return function (openmct) {
|
||||||
openmct.time.addClock(new LADClock());
|
openmct.time.addClock(new LADClock());
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -56,8 +56,8 @@ define([
|
|||||||
* the threshold required.
|
* the threshold required.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function getScaledFormat (d) {
|
function getScaledFormat(d) {
|
||||||
var m = moment.utc(d);
|
var momentified = moment.utc(d);
|
||||||
/**
|
/**
|
||||||
* Uses logic from d3 Time-Scales, v3 of the API. See
|
* Uses logic from d3 Time-Scales, v3 of the API. See
|
||||||
* https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md
|
* https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md
|
||||||
@ -65,23 +65,35 @@ define([
|
|||||||
* Licensed
|
* Licensed
|
||||||
*/
|
*/
|
||||||
return [
|
return [
|
||||||
[".SSS", function(m) { return m.milliseconds(); }],
|
[".SSS", function (m) {
|
||||||
[":ss", function(m) { return m.seconds(); }],
|
return m.milliseconds();
|
||||||
["hh:mma", function(m) { return m.minutes(); }],
|
|
||||||
["hha", function(m) { return m.hours(); }],
|
|
||||||
["ddd DD", function(m) {
|
|
||||||
return m.days() &&
|
|
||||||
m.date() != 1;
|
|
||||||
}],
|
}],
|
||||||
["MMM DD", function(m) { return m.date() != 1; }],
|
[":ss", function (m) {
|
||||||
["MMMM", function(m) {
|
return m.seconds();
|
||||||
|
}],
|
||||||
|
["hh:mma", function (m) {
|
||||||
|
return m.minutes();
|
||||||
|
}],
|
||||||
|
["hha", function (m) {
|
||||||
|
return m.hours();
|
||||||
|
}],
|
||||||
|
["ddd DD", function (m) {
|
||||||
|
return m.days() &&
|
||||||
|
m.date() !== 1;
|
||||||
|
}],
|
||||||
|
["MMM DD", function (m) {
|
||||||
|
return m.date() !== 1;
|
||||||
|
}],
|
||||||
|
["MMMM", function (m) {
|
||||||
return m.month();
|
return m.month();
|
||||||
}],
|
}],
|
||||||
["YYYY", function() { return true; }]
|
["YYYY", function () {
|
||||||
].filter(function (row){
|
return true;
|
||||||
return row[1](m);
|
}]
|
||||||
|
].filter(function (row) {
|
||||||
|
return row[1](momentified);
|
||||||
})[0][0];
|
})[0][0];
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -91,7 +103,7 @@ define([
|
|||||||
* @returns {string} the formatted date
|
* @returns {string} the formatted date
|
||||||
*/
|
*/
|
||||||
LocalTimeFormat.prototype.format = function (value, scale) {
|
LocalTimeFormat.prototype.format = function (value, scale) {
|
||||||
if (scale !== undefined){
|
if (scale !== undefined) {
|
||||||
var scaledFormat = getScaledFormat(value, scale);
|
var scaledFormat = getScaledFormat(value, scale);
|
||||||
if (scaledFormat) {
|
if (scaledFormat) {
|
||||||
return moment.utc(value).format(scaledFormat);
|
return moment.utc(value).format(scaledFormat);
|
||||||
|
@ -27,7 +27,7 @@ define([], function () {
|
|||||||
* @implements TimeSystem
|
* @implements TimeSystem
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function LocalTimeSystem () {
|
function LocalTimeSystem() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some metadata, which will be used to identify the time system in
|
* Some metadata, which will be used to identify the time system in
|
||||||
|
@ -35,6 +35,6 @@ define([
|
|||||||
key: 'local-format',
|
key: 'local-format',
|
||||||
implementation: LocalTimeFormat
|
implementation: LocalTimeFormat
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -81,13 +81,13 @@ define([], function () {
|
|||||||
bounds = {
|
bounds = {
|
||||||
start: clock.currentValue() + clockOffsets.start,
|
start: clock.currentValue() + clockOffsets.start,
|
||||||
end: clock.currentValue() + clockOffsets.end
|
end: clock.currentValue() + clockOffsets.end
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
openmct.time.timeSystem(timeSystem, bounds);
|
openmct.time.timeSystem(timeSystem, bounds);
|
||||||
} else {
|
} else {
|
||||||
throw 'Invalid time conductor configuration. Please define defaults for time system "' + timeSystem.key + '"';
|
throw 'Invalid time conductor configuration. Please define defaults for time system "' + timeSystem.key + '"';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,7 @@ define([
|
|||||||
* @memberof platform/commonUI/formats
|
* @memberof platform/commonUI/formats
|
||||||
*/
|
*/
|
||||||
function DurationFormat() {
|
function DurationFormat() {
|
||||||
this.key = "duration"
|
this.key = "duration";
|
||||||
}
|
}
|
||||||
|
|
||||||
DurationFormat.prototype.format = function (value) {
|
DurationFormat.prototype.format = function (value) {
|
||||||
|
@ -129,4 +129,4 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
return UTCTimeFormat;
|
return UTCTimeFormat;
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ define([
|
|||||||
"./UTCTimeSystem",
|
"./UTCTimeSystem",
|
||||||
"./LocalClock",
|
"./LocalClock",
|
||||||
"./UTCTimeFormat",
|
"./UTCTimeFormat",
|
||||||
"./DurationFormat",
|
"./DurationFormat"
|
||||||
], function (
|
], function (
|
||||||
UTCTimeSystem,
|
UTCTimeSystem,
|
||||||
LocalClock,
|
LocalClock,
|
||||||
@ -47,6 +47,6 @@ define([
|
|||||||
"key": "DEFAULT_TIME_FORMAT",
|
"key": "DEFAULT_TIME_FORMAT",
|
||||||
"value": "utc"
|
"value": "utc"
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user