mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 05:38:12 +00:00
feat: AMD -> ES6 (#7029)
* feat: full amd -> es6 conversion * fix: move MCT to ES6 class * fix: default drop, correct imports * fix: correct all imports * fix: property typo * fix: avoid anonymous functions * fix: correct typo scarily small - can see why this e2e coverage issue is high priority * fix: use proper uuid format * style: fmt * fix: import vue correctly, get correct layout * fix: createApp without JSON fixes template issues * fix: don't use default on InspectorDataVisualization * fix: remove more .default calls * Update src/api/api.js Co-authored-by: Jesse Mazzella <ozyx@users.noreply.github.com> * Update src/plugins/plugins.js Co-authored-by: Jesse Mazzella <ozyx@users.noreply.github.com> * Update src/plugins/plugins.js Co-authored-by: Jesse Mazzella <ozyx@users.noreply.github.com> * fix: suggestions * fix: drop unnecessary this.annotation initialization * fix: move all initialization calls to constructor * refactor: move vue dist import to webpack alias --------- Co-authored-by: Jesse Mazzella <ozyx@users.noreply.github.com>
This commit is contained in:
@ -20,457 +20,444 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'EventEmitter',
|
||||
'lodash',
|
||||
'./collections/TableRowCollection',
|
||||
'./TelemetryTableRow',
|
||||
'./TelemetryTableNameColumn',
|
||||
'./TelemetryTableColumn',
|
||||
'./TelemetryTableUnitColumn',
|
||||
'./TelemetryTableConfiguration',
|
||||
'../../utils/staleness'
|
||||
], function (
|
||||
EventEmitter,
|
||||
_,
|
||||
TableRowCollection,
|
||||
TelemetryTableRow,
|
||||
TelemetryTableNameColumn,
|
||||
TelemetryTableColumn,
|
||||
TelemetryTableUnitColumn,
|
||||
TelemetryTableConfiguration,
|
||||
StalenessUtils
|
||||
) {
|
||||
class TelemetryTable extends EventEmitter {
|
||||
constructor(domainObject, openmct) {
|
||||
super();
|
||||
import EventEmitter from 'EventEmitter';
|
||||
import _ from 'lodash';
|
||||
|
||||
this.domainObject = domainObject;
|
||||
this.openmct = openmct;
|
||||
this.rowCount = 100;
|
||||
this.tableComposition = undefined;
|
||||
this.datumCache = [];
|
||||
this.configuration = new TelemetryTableConfiguration(domainObject, openmct);
|
||||
this.paused = false;
|
||||
this.keyString = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
||||
import StalenessUtils from '../../utils/staleness';
|
||||
import TableRowCollection from './collections/TableRowCollection';
|
||||
import TelemetryTableColumn from './TelemetryTableColumn';
|
||||
import TelemetryTableConfiguration from './TelemetryTableConfiguration';
|
||||
import TelemetryTableNameColumn from './TelemetryTableNameColumn';
|
||||
import TelemetryTableRow from './TelemetryTableRow';
|
||||
import TelemetryTableUnitColumn from './TelemetryTableUnitColumn';
|
||||
|
||||
this.telemetryObjects = {};
|
||||
this.subscribedStaleObjects = new Map();
|
||||
this.telemetryCollections = {};
|
||||
this.delayedActions = [];
|
||||
this.outstandingRequests = 0;
|
||||
this.stalenessSubscription = {};
|
||||
export default class TelemetryTable extends EventEmitter {
|
||||
constructor(domainObject, openmct) {
|
||||
super();
|
||||
|
||||
this.addTelemetryObject = this.addTelemetryObject.bind(this);
|
||||
this.removeTelemetryObject = this.removeTelemetryObject.bind(this);
|
||||
this.removeTelemetryCollection = this.removeTelemetryCollection.bind(this);
|
||||
this.incrementOutstandingRequests = this.incrementOutstandingRequests.bind(this);
|
||||
this.decrementOutstandingRequests = this.decrementOutstandingRequests.bind(this);
|
||||
this.resetRowsFromAllData = this.resetRowsFromAllData.bind(this);
|
||||
this.isTelemetryObject = this.isTelemetryObject.bind(this);
|
||||
this.updateFilters = this.updateFilters.bind(this);
|
||||
this.clearData = this.clearData.bind(this);
|
||||
this.buildOptionsFromConfiguration = this.buildOptionsFromConfiguration.bind(this);
|
||||
this.domainObject = domainObject;
|
||||
this.openmct = openmct;
|
||||
this.rowCount = 100;
|
||||
this.tableComposition = undefined;
|
||||
this.datumCache = [];
|
||||
this.configuration = new TelemetryTableConfiguration(domainObject, openmct);
|
||||
this.paused = false;
|
||||
this.keyString = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
||||
|
||||
this.filterObserver = undefined;
|
||||
this.telemetryObjects = {};
|
||||
this.subscribedStaleObjects = new Map();
|
||||
this.telemetryCollections = {};
|
||||
this.delayedActions = [];
|
||||
this.outstandingRequests = 0;
|
||||
this.stalenessSubscription = {};
|
||||
|
||||
this.createTableRowCollections();
|
||||
this.resubscribeToStaleness = this.resubscribeAllObjectsToStaleness.bind(this);
|
||||
this.openmct.time.on('clockChanged', this.resubscribeToStaleness);
|
||||
}
|
||||
this.addTelemetryObject = this.addTelemetryObject.bind(this);
|
||||
this.removeTelemetryObject = this.removeTelemetryObject.bind(this);
|
||||
this.removeTelemetryCollection = this.removeTelemetryCollection.bind(this);
|
||||
this.incrementOutstandingRequests = this.incrementOutstandingRequests.bind(this);
|
||||
this.decrementOutstandingRequests = this.decrementOutstandingRequests.bind(this);
|
||||
this.resetRowsFromAllData = this.resetRowsFromAllData.bind(this);
|
||||
this.isTelemetryObject = this.isTelemetryObject.bind(this);
|
||||
this.updateFilters = this.updateFilters.bind(this);
|
||||
this.clearData = this.clearData.bind(this);
|
||||
this.buildOptionsFromConfiguration = this.buildOptionsFromConfiguration.bind(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
addNameColumn(telemetryObject, metadataValues) {
|
||||
let metadatum = metadataValues.find((m) => m.key === 'name');
|
||||
if (!metadatum) {
|
||||
metadatum = {
|
||||
format: 'string',
|
||||
key: 'name',
|
||||
name: 'Name'
|
||||
};
|
||||
}
|
||||
this.filterObserver = undefined;
|
||||
|
||||
const column = new TelemetryTableNameColumn(this.openmct, telemetryObject, metadatum);
|
||||
this.createTableRowCollections();
|
||||
this.resubscribeToStaleness = this.resubscribeAllObjectsToStaleness.bind(this);
|
||||
this.openmct.time.on('clockChanged', this.resubscribeToStaleness);
|
||||
}
|
||||
|
||||
this.configuration.addSingleColumnForObject(telemetryObject, column);
|
||||
}
|
||||
|
||||
initialize() {
|
||||
if (this.domainObject.type === 'table') {
|
||||
this.filterObserver = this.openmct.objects.observe(
|
||||
this.domainObject,
|
||||
'configuration.filters',
|
||||
this.updateFilters
|
||||
);
|
||||
this.filters = this.domainObject.configuration.filters;
|
||||
this.loadComposition();
|
||||
} else {
|
||||
this.addTelemetryObject(this.domainObject);
|
||||
}
|
||||
}
|
||||
|
||||
createTableRowCollections() {
|
||||
this.tableRows = new TableRowCollection();
|
||||
|
||||
//Fetch any persisted default sort
|
||||
let sortOptions = this.configuration.getConfiguration().sortOptions;
|
||||
|
||||
//If no persisted sort order, default to sorting by time system, ascending.
|
||||
sortOptions = sortOptions || {
|
||||
key: this.openmct.time.timeSystem().key,
|
||||
direction: 'asc'
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
addNameColumn(telemetryObject, metadataValues) {
|
||||
let metadatum = metadataValues.find((m) => m.key === 'name');
|
||||
if (!metadatum) {
|
||||
metadatum = {
|
||||
format: 'string',
|
||||
key: 'name',
|
||||
name: 'Name'
|
||||
};
|
||||
|
||||
this.tableRows.sortBy(sortOptions);
|
||||
this.tableRows.on('resetRowsFromAllData', this.resetRowsFromAllData);
|
||||
}
|
||||
|
||||
loadComposition() {
|
||||
this.tableComposition = this.openmct.composition.get(this.domainObject);
|
||||
const column = new TelemetryTableNameColumn(this.openmct, telemetryObject, metadatum);
|
||||
|
||||
if (this.tableComposition !== undefined) {
|
||||
this.tableComposition.load().then((composition) => {
|
||||
composition = composition.filter(this.isTelemetryObject);
|
||||
composition.forEach(this.addTelemetryObject);
|
||||
this.configuration.addSingleColumnForObject(telemetryObject, column);
|
||||
}
|
||||
|
||||
this.tableComposition.on('add', this.addTelemetryObject);
|
||||
this.tableComposition.on('remove', this.removeTelemetryObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addTelemetryObject(telemetryObject) {
|
||||
this.addColumnsForObject(telemetryObject, true);
|
||||
|
||||
const keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
let requestOptions = this.buildOptionsFromConfiguration(telemetryObject);
|
||||
let columnMap = this.getColumnMapForObject(keyString);
|
||||
let limitEvaluator = this.openmct.telemetry.limitEvaluator(telemetryObject);
|
||||
|
||||
const telemetryProcessor = this.getTelemetryProcessor(keyString, columnMap, limitEvaluator);
|
||||
const telemetryRemover = this.getTelemetryRemover();
|
||||
|
||||
this.removeTelemetryCollection(keyString);
|
||||
|
||||
this.telemetryCollections[keyString] = this.openmct.telemetry.requestCollection(
|
||||
telemetryObject,
|
||||
requestOptions
|
||||
initialize() {
|
||||
if (this.domainObject.type === 'table') {
|
||||
this.filterObserver = this.openmct.objects.observe(
|
||||
this.domainObject,
|
||||
'configuration.filters',
|
||||
this.updateFilters
|
||||
);
|
||||
|
||||
this.telemetryCollections[keyString].on('requestStarted', this.incrementOutstandingRequests);
|
||||
this.telemetryCollections[keyString].on('requestEnded', this.decrementOutstandingRequests);
|
||||
this.telemetryCollections[keyString].on('remove', telemetryRemover);
|
||||
this.telemetryCollections[keyString].on('add', telemetryProcessor);
|
||||
this.telemetryCollections[keyString].on('clear', this.clearData);
|
||||
this.telemetryCollections[keyString].load();
|
||||
|
||||
this.subscribeToStaleness(telemetryObject);
|
||||
|
||||
this.telemetryObjects[keyString] = {
|
||||
telemetryObject,
|
||||
keyString,
|
||||
requestOptions,
|
||||
columnMap,
|
||||
limitEvaluator
|
||||
};
|
||||
|
||||
this.emit('object-added', telemetryObject);
|
||||
}
|
||||
|
||||
resubscribeAllObjectsToStaleness() {
|
||||
if (!this.subscribedStaleObjects || this.subscribedStaleObjects.size < 1) {
|
||||
return;
|
||||
}
|
||||
for (const [, telemetryObject] of this.subscribedStaleObjects) {
|
||||
this.subscribeToStaleness(telemetryObject);
|
||||
}
|
||||
}
|
||||
|
||||
subscribeToStaleness(domainObject) {
|
||||
const keyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||
if (this.stalenessSubscription?.[keyString]) {
|
||||
this.unsubscribeFromStaleness(domainObject.identifier);
|
||||
}
|
||||
|
||||
this.stalenessSubscription[keyString] = {};
|
||||
this.stalenessSubscription[keyString].stalenessUtils = new StalenessUtils.default(
|
||||
this.openmct,
|
||||
domainObject
|
||||
);
|
||||
this.openmct.telemetry.isStale(domainObject).then((stalenessResponse) => {
|
||||
if (stalenessResponse !== undefined) {
|
||||
this.handleStaleness(keyString, stalenessResponse);
|
||||
}
|
||||
});
|
||||
const stalenessSubscription = this.openmct.telemetry.subscribeToStaleness(
|
||||
domainObject,
|
||||
(stalenessResponse) => {
|
||||
this.handleStaleness(keyString, stalenessResponse);
|
||||
}
|
||||
);
|
||||
this.subscribedStaleObjects.set(keyString, domainObject);
|
||||
|
||||
this.stalenessSubscription[keyString].unsubscribe = stalenessSubscription;
|
||||
}
|
||||
|
||||
handleStaleness(keyString, stalenessResponse, skipCheck = false) {
|
||||
if (
|
||||
skipCheck ||
|
||||
this.stalenessSubscription[keyString].stalenessUtils.shouldUpdateStaleness(
|
||||
stalenessResponse,
|
||||
keyString
|
||||
)
|
||||
) {
|
||||
this.emit('telemetry-staleness', {
|
||||
keyString,
|
||||
stalenessResponse: stalenessResponse
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getTelemetryProcessor(keyString, columnMap, limitEvaluator) {
|
||||
return (telemetry) => {
|
||||
//Check that telemetry object has not been removed since telemetry was requested.
|
||||
if (!this.telemetryObjects[keyString]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const metadataValue = this.openmct.telemetry
|
||||
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
|
||||
.getUseToUpdateInPlaceValue();
|
||||
|
||||
let telemetryRows = telemetry.map(
|
||||
(datum) =>
|
||||
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
|
||||
);
|
||||
|
||||
if (this.paused) {
|
||||
this.delayedActions.push(this.tableRows.addRows.bind(this, telemetryRows, 'add'));
|
||||
} else {
|
||||
this.tableRows.addRows(telemetryRows);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getTelemetryRemover() {
|
||||
return (telemetry) => {
|
||||
if (this.paused) {
|
||||
this.delayedActions.push(this.tableRows.removeRowsByData.bind(this, telemetry));
|
||||
} else {
|
||||
this.tableRows.removeRowsByData(telemetry);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
incrementOutstandingRequests() {
|
||||
if (this.outstandingRequests === 0) {
|
||||
this.emit('outstanding-requests', true);
|
||||
}
|
||||
|
||||
this.outstandingRequests++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
decrementOutstandingRequests() {
|
||||
this.outstandingRequests--;
|
||||
|
||||
if (this.outstandingRequests === 0) {
|
||||
this.emit('outstanding-requests', false);
|
||||
}
|
||||
}
|
||||
|
||||
// will pull all necessary information for all existing bounded telemetry
|
||||
// and pass to table row collection to reset without making any new requests
|
||||
// triggered by filtering
|
||||
resetRowsFromAllData() {
|
||||
let allRows = [];
|
||||
|
||||
Object.keys(this.telemetryCollections).forEach((keyString) => {
|
||||
let { columnMap, limitEvaluator } = this.telemetryObjects[keyString];
|
||||
|
||||
const metadataValue = this.openmct.telemetry
|
||||
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
|
||||
.getUseToUpdateInPlaceValue();
|
||||
|
||||
this.telemetryCollections[keyString].getAll().forEach((datum) => {
|
||||
allRows.push(
|
||||
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
this.tableRows.clearRowsFromTableAndFilter(allRows);
|
||||
}
|
||||
|
||||
updateFilters(updatedFilters) {
|
||||
let deepCopiedFilters = JSON.parse(JSON.stringify(updatedFilters));
|
||||
|
||||
if (this.filters && !_.isEqual(this.filters, deepCopiedFilters)) {
|
||||
this.filters = deepCopiedFilters;
|
||||
this.tableRows.clear();
|
||||
this.clearAndResubscribe();
|
||||
} else {
|
||||
this.filters = deepCopiedFilters;
|
||||
}
|
||||
}
|
||||
|
||||
clearAndResubscribe() {
|
||||
let objectKeys = Object.keys(this.telemetryObjects);
|
||||
|
||||
this.tableRows.clear();
|
||||
objectKeys.forEach((keyString) => {
|
||||
this.addTelemetryObject(this.telemetryObjects[keyString].telemetryObject);
|
||||
});
|
||||
}
|
||||
|
||||
removeTelemetryObject(objectIdentifier) {
|
||||
const keyString = this.openmct.objects.makeKeyString(objectIdentifier);
|
||||
|
||||
this.configuration.removeColumnsForObject(objectIdentifier, true);
|
||||
this.tableRows.removeRowsByObject(keyString);
|
||||
|
||||
this.removeTelemetryCollection(keyString);
|
||||
delete this.telemetryObjects[keyString];
|
||||
|
||||
this.emit('object-removed', objectIdentifier);
|
||||
|
||||
this.unsubscribeFromStaleness(objectIdentifier);
|
||||
}
|
||||
|
||||
unsubscribeFromStaleness(objectIdentifier) {
|
||||
const keyString = this.openmct.objects.makeKeyString(objectIdentifier);
|
||||
const SKIP_CHECK = true;
|
||||
|
||||
this.stalenessSubscription[keyString].unsubscribe();
|
||||
this.stalenessSubscription[keyString].stalenessUtils.destroy();
|
||||
this.handleStaleness(keyString, { isStale: false }, SKIP_CHECK);
|
||||
delete this.stalenessSubscription[keyString];
|
||||
}
|
||||
|
||||
clearData() {
|
||||
this.tableRows.clear();
|
||||
this.emit('refresh');
|
||||
}
|
||||
|
||||
addColumnsForObject(telemetryObject) {
|
||||
const metadata = this.openmct.telemetry.getMetadata(telemetryObject);
|
||||
let metadataValues = metadata.values();
|
||||
|
||||
this.addNameColumn(telemetryObject, metadataValues);
|
||||
metadataValues.forEach((metadatum) => {
|
||||
if (metadatum.key === 'name' || metadata.isInPlaceUpdateValue(metadatum)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let column = this.createColumn(metadatum);
|
||||
this.configuration.addSingleColumnForObject(telemetryObject, column);
|
||||
// add units column if available
|
||||
if (metadatum.unit !== undefined) {
|
||||
let unitColumn = this.createUnitColumn(metadatum);
|
||||
this.configuration.addSingleColumnForObject(telemetryObject, unitColumn);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getColumnMapForObject(objectKeyString) {
|
||||
let columns = this.configuration.getColumns();
|
||||
|
||||
if (columns[objectKeyString]) {
|
||||
return columns[objectKeyString].reduce((map, column) => {
|
||||
map[column.getKey()] = column;
|
||||
|
||||
return map;
|
||||
}, {});
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
buildOptionsFromConfiguration(telemetryObject) {
|
||||
let keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
let filters =
|
||||
this.domainObject.configuration &&
|
||||
this.domainObject.configuration.filters &&
|
||||
this.domainObject.configuration.filters[keyString];
|
||||
|
||||
return { filters } || {};
|
||||
}
|
||||
|
||||
createColumn(metadatum) {
|
||||
return new TelemetryTableColumn(this.openmct, metadatum);
|
||||
}
|
||||
|
||||
createUnitColumn(metadatum) {
|
||||
return new TelemetryTableUnitColumn(this.openmct, metadatum);
|
||||
}
|
||||
|
||||
isTelemetryObject(domainObject) {
|
||||
return Object.prototype.hasOwnProperty.call(domainObject, 'telemetry');
|
||||
}
|
||||
|
||||
sortBy(sortOptions) {
|
||||
this.tableRows.sortBy(sortOptions);
|
||||
|
||||
if (this.openmct.editor.isEditing()) {
|
||||
let configuration = this.configuration.getConfiguration();
|
||||
configuration.sortOptions = sortOptions;
|
||||
this.configuration.updateConfiguration(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
runDelayedActions() {
|
||||
this.delayedActions.forEach((action) => action());
|
||||
this.delayedActions = [];
|
||||
}
|
||||
|
||||
removeTelemetryCollection(keyString) {
|
||||
if (this.telemetryCollections[keyString]) {
|
||||
this.telemetryCollections[keyString].destroy();
|
||||
this.telemetryCollections[keyString] = undefined;
|
||||
delete this.telemetryCollections[keyString];
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
this.paused = true;
|
||||
}
|
||||
|
||||
unpause() {
|
||||
this.paused = false;
|
||||
this.runDelayedActions();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.tableRows.destroy();
|
||||
|
||||
this.tableRows.off('resetRowsFromAllData', this.resetRowsFromAllData);
|
||||
this.openmct.time.off('clockChanged', this.resubscribeToStaleness);
|
||||
|
||||
let keystrings = Object.keys(this.telemetryCollections);
|
||||
keystrings.forEach(this.removeTelemetryCollection);
|
||||
|
||||
if (this.filterObserver) {
|
||||
this.filterObserver();
|
||||
}
|
||||
|
||||
Object.values(this.stalenessSubscription).forEach((stalenessSubscription) => {
|
||||
stalenessSubscription.unsubscribe();
|
||||
stalenessSubscription.stalenessUtils.destroy();
|
||||
});
|
||||
|
||||
if (this.tableComposition !== undefined) {
|
||||
this.tableComposition.off('add', this.addTelemetryObject);
|
||||
this.tableComposition.off('remove', this.removeTelemetryObject);
|
||||
}
|
||||
this.filters = this.domainObject.configuration.filters;
|
||||
this.loadComposition();
|
||||
} else {
|
||||
this.addTelemetryObject(this.domainObject);
|
||||
}
|
||||
}
|
||||
|
||||
return TelemetryTable;
|
||||
});
|
||||
createTableRowCollections() {
|
||||
this.tableRows = new TableRowCollection();
|
||||
|
||||
//Fetch any persisted default sort
|
||||
let sortOptions = this.configuration.getConfiguration().sortOptions;
|
||||
|
||||
//If no persisted sort order, default to sorting by time system, ascending.
|
||||
sortOptions = sortOptions || {
|
||||
key: this.openmct.time.timeSystem().key,
|
||||
direction: 'asc'
|
||||
};
|
||||
|
||||
this.tableRows.sortBy(sortOptions);
|
||||
this.tableRows.on('resetRowsFromAllData', this.resetRowsFromAllData);
|
||||
}
|
||||
|
||||
loadComposition() {
|
||||
this.tableComposition = this.openmct.composition.get(this.domainObject);
|
||||
|
||||
if (this.tableComposition !== undefined) {
|
||||
this.tableComposition.load().then((composition) => {
|
||||
composition = composition.filter(this.isTelemetryObject);
|
||||
composition.forEach(this.addTelemetryObject);
|
||||
|
||||
this.tableComposition.on('add', this.addTelemetryObject);
|
||||
this.tableComposition.on('remove', this.removeTelemetryObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addTelemetryObject(telemetryObject) {
|
||||
this.addColumnsForObject(telemetryObject, true);
|
||||
|
||||
const keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
let requestOptions = this.buildOptionsFromConfiguration(telemetryObject);
|
||||
let columnMap = this.getColumnMapForObject(keyString);
|
||||
let limitEvaluator = this.openmct.telemetry.limitEvaluator(telemetryObject);
|
||||
|
||||
const telemetryProcessor = this.getTelemetryProcessor(keyString, columnMap, limitEvaluator);
|
||||
const telemetryRemover = this.getTelemetryRemover();
|
||||
|
||||
this.removeTelemetryCollection(keyString);
|
||||
|
||||
this.telemetryCollections[keyString] = this.openmct.telemetry.requestCollection(
|
||||
telemetryObject,
|
||||
requestOptions
|
||||
);
|
||||
|
||||
this.telemetryCollections[keyString].on('requestStarted', this.incrementOutstandingRequests);
|
||||
this.telemetryCollections[keyString].on('requestEnded', this.decrementOutstandingRequests);
|
||||
this.telemetryCollections[keyString].on('remove', telemetryRemover);
|
||||
this.telemetryCollections[keyString].on('add', telemetryProcessor);
|
||||
this.telemetryCollections[keyString].on('clear', this.clearData);
|
||||
this.telemetryCollections[keyString].load();
|
||||
|
||||
this.subscribeToStaleness(telemetryObject);
|
||||
|
||||
this.telemetryObjects[keyString] = {
|
||||
telemetryObject,
|
||||
keyString,
|
||||
requestOptions,
|
||||
columnMap,
|
||||
limitEvaluator
|
||||
};
|
||||
|
||||
this.emit('object-added', telemetryObject);
|
||||
}
|
||||
|
||||
resubscribeAllObjectsToStaleness() {
|
||||
if (!this.subscribedStaleObjects || this.subscribedStaleObjects.size < 1) {
|
||||
return;
|
||||
}
|
||||
for (const [, telemetryObject] of this.subscribedStaleObjects) {
|
||||
this.subscribeToStaleness(telemetryObject);
|
||||
}
|
||||
}
|
||||
|
||||
subscribeToStaleness(domainObject) {
|
||||
const keyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||
if (this.stalenessSubscription?.[keyString]) {
|
||||
this.unsubscribeFromStaleness(domainObject.identifier);
|
||||
}
|
||||
|
||||
this.stalenessSubscription[keyString] = {};
|
||||
this.stalenessSubscription[keyString].stalenessUtils = new StalenessUtils(
|
||||
this.openmct,
|
||||
domainObject
|
||||
);
|
||||
this.openmct.telemetry.isStale(domainObject).then((stalenessResponse) => {
|
||||
if (stalenessResponse !== undefined) {
|
||||
this.handleStaleness(keyString, stalenessResponse);
|
||||
}
|
||||
});
|
||||
const stalenessSubscription = this.openmct.telemetry.subscribeToStaleness(
|
||||
domainObject,
|
||||
(stalenessResponse) => {
|
||||
this.handleStaleness(keyString, stalenessResponse);
|
||||
}
|
||||
);
|
||||
this.subscribedStaleObjects.set(keyString, domainObject);
|
||||
|
||||
this.stalenessSubscription[keyString].unsubscribe = stalenessSubscription;
|
||||
}
|
||||
|
||||
handleStaleness(keyString, stalenessResponse, skipCheck = false) {
|
||||
if (
|
||||
skipCheck ||
|
||||
this.stalenessSubscription[keyString].stalenessUtils.shouldUpdateStaleness(
|
||||
stalenessResponse,
|
||||
keyString
|
||||
)
|
||||
) {
|
||||
this.emit('telemetry-staleness', {
|
||||
keyString,
|
||||
stalenessResponse: stalenessResponse
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getTelemetryProcessor(keyString, columnMap, limitEvaluator) {
|
||||
return (telemetry) => {
|
||||
//Check that telemetry object has not been removed since telemetry was requested.
|
||||
if (!this.telemetryObjects[keyString]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const metadataValue = this.openmct.telemetry
|
||||
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
|
||||
.getUseToUpdateInPlaceValue();
|
||||
|
||||
let telemetryRows = telemetry.map(
|
||||
(datum) =>
|
||||
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
|
||||
);
|
||||
|
||||
if (this.paused) {
|
||||
this.delayedActions.push(this.tableRows.addRows.bind(this, telemetryRows, 'add'));
|
||||
} else {
|
||||
this.tableRows.addRows(telemetryRows);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getTelemetryRemover() {
|
||||
return (telemetry) => {
|
||||
if (this.paused) {
|
||||
this.delayedActions.push(this.tableRows.removeRowsByData.bind(this, telemetry));
|
||||
} else {
|
||||
this.tableRows.removeRowsByData(telemetry);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
incrementOutstandingRequests() {
|
||||
if (this.outstandingRequests === 0) {
|
||||
this.emit('outstanding-requests', true);
|
||||
}
|
||||
|
||||
this.outstandingRequests++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
decrementOutstandingRequests() {
|
||||
this.outstandingRequests--;
|
||||
|
||||
if (this.outstandingRequests === 0) {
|
||||
this.emit('outstanding-requests', false);
|
||||
}
|
||||
}
|
||||
|
||||
// will pull all necessary information for all existing bounded telemetry
|
||||
// and pass to table row collection to reset without making any new requests
|
||||
// triggered by filtering
|
||||
resetRowsFromAllData() {
|
||||
let allRows = [];
|
||||
|
||||
Object.keys(this.telemetryCollections).forEach((keyString) => {
|
||||
let { columnMap, limitEvaluator } = this.telemetryObjects[keyString];
|
||||
|
||||
const metadataValue = this.openmct.telemetry
|
||||
.getMetadata(this.telemetryObjects[keyString].telemetryObject)
|
||||
.getUseToUpdateInPlaceValue();
|
||||
|
||||
this.telemetryCollections[keyString].getAll().forEach((datum) => {
|
||||
allRows.push(
|
||||
new TelemetryTableRow(datum, columnMap, keyString, limitEvaluator, metadataValue?.key)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
this.tableRows.clearRowsFromTableAndFilter(allRows);
|
||||
}
|
||||
|
||||
updateFilters(updatedFilters) {
|
||||
let deepCopiedFilters = JSON.parse(JSON.stringify(updatedFilters));
|
||||
|
||||
if (this.filters && !_.isEqual(this.filters, deepCopiedFilters)) {
|
||||
this.filters = deepCopiedFilters;
|
||||
this.tableRows.clear();
|
||||
this.clearAndResubscribe();
|
||||
} else {
|
||||
this.filters = deepCopiedFilters;
|
||||
}
|
||||
}
|
||||
|
||||
clearAndResubscribe() {
|
||||
let objectKeys = Object.keys(this.telemetryObjects);
|
||||
|
||||
this.tableRows.clear();
|
||||
objectKeys.forEach((keyString) => {
|
||||
this.addTelemetryObject(this.telemetryObjects[keyString].telemetryObject);
|
||||
});
|
||||
}
|
||||
|
||||
removeTelemetryObject(objectIdentifier) {
|
||||
const keyString = this.openmct.objects.makeKeyString(objectIdentifier);
|
||||
|
||||
this.configuration.removeColumnsForObject(objectIdentifier, true);
|
||||
this.tableRows.removeRowsByObject(keyString);
|
||||
|
||||
this.removeTelemetryCollection(keyString);
|
||||
delete this.telemetryObjects[keyString];
|
||||
|
||||
this.emit('object-removed', objectIdentifier);
|
||||
|
||||
this.unsubscribeFromStaleness(objectIdentifier);
|
||||
}
|
||||
|
||||
unsubscribeFromStaleness(objectIdentifier) {
|
||||
const keyString = this.openmct.objects.makeKeyString(objectIdentifier);
|
||||
const SKIP_CHECK = true;
|
||||
|
||||
this.stalenessSubscription[keyString].unsubscribe();
|
||||
this.stalenessSubscription[keyString].stalenessUtils.destroy();
|
||||
this.handleStaleness(keyString, { isStale: false }, SKIP_CHECK);
|
||||
delete this.stalenessSubscription[keyString];
|
||||
}
|
||||
|
||||
clearData() {
|
||||
this.tableRows.clear();
|
||||
this.emit('refresh');
|
||||
}
|
||||
|
||||
addColumnsForObject(telemetryObject) {
|
||||
const metadata = this.openmct.telemetry.getMetadata(telemetryObject);
|
||||
let metadataValues = metadata.values();
|
||||
|
||||
this.addNameColumn(telemetryObject, metadataValues);
|
||||
metadataValues.forEach((metadatum) => {
|
||||
if (metadatum.key === 'name' || metadata.isInPlaceUpdateValue(metadatum)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let column = this.createColumn(metadatum);
|
||||
this.configuration.addSingleColumnForObject(telemetryObject, column);
|
||||
// add units column if available
|
||||
if (metadatum.unit !== undefined) {
|
||||
let unitColumn = this.createUnitColumn(metadatum);
|
||||
this.configuration.addSingleColumnForObject(telemetryObject, unitColumn);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getColumnMapForObject(objectKeyString) {
|
||||
let columns = this.configuration.getColumns();
|
||||
|
||||
if (columns[objectKeyString]) {
|
||||
return columns[objectKeyString].reduce((map, column) => {
|
||||
map[column.getKey()] = column;
|
||||
|
||||
return map;
|
||||
}, {});
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
buildOptionsFromConfiguration(telemetryObject) {
|
||||
let keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
let filters =
|
||||
this.domainObject.configuration &&
|
||||
this.domainObject.configuration.filters &&
|
||||
this.domainObject.configuration.filters[keyString];
|
||||
|
||||
return { filters } || {};
|
||||
}
|
||||
|
||||
createColumn(metadatum) {
|
||||
return new TelemetryTableColumn(this.openmct, metadatum);
|
||||
}
|
||||
|
||||
createUnitColumn(metadatum) {
|
||||
return new TelemetryTableUnitColumn(this.openmct, metadatum);
|
||||
}
|
||||
|
||||
isTelemetryObject(domainObject) {
|
||||
return Object.prototype.hasOwnProperty.call(domainObject, 'telemetry');
|
||||
}
|
||||
|
||||
sortBy(sortOptions) {
|
||||
this.tableRows.sortBy(sortOptions);
|
||||
|
||||
if (this.openmct.editor.isEditing()) {
|
||||
let configuration = this.configuration.getConfiguration();
|
||||
configuration.sortOptions = sortOptions;
|
||||
this.configuration.updateConfiguration(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
runDelayedActions() {
|
||||
this.delayedActions.forEach((action) => action());
|
||||
this.delayedActions = [];
|
||||
}
|
||||
|
||||
removeTelemetryCollection(keyString) {
|
||||
if (this.telemetryCollections[keyString]) {
|
||||
this.telemetryCollections[keyString].destroy();
|
||||
this.telemetryCollections[keyString] = undefined;
|
||||
delete this.telemetryCollections[keyString];
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
this.paused = true;
|
||||
}
|
||||
|
||||
unpause() {
|
||||
this.paused = false;
|
||||
this.runDelayedActions();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.tableRows.destroy();
|
||||
|
||||
this.tableRows.off('resetRowsFromAllData', this.resetRowsFromAllData);
|
||||
this.openmct.time.off('clockChanged', this.resubscribeToStaleness);
|
||||
|
||||
let keystrings = Object.keys(this.telemetryCollections);
|
||||
keystrings.forEach(this.removeTelemetryCollection);
|
||||
|
||||
if (this.filterObserver) {
|
||||
this.filterObserver();
|
||||
}
|
||||
|
||||
Object.values(this.stalenessSubscription).forEach((stalenessSubscription) => {
|
||||
stalenessSubscription.unsubscribe();
|
||||
stalenessSubscription.stalenessUtils.destroy();
|
||||
});
|
||||
|
||||
if (this.tableComposition !== undefined) {
|
||||
this.tableComposition.off('add', this.addTelemetryObject);
|
||||
this.tableComposition.off('remove', this.removeTelemetryObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user