mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 13:48:12 +00:00
Added mutation listener
This commit is contained in:
@ -57,9 +57,8 @@ define(
|
||||
this.table = new TableConfiguration($scope.domainObject,
|
||||
telemetryFormatter);
|
||||
this.changeListeners = [];
|
||||
this.initialized = false;
|
||||
|
||||
$scope.rows = undefined;
|
||||
$scope.rows = [];
|
||||
|
||||
// Subscribe to telemetry when a domain object becomes available
|
||||
this.$scope.$watch('domainObject', function(domainObject){
|
||||
@ -86,14 +85,22 @@ define(
|
||||
return listener && listener();
|
||||
});
|
||||
this.changeListeners = [];
|
||||
// When composition changes, re-subscribe to the various
|
||||
// telemetry subscriptions
|
||||
this.changeListeners.push(this.$scope.$watchCollection(
|
||||
'domainObject.getModel().composition', function(composition, oldComposition) {
|
||||
if (composition!== oldComposition) {
|
||||
self.subscribe();
|
||||
}
|
||||
}));
|
||||
|
||||
/**
|
||||
* Listen to all children for model mutation events that might
|
||||
* indicate that metadata is available, or that composition has
|
||||
* changed.
|
||||
*/
|
||||
if (this.$scope.domainObject.hasCapability('composition')) {
|
||||
this.$scope.domainObject.useCapability('composition').then(function (composees) {
|
||||
composees.forEach(function (composee) {
|
||||
self.changeListeners.push(composee.getCapability('mutation').listen(self.setup.bind(self)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//Register mutation listener for the parent itself
|
||||
self.changeListeners.push(self.$scope.domainObject.getCapability('mutation').listen(this.setup.bind(this)));
|
||||
|
||||
//Change of bounds in time conductor
|
||||
this.changeListeners.push(this.$scope.$on('telemetry:display:bounds',
|
||||
@ -117,8 +124,7 @@ define(
|
||||
*/
|
||||
TelemetryTableController.prototype.subscribe = function () {
|
||||
var self = this;
|
||||
this.initialized = false;
|
||||
this.$scope.rows = undefined;
|
||||
this.$scope.rows = [];
|
||||
|
||||
if (this.handle) {
|
||||
this.handle.unsubscribe();
|
||||
@ -126,10 +132,10 @@ define(
|
||||
|
||||
//Noop because not supporting realtime data right now
|
||||
function update(){
|
||||
if(!self.initialized){
|
||||
self.setup();
|
||||
//Is there anything to show?
|
||||
if (self.table.columns.length > 0){
|
||||
self.updateRealtime();
|
||||
}
|
||||
self.updateRealtime();
|
||||
}
|
||||
|
||||
this.handle = this.$scope.domainObject && this.telemetryHandler.handle(
|
||||
@ -137,8 +143,10 @@ define(
|
||||
update,
|
||||
true // Lossless
|
||||
);
|
||||
|
||||
this.handle.request({}).then(this.addHistoricalData.bind(this));
|
||||
|
||||
//Call setup at least once
|
||||
this.setup();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -175,33 +183,44 @@ define(
|
||||
*/
|
||||
TelemetryTableController.prototype.setup = function () {
|
||||
var handle = this.handle,
|
||||
domainObject = this.$scope.domainObject,
|
||||
table = this.table,
|
||||
self = this;
|
||||
self = this,
|
||||
metadatas = [];
|
||||
|
||||
//Is metadata available yet?
|
||||
if (handle) {
|
||||
table.buildColumns(handle.getMetadata());
|
||||
|
||||
self.filterColumns();
|
||||
|
||||
// When table column configuration changes, (due to being
|
||||
// selected or deselected), filter columns appropriately.
|
||||
self.changeListeners.push(self.$scope.$watchCollection(
|
||||
'domainObject.getModel().configuration.table.columns',
|
||||
self.filterColumns.bind(self)
|
||||
));
|
||||
self.initialized = true;
|
||||
function addMetadata(object) {
|
||||
if (object.hasCapability('telemetry') &&
|
||||
object.getCapability('telemetry').getMetadata()){
|
||||
metadatas.push(object.getCapability('telemetry').getMetadata());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param object The object for which data is available (table may
|
||||
* be composed of multiple objects)
|
||||
* @param datum The data received from the telemetry source
|
||||
*/
|
||||
TelemetryTableController.prototype.updateRows = function (object, datum) {
|
||||
this.$scope.rows.push(this.table.getRowValues(object, datum));
|
||||
function buildAndFilterColumns(){
|
||||
if (metadatas && metadatas.length > 0){
|
||||
self.$scope.rows = [];
|
||||
table.buildColumns(metadatas);
|
||||
self.filterColumns();
|
||||
}
|
||||
}
|
||||
|
||||
//if (handle) {
|
||||
//Add telemetry metadata (if any) for parent object
|
||||
addMetadata(domainObject);
|
||||
|
||||
//If object is composed of multiple objects, also add
|
||||
// telemetry metadata from children
|
||||
if (domainObject.hasCapability('composition')) {
|
||||
domainObject.useCapability('composition').then(function (composition) {
|
||||
composition.forEach(addMetadata);
|
||||
}).then(function () {
|
||||
//Build columns based on available metadata
|
||||
buildAndFilterColumns();
|
||||
});
|
||||
} else {
|
||||
//Build columns based on collected metadata
|
||||
buildAndFilterColumns();
|
||||
}
|
||||
// }
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user