Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 123 additions & 69 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,84 +198,138 @@
*
* key property is required and other options are optional
* timeSystem:
* * key: string, required
* * key: string, required. Time system. Options are 'scet', 'ert', 'sclk', 'msl.sol' and 'lmst'.
* * limit: number, optional - maximum duration between start and end bounds allow
* * presets: array, optional - preset bounds for convenience
* * * preset:
* * * * label: string, descriptive label for preset
* * modeSettings: object, optional - presets for convenience.
* * * fixed: object, optional - valid objects are bounds objects and presets array.
* * * realtime: object, optional - valid objects are clockOffsets and presets array.
* * * lad:object, optional - valid objects are clockoffsets.
* * * *
* * * * Optional objects:
* * * * bounds: start and end bounds for preset as numbers
* * * * * * * * start and end can be declared as a number or a function returning a number
*
* * * * * * * * start: and end: can be declared as a number or a function returning a number
* * * * presets: array of objects consisting of:
* * * * * bounds: - required.
* * * * * label: - required, string
* * * * clockOffsets: object, optional. Start and end relative to active clock.
* * * * start: and end: numbers relative to active clock's 0. Start is negative, end is positive.
* *advanced** example configuration below
*
timeSystems: [
{
key:'scet',
presets: [
{
label: 'Last 2 hours',
bounds: {
start: Date.now() - 1000 * 60 * 60 * 2,
end: Date.now()
}
{
key:'scet',
modeSettings:{
fixed:{
bounds:{
// 1 day ago
start: new Date(
Date.UTC(
new Date().getUTCFullYear(),
new Date().getUTCMonth(),
new Date().getUTCDate()
) - 1 * 864e5
).getTime(),
end: new Date(
Date.UTC(
new Date().getUTCFullYear(),
new Date().getUTCMonth(),
new Date().getUTCDate()
) + 864e5 - 1
).getTime()
},
{
label: 'Last 1 hour',
bounds: {
start: Date.now() - 1000 * 60 * 60,
end: Date.now()
}
presets:[
{
label: 'Last 2 hours (SCET Recorded)',
bounds: {
start: () => Date.now() - 1000 * 60 * 60 * 2,
end: () => Date.now()
}
],
limit: 1000 * 60 * 60 * 6
},
{
key:'ert',
presets: [
{
label: 'Last 2 hours',
bounds: {
start: Date.now() - 1000 * 60 * 60 * 2,
end: Date.now()
}
},
{
label: 'Last 1 hour',
bounds: {
start: Date.now() - 1000 * 60 * 60,
end: Date.now()
}
},
]
},
realtime:{
clockOffsets:{
start: -60 * 60 * 1000,
end: 5 * 60 * 1000
},
presets:[
{
label: 'Last 2 hours (SCET Realtime)',
bounds: {
start: -60 * 60 * 1000 * 2,
end: 5 * 60 * 1000
}
],
limit: 1000 * 60 * 60 * 6
}
]
},
lad:{
clockOffsets:{
start: -60 * 60 * 1000,
end: 5 * 60 * 1000
},
},
},
limit: 1000 * 60 * 60 * 60
},
{
key:'ert',
modeSettings:{
fixed:{
bounds:{
// 1 day ago
start: new Date(
Date.UTC(
new Date().getUTCFullYear(),
new Date().getUTCMonth(),
new Date().getUTCDate()
) - 1 * 864e5
).getTime(),
// today
end: new Date(
Date.UTC(
new Date().getUTCFullYear(),
new Date().getUTCMonth(),
new Date().getUTCDate()
) + 864e5 - 1
).getTime()
},
{
key:'sclk',
presets: [
{
label: 'Last 2 hours',
bounds: {
start: Date.now() - 1000 * 60 * 60 * 2,
end: Date.now()
}
},
{
label: 'Last 1 hour',
bounds: {
start: Date.now() - 1000 * 60 * 60,
end: Date.now()
}
}
],
limit: 1000 / 5 * 60 * 60 * 6
presets:[
{
label: 'Last 2 hours (ERT Recorded)',
bounds: {
start: Date.now() - 1000 * 60 * 60 * 2,
end: Date.now()
}
},
]
},
{
key:'lmst',
presets: []
}
],
*/

realtime:{
clockOffsets:{
start: -60 * 60 * 1000,
end: 5 * 60 * 1000
},
presets:[
{
label: 'Last 2 hours (ERT Realtime)',
bounds: {
start: -60 * 60 * 1000 * 2,
end: 5 * 60 * 1000
}
}
]
},
lad:{
clockOffsets:{
start: -60 * 60 * 1000,
end: 5 * 60 * 1000
},
},
},
limit: 1000 * 60 * 60 * 60
}
],
*/

/**
* allowRealtime: whether or not to allow utc-relative time conductor.
*/
Expand Down Expand Up @@ -528,4 +582,4 @@
};

window.openmctMCWSConfig = openmctMCWSConfig;
})();
})();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"mini-css-extract-plugin": "2.7.6",
"moment": "2.30.1",
"node-bourbon": "^4.2.3",
"openmct": "nasa/openmct#omm-r5.3.0-rc3",
"openmct": "nasa/openmct#omm-r5.3.1",
"printj": "1.3.1",
"raw-loader": "^0.5.1",
"resolve-url-loader": "5.0.0",
Expand Down
89 changes: 59 additions & 30 deletions src/time/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ const SYSTEM_MAP = {

export default function TimePlugin(options) {
return function install (openmct) {
var TODAY_BOUNDS = {
const TODAY_BOUNDS = {
start: moment.utc().startOf('day').valueOf(),
end: moment.utc().endOf('day').valueOf()
};

var solFormat = new MSLSolFormat(openmct);
var lmstFormat = new LMSTFormat(openmct);
var nowLST = solFormat.format(moment.utc());
var sol = Number(/SOL-(\d+)M/.exec(nowLST)[1]);

var BOUNDS_MAP = {
const solFormat = new MSLSolFormat(openmct);
const lmstFormat = new LMSTFormat(openmct);
const nowLST = solFormat.format(moment.utc());
const sol = Number(/SOL-(\d+)M/.exec(nowLST)[1]);
const BOUNDS_MAP = {
ert: TODAY_BOUNDS,
scet: TODAY_BOUNDS,
sclk: {
Expand All @@ -51,7 +49,7 @@ export default function TimePlugin(options) {
}

if (options.lmstEpoch) {
var lmstFormatWithEpoch = new LMSTFormat(options.lmstEpoch);
const lmstFormatWithEpoch = new LMSTFormat(options.lmstEpoch);

BOUNDS_MAP.lmst = {
start: lmstFormatWithEpoch.parse('SOL-' + sol),
Expand All @@ -61,74 +59,105 @@ export default function TimePlugin(options) {

install.ladClocks = {};
install.timeSystems = options.timeSystems;

let useUTCClock = false;
let menuOptions = [];


options.timeSystems.forEach(function (timeSystem) {
const key = timeSystem.key || timeSystem;
const key = timeSystem.key ?? timeSystem;

if (!SYSTEM_MAP[key]) {
console.error('Invalid timeSystem specified: ' + key);

return;
}

const system = new SYSTEM_MAP[key](options.utcFormat);
openmct.time.addTimeSystem(system);

const systemOptions = {
timeSystem: system.key,
bounds: BOUNDS_MAP[key]
name: 'fixed'
};

if (timeSystem.presets) {
systemOptions.presets = timeSystem.presets;
openmct.time.addTimeSystem(system);

if(timeSystem.modeSettings?.fixed?.bounds){
systemOptions.bounds = timeSystem.modeSettings.fixed.bounds;
} else {
systemOptions.bounds = BOUNDS_MAP[key];
}

if (timeSystem.modeSettings?.fixed?.presets) {
systemOptions.presets = timeSystem.modeSettings.fixed.presets;
}

if (timeSystem.limit) {
systemOptions.limit = timeSystem.limit;
}

if (options.records) {
systemOptions.records = options.records;
}

menuOptions.push(systemOptions);

const DEFAULT_OFFSET_CONFIG = {
start: -30 * 60 * 1000,
end: 5 * 60 * 1000
}

if (options.allowRealtime && system.isUTCBased) {
let offsetConfig = DEFAULT_OFFSET_CONFIG;
let presetConfig = [];

if (timeSystem.modeSettings?.realtime?.clockOffsets){
offsetConfig = timeSystem.modeSettings.realtime.clockOffsets
}

if (timeSystem.modeSettings?.realtime?.presets){
presetConfig = timeSystem.modeSettings.realtime.presets
}

useUTCClock = true;
menuOptions.push({
name:'realtime',
timeSystem: system.key,
clock: 'utc.local',
clockOffsets: {
start: -30 * 60 * 1000,
end: 5 * 60 * 1000
}
clockOffsets: offsetConfig,
presets: presetConfig
});
}

if (options.allowRealtime && options.allowLAD) {
var ladClock = new LADClock(key);
const ladClock = new LADClock(key);
let offsetConfig = DEFAULT_OFFSET_CONFIG;

if (timeSystem.modeSettings?.lad?.clockOffsets){
offsetConfig = timeSystem.modeSettings.lad.clockOffsets
}

install.ladClocks[key] = ladClock;
openmct.time.addClock(ladClock);
menuOptions.push({
timeSystem: system.key,
clock: ladClock.key,
clockOffsets: {
start: -30 * 60 * 1000,
end: 5 * 60 * 1000
}
clockOffsets: offsetConfig,
});
}
});

if (options.defaultMode) {
let matchingConfigIndex = menuOptions.findIndex(menuOption =>
menuOption.clock === options.defaultMode);
const isFixedMode = options.defaultMode === 'fixed';
const matchingConfigIndex = menuOptions.findIndex(
(menuOption) => isFixedMode ? !menuOption.clock : menuOption.clock === options.defaultMode
);

if (matchingConfigIndex !== -1) {
let matchingConfig = menuOptions[matchingConfigIndex];
const matchingConfig = menuOptions[matchingConfigIndex];

menuOptions.splice(matchingConfigIndex, 1);
menuOptions.unshift(matchingConfig);
} else {
console.warn(`Default mode '${options.defaultMode}' specified in configuration could not be applied.
Are LAD or realtime enabled? Does the defaultMode contain a typo?`);
console.warn(`Default mode '${options.defaultMode}' specified in configuration could not be applied. Are LAD or realtime enabled? Does the defaultMode contain a typo?`);
}
}

Expand Down