mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 05:38:12 +00:00
add comps manager
This commit is contained in:
@ -0,0 +1,50 @@
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
|
||||
export default class CompsManager extends EventEmitter {
|
||||
#openmct;
|
||||
#domainObject;
|
||||
#telemetryObjects = {};
|
||||
#telemetryCollections = {};
|
||||
|
||||
constructor(openmct, domainObject) {
|
||||
super();
|
||||
this.#openmct = openmct;
|
||||
this.#domainObject = domainObject;
|
||||
}
|
||||
|
||||
#removeTelemetryObject(telemetryObject) {
|
||||
const keyString = this.#openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
delete this.#telemetryObjects[keyString];
|
||||
this.#telemetryCollections[keyString]?.destroy();
|
||||
delete this.#telemetryCollections[keyString];
|
||||
}
|
||||
|
||||
telemetryProcessor(telemetryObjects) {
|
||||
console.debug('Telemetry Processor', telemetryObjects);
|
||||
}
|
||||
|
||||
clearData() {
|
||||
console.debug('Clear Data');
|
||||
}
|
||||
|
||||
#addTelemetryObject(telemetryObject) {
|
||||
const keyString = this.#openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
this.#telemetryObjects[keyString] = telemetryObject;
|
||||
this.#telemetryCollections[keyString] =
|
||||
this.#openmct.telemetry.requestCollection(telemetryObject);
|
||||
|
||||
this.#telemetryCollections[keyString].on('add', this.telemetryProcessor);
|
||||
this.#telemetryCollections[keyString].on('clear', this.clearData);
|
||||
this.#telemetryCollections[keyString].load();
|
||||
}
|
||||
|
||||
static getCompsManager(domainObject, openmct, compsManagerPool) {
|
||||
const id = openmct.objects.makeKeyString(domainObject.identifier);
|
||||
|
||||
if (!compsManagerPool[id]) {
|
||||
compsManagerPool[id] = new CompsManager(domainObject, this.openmct);
|
||||
}
|
||||
|
||||
return compsManagerPool[id];
|
||||
}
|
||||
}
|
||||
|
@ -29,45 +29,6 @@ export default class CompsTelemetryProvider {
|
||||
|
||||
constructor(openmct) {
|
||||
this.#openmct = openmct;
|
||||
this.#loadComposition();
|
||||
this.#startSharedWorker();
|
||||
}
|
||||
|
||||
async #loadComposition() {
|
||||
this.#composition = this.#openmct.composition.get(this.domainObject);
|
||||
if (this.#composition) {
|
||||
await this.#composition.load();
|
||||
// load all of our telemetry objects
|
||||
this.#composition.forEach(this.#addTelemetryObject);
|
||||
|
||||
this.#composition.on('add', this.#addTelemetryObject);
|
||||
this.#composition.on('remove', this.#removeTelemetryObject);
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.#composition.off('add', this.#addTelemetryObject);
|
||||
this.#composition.off('remove', this.removeTelemetryObject);
|
||||
}
|
||||
|
||||
#addTelemetryObject(telemetryObject) {
|
||||
const keyString = this.#openmct.objects.makeKeyString(telemetryObject.identifier);
|
||||
this.#telemetryObjects[keyString] = telemetryObject;
|
||||
this.#telemetryCollections[keyString] =
|
||||
this.#openmct.telemetry.requestCollection(telemetryObject);
|
||||
|
||||
this.#telemetryCollections[keyString].on('add', this.#telemetryProcessor);
|
||||
this.#telemetryCollections[keyString].on('clear', this.#clearData);
|
||||
this.#telemetryCollections[keyString].load();
|
||||
}
|
||||
|
||||
#telemetryProcessor(telemetryObjects) {
|
||||
console.debug('📡 Processing telemetry:', telemetryObjects);
|
||||
}
|
||||
|
||||
#clearData() {
|
||||
// clear data
|
||||
console.debug('🆑 Clearing data');
|
||||
}
|
||||
|
||||
#removeTelemetryObject(telemetryObject) {
|
||||
|
@ -27,11 +27,12 @@ import CompsView from './components/CompsView.vue';
|
||||
const DEFAULT_VIEW_PRIORITY = 100;
|
||||
|
||||
export default class ConditionSetViewProvider {
|
||||
constructor(openmct) {
|
||||
constructor(openmct, compsManagerPool) {
|
||||
this.openmct = openmct;
|
||||
this.name = 'Comps View';
|
||||
this.key = 'comps.view';
|
||||
this.cssClass = 'icon-telemetry';
|
||||
this.compsManagerPool = compsManagerPool;
|
||||
}
|
||||
|
||||
canView(domainObject, objectPath) {
|
||||
@ -57,14 +58,15 @@ export default class ConditionSetViewProvider {
|
||||
provide: {
|
||||
openmct: this.openmct,
|
||||
domainObject,
|
||||
objectPath
|
||||
objectPath,
|
||||
compsManagerPool: this.compsManagerPool
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isEditing
|
||||
};
|
||||
},
|
||||
template: '<comps :isEditing="isEditing"></comps>'
|
||||
template: '<CompsView :isEditing="isEditing"></CompsView>'
|
||||
},
|
||||
{
|
||||
app: this.openmct.app,
|
||||
|
@ -21,19 +21,45 @@
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div class="u-contents"></div>
|
||||
<div class="u-contents">This is the comps view</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
inject: ['openmct', 'domainObject'],
|
||||
mounted() { },
|
||||
beforeUnmount() {
|
||||
if (this.unobserve) {
|
||||
this.unobserve();
|
||||
}
|
||||
<script setup>
|
||||
import { inject, onBeforeUnmount, onMounted } from 'vue';
|
||||
|
||||
this.openmct.time.off('tick', this.tick);
|
||||
}
|
||||
};
|
||||
import CompsManager from '../CompsManager';
|
||||
|
||||
const openmct = inject('openmct');
|
||||
const domainObject = inject('domainObject');
|
||||
const compsManagerPool = inject('compsManagerPool');
|
||||
const compsManager = CompsManager.getCompsManager(domainObject, openmct, compsManagerPool);
|
||||
const composition = openmct.composition.get(domainObject);
|
||||
|
||||
onMounted(() => {
|
||||
loadComposition();
|
||||
console.debug('🚀 CompsView: onMounted with compsManager', compsManager);
|
||||
});
|
||||
|
||||
async function loadComposition() {
|
||||
if (composition) {
|
||||
composition.on('add', addTelemetryObject);
|
||||
composition.on('remove', removeTelemetryObject);
|
||||
await composition.load();
|
||||
}
|
||||
}
|
||||
|
||||
function addTelemetryObject(object) {
|
||||
console.debug('📢 CompsView: addTelemetryObject', object);
|
||||
}
|
||||
|
||||
function removeTelemetryObject(object) {
|
||||
console.debug('❌ CompsView: removeTelemetryObject', object);
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (composition) {
|
||||
composition.off('add', addTelemetryObject);
|
||||
composition.off('remove', removeTelemetryObject);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -23,6 +23,8 @@ import CompsTelemetryProvider from './CompsTelemetryProvider.js';
|
||||
import CompsViewProvider from './CompsViewProvider.js';
|
||||
|
||||
export default function CompsPlugin() {
|
||||
const compsManagerPool = {};
|
||||
|
||||
return function install(openmct) {
|
||||
openmct.types.addType('comps', {
|
||||
name: 'Comps',
|
||||
@ -40,7 +42,7 @@ export default function CompsPlugin() {
|
||||
openmct.composition.addPolicy((parent, child) => {
|
||||
return openmct.telemetry.isTelemetryObject(child);
|
||||
});
|
||||
openmct.telemetry.addProvider(new CompsTelemetryProvider(openmct));
|
||||
openmct.objectViews.addProvider(new CompsViewProvider(openmct));
|
||||
openmct.telemetry.addProvider(new CompsTelemetryProvider(openmct, compsManagerPool));
|
||||
openmct.objectViews.addProvider(new CompsViewProvider(openmct, compsManagerPool));
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user