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