-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathplugin.js
More file actions
401 lines (356 loc) · 14.3 KB
/
Copy pathplugin.js
File metadata and controls
401 lines (356 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
import AboutTemplate from './about.html';
// eslint-disable-next-line no-unused-vars
import VistaStyles from './src/styles/sass/vista.scss'; /** Do not delete, needed for webpack to compile scss file*/
import CommandEventsViewPlugin from './src/commandEventsView/plugin.js';
import TaxonomyPlugin from './src/taxonomy/plugin.js';
import HistoricalTelemetryPlugin from './src/historical/plugin.js';
import LinkPlugin from './src/link/plugin.js';
import FormatPlugin from './src/formats/plugin.js';
import MessagesPlugin from './src/messagesView/plugin.js';
import ProductStatusPlugin from './src/product-status/plugin.js';
import MetadataActionPlugin from './src/metadataAction/plugin.js';
import ClearDataIndicatorPlugin from './src/clearDataIndicator/plugin.js';
import DictionaryViewPlugin from './src/dictionaryView/plugin.js';
import PacketSummaryPlugin from './src/packetSummary/plugin.js';
import ContainerViewPlugin from './src/containerView/plugin.js';
import IdentityProvider from './src/services/identity/MCWSIdentityProvider.js';
import MCWSPersistenceProviderPlugin from './src/persistence/plugin.js';
import DatasetCache from './src/services/dataset/DatasetCache.js';
import SessionService from './src/services/session/SessionService.js';
import GlobalStaleness from './src/services/globalStaleness/globalStaleness.js';
import TypePlugin from './src/types/plugin.js';
import TimePlugin from './src/time/plugin.js';
import getVistaTime from './src/services/time/vistaTime.js';
import RealtimeTelemetryPlugin from './src/realtime/plugin.js';
import VenuePlugin from './src/venues/plugin.js';
import mcwsClient from './src/services/mcws/MCWSClient.js';
import UTCDayOfYearFormat from './src/formats/UTCDayOfYearFormat.js';
import FrameWatchViewPlugin from './src/frameSummary/plugin.js';
import FrameEventFilterViewPlugin from './src/frameEventFilterView/plugin.js';
import ChannelTablePlugin from './src/channelTable/channelTablePlugin/plugin.js';
import ChannelTableSetPlugin from './src/channelTable/channelTableSetPlugin/plugin.js';
import ChannelLimitsPlugin from './src/channelLimits/plugin.js';
import FrameAccountabilityPlugin from './src/frameAccountability/plugin.js';
import AlarmsViewPlugin from './src/alarmsView/plugin.js';
import EVRViewPlugin from './src/evrView/plugin.js';
import CustomFormatterPlugin from './src/customFormatter/plugin.js';
import CustomFormsPlugin from './src/customForms/plugin.js';
import ActionModifiersPlugin from './src/actionModifiers/plugin.js';
import RealtimeIndicatorPlugin from './src/realtimeIndicator/plugin.js';
import PacketQueryPlugin from './src/packetQuery/plugin.js';
import MCWSIndicatorPlugin from './src/mcwsIndicator/plugin.js';
import MultipleHistoricalSessions from './src/multipleHistoricalSessions/plugin.js';
import MessageStreamProcessor from './src/messageStreamProcessor/MessageStreamProcessor.js';
import RealtimeSessions from './src/realtimeSessions/plugin.js';
import GlobalFilters from './src/globalFilters/plugin.js';
import ExportDataAction from './src/exportDataAction/plugin.js';
// optional runtime config
let runtimeConfig = {};
try {
const response = await fetch('./mcws-config.json', { cache: 'no-store' });
if (response.ok) {
runtimeConfig = await response.json();
} else if (response.status !== 404) {
console.warn(`Unable to load mcws-config.json: ${response.status}`);
}
} catch (error) {
console.warn('Unable to load mcws-config.json', error);
}
// helper function to check if an item is an object
function isObject(item) {
return item && typeof item === 'object' && !Array.isArray(item);
}
// helper function to tag every leaf in a newly introduced subtree with
// the current config source name ('default', 'build', 'runtime').
function buildSourceObj(configName, value) {
if (!isObject(value)) {
return configName;
}
return Object.keys(value).reduce((acc, key) => {
acc[key] = buildSourceObj(configName, value[key]);
return acc;
}, {});
}
// merge a single layer of the config object into the target object
// and track the source of the values, this is the main merge/track function
function mergeConfiguration(targetConfig, sourceConfig, name, sourceTags = {}) {
const output = { ...targetConfig };
const tags = { ...sourceTags };
if (!isObject(sourceConfig)) {
return { config: output, sources: tags };
}
Object.keys(sourceConfig).forEach((key) => {
if (isObject(sourceConfig[key])) {
if (!(key in output) || !isObject(output[key])) {
output[key] = sourceConfig[key];
tags[key] = buildSourceObj(name, sourceConfig[key]);
} else {
const merged = mergeConfiguration(output[key], sourceConfig[key], name, tags[key] || {});
output[key] = merged.config;
tags[key] = merged.sources;
}
} else {
output[key] = sourceConfig[key];
tags[key] = name;
}
});
return { config: output, sources: tags };
}
// populateAudit helper function to assign a value at a given path in the audit object
function assignAtPath(obj, pathParts, value) {
if (pathParts.length === 1) {
obj[pathParts[0]] = value;
return;
}
if (!(pathParts[0] in obj) || !isObject(obj[pathParts[0]])) {
obj[pathParts[0]] = {};
}
assignAtPath(obj[pathParts[0]], pathParts.slice(1), value);
}
// build the audit object by config source and create a flat
// object with the source tags for easier (additional) tracking
// of where the values are coming from
function populateAudit(config, sourceTags, audit, pathPrefix = '') {
Object.keys(config).forEach((key) => {
const path = pathPrefix ? `${pathPrefix}.${key}` : key;
const tag = sourceTags[key];
if (typeof tag === 'string') {
assignAtPath(audit[tag], path.split('.'), config[key]);
audit.sources[path] = tag;
} else if (tag && typeof tag === 'object') {
populateAudit(config[key], tag, audit, path);
}
});
}
/**
* Merges config layers in order (lowest precedence first) and builds a source audit.
* @param {{ name: 'default'|'build'|'runtime', sourceConfig: object }[]} sourceConfigurations
* @returns {{ config: object, audit: { runtime: object, build: object, default: object, derived: object, sources: Record<string, string> } }}
*/
function mergeConfigsWithAudit(sourceConfigurations) {
let finalConfiguration = {};
let sources = {};
sourceConfigurations.forEach(({ name, sourceConfig }) => {
const merged = mergeConfiguration(finalConfiguration, sourceConfig, name, sources);
finalConfiguration = merged.config;
sources = merged.sources;
});
const audit = {
runtime: {},
build: {},
default: {},
derived: {},
sources: {}
};
populateAudit(finalConfiguration, sources, audit);
return { config: finalConfiguration, audit };
}
export default function openmctMCWSPlugin(options) {
return function install(openmct) {
const defaultConfig = {
venueAware: {
enabled: false,
venues: 'ExampleVenueDefinitions.json'
},
namespaces: [
{
key: 'dev',
name: 'Shared',
url: ''
},
{
userNamespace: true,
key: 'dev',
name: 'Users',
url: ''
}
],
taxonomy: {
evrDefaultBackgroundColor: undefined,
evrDefaultForegroundColor: undefined,
evrBackgroundColorByLevel: {
FATAL: '#ff0000',
WARNING_HI: '#ff7f24',
WARNING_LO: '#ffff00',
COMMAND: '#00bfff',
ACTIVITY_HI: '#6d6d6d',
ACTIVITY_LO: '#dcdcdc',
DIAGNOSTIC: '#00ff00',
EVR_UNKNOWN: '#00ff00',
FAULT: '#ff0000',
WARNING: '#ff7f24'
},
evrForegroundColorByLevel: {
FATAL: '#ffffff',
WARNING_HI: '#000000',
WARNING_LO: '#000000',
COMMAND: '#ffffff',
ACTIVITY_HI: '#ffffff',
ACTIVITY_LO: '#000000',
DIAGNOSTIC: '#000000',
EVR_UNKNOWN: '#000000',
FAULT: '#ffffff',
WARNING: '#000000'
}
},
time: {
defaultMode: 'fixed',
utcFormat: 'utc.day-of-year',
lmstEpoch: Date.UTC(2020, 2, 18, 0, 0, 0),
subscriptionMCWSFilterDelay: 100,
timeSystems: ['scet', 'ert'],
allowRealtime: true,
allowLAD: true,
records: 10
},
sessionHistoricalMaxResults: 100,
batchHistoricalChannelQueries: false,
disableSortParam: false,
messageStreamUrl: '',
messageTypeFilters: [],
frameAccountabilityExpectedVcidList: [],
queryTimespanLimit: undefined,
globalStalenessInterval: undefined,
customFormatters: [],
sessions: {
historicalSessionFilter: {
disable: false,
maxRecords: 100,
denyUnfilteredQueries: false
},
realtimeSession: {
disable: false
}
},
tablePerformanceOptions: {
telemetryMode: 'unlimited',
persistModeChange: false,
rowLimit: 50
},
assetPath: 'node_modules/openmct/dist',
mcwsPluginAssetPath: 'node_modules/openmct-mcws-plugin/dist'
};
const recipeConfig = options || {};
// order of precedence: runtimeConfig, recipeConfig, defaultConfig
// mergeConfigsWithAudit builds lowest precedence first, with later
// configs overwriting earlier ones
const { config, audit } = mergeConfigsWithAudit([
{ name: 'default', sourceConfig: defaultConfig },
{ name: 'build', sourceConfig: recipeConfig },
{ name: 'runtime', sourceConfig: runtimeConfig }
]);
if (config.useDeveloperStorage === undefined) {
// Attempt to define a reasonable default for developer storage that supports Open MCT build tool
if (config.mcwsUrl === undefined || config.mcwsUrl.trim().length === 0) {
config.useDeveloperStorage = true;
} else {
config.useDeveloperStorage = false;
}
audit.derived.useDeveloperStorage = config.useDeveloperStorage;
audit.sources.useDeveloperStorage = 'derived';
}
openmct.setAssetPath(config.assetPath);
openmct.install(ClearDataIndicatorPlugin(config.globalStalenessInterval));
openmct.install(CommandEventsViewPlugin(config.tablePerformanceOptions));
openmct.install(MessagesPlugin(config.tablePerformanceOptions));
openmct.install(ProductStatusPlugin(config.tablePerformanceOptions));
openmct.install(MetadataActionPlugin());
openmct.install(DictionaryViewPlugin(config.tablePerformanceOptions));
openmct.install(PacketSummaryPlugin(config.tablePerformanceOptions));
openmct.install(ContainerViewPlugin());
// initialize session service, datasetCache service, global staleness
SessionService(openmct, config);
DatasetCache(openmct);
GlobalStaleness(openmct, config.globalStalenessInterval);
openmct.install(new FormatPlugin(config));
const timePlugin = new TimePlugin(config.time);
openmct.install(timePlugin);
const formatKey = config.time.utcFormat;
const utcFormat = formatKey
? openmct.telemetry.getFormatter(formatKey)
: new UTCDayOfYearFormat();
const vistaTime = getVistaTime({
options: timePlugin,
format: utcFormat
});
openmct.install(RealtimeIndicatorPlugin(vistaTime, utcFormat));
mcwsClient.configure(config);
openmct.install(MultipleHistoricalSessions(config.tablePerformanceOptions));
openmct.install(RealtimeSessions());
openmct.install(new HistoricalTelemetryPlugin(config));
openmct.install(new RealtimeTelemetryPlugin(vistaTime, config));
openmct.install(new TypePlugin());
openmct.install(new TaxonomyPlugin(config.taxonomy));
openmct.install(new LinkPlugin(config));
openmct.install(new VenuePlugin(config));
openmct.install(FrameWatchViewPlugin(config.tablePerformanceOptions));
openmct.install(FrameEventFilterViewPlugin(config.tablePerformanceOptions));
openmct.install(new ChannelTablePlugin(config.tablePerformanceOptions));
openmct.install(new ChannelTableSetPlugin());
openmct.install(new ChannelLimitsPlugin());
openmct.install(new FrameAccountabilityPlugin(config));
openmct.install(EVRViewPlugin(config));
openmct.install(new AlarmsViewPlugin(config.tablePerformanceOptions));
openmct.install(MCWSIndicatorPlugin());
if (config.messageStreamUrl && config.messageStreamUrl !== '') {
openmct.install(
new MessageStreamProcessor(config.messageStreamUrl, {
clearData: ['StartOfSession', 'EndOfSession'],
suspectChannels: ['SuspectChannels']
})
);
}
if (config.customFormatters.length) {
openmct.install(CustomFormatterPlugin(config.customFormatters));
}
openmct.install(CustomFormsPlugin());
openmct.install(
new ExportDataAction([
'table',
'telemetry.plot.overlay',
'telemetry.plot.stacked',
'vista.channel',
'vista.channelGroup',
'vista.chanTableGroup',
'vista.evr',
'vista.evrModule',
'vista.evrSource',
'vista.evrView'
])
);
openmct.install(ActionModifiersPlugin());
openmct.install(new PacketQueryPlugin());
if (config.globalFilters) {
openmct.install(new GlobalFilters(config.globalFilters));
}
openmct.user.setProvider(new IdentityProvider(openmct));
if (!config.useDeveloperStorage) {
openmct.install(MCWSPersistenceProviderPlugin(config.namespaces));
}
openmct.branding({ aboutHtml: insertBuildInfo(AboutTemplate) });
// do not show telemetry if it falls out of bounds
// even if there is no new telemetry
openmct.telemetry.greedyLAD(false);
// expose the config to the window
window.openmctMCWSConfig = config;
window.openmctMCWSConfigurationAudit = audit;
// load the css file
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = `${config.mcwsPluginAssetPath}/openmct-mcws-plugin.css`;
document.head.appendChild(link);
};
/**
* Replaces placeholders in the HTML with build info provided by webpack.
* Build info is defined in webpack config, and is exposed as global
* JavaScript variables
* @param {*} markup
*/
function insertBuildInfo(markup) {
return markup
.replace(/\$\{project\.version\}/g, __OMM_VERSION__)
.replace(/\$\{timestamp\}/g, __OMM_BUILD_DATE__)
.replace(/\$\{buildNumber\}/g, __OMM_REVISION__)
.replace(/\$\{branch\}/g, __OMM_BUILD_BRANCH__);
}
}