Skip to content

Commit a2bf92d

Browse files
committed
[Tables] Subscribe to parent if a telemetry object, or children, but not both. Fixes nasa#1464
1 parent 6fa5a31 commit a2bf92d

File tree

2 files changed

+115
-38
lines changed

2 files changed

+115
-38
lines changed

platform/features/table/src/controllers/TelemetryTableController.js

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ define(
7272
* Create a new format object from legacy object, and replace it
7373
* when it changes
7474
*/
75-
this.newObject = objectUtils.toNewFormat($scope.domainObject.getModel(),
75+
this.domainObject = objectUtils.toNewFormat($scope.domainObject.getModel(),
7676
$scope.domainObject.getId());
7777

7878
_.bindAll(this, [
@@ -144,9 +144,9 @@ define(
144144
this.unobserveObject();
145145
}
146146

147-
this.unobserveObject = this.openmct.objects.observe(this.newObject, "*",
147+
this.unobserveObject = this.openmct.objects.observe(this.domainObject, "*",
148148
function (domainObject) {
149-
this.newObject = domainObject;
149+
this.domainObject = domainObject;
150150
this.getData();
151151
}.bind(this)
152152
);
@@ -399,17 +399,50 @@ define(
399399
return objects;
400400
};
401401

402+
/**
403+
* Return an array of telemetry objects in this view that should be
404+
* subscribed to.
405+
* @private
406+
* @returns {Promise<Array>} a promise that resolves with an array of
407+
* telemetry objects in this view.
408+
*/
409+
TelemetryTableController.prototype.getTelemetryObjects = function () {
410+
var telemetryApi = this.openmct.telemetry;
411+
var compositionApi = this.openmct.composition;
412+
413+
function filterForTelemetry(objects) {
414+
return objects.filter(telemetryApi.canProvideTelemetry.bind(telemetryApi));
415+
}
416+
417+
/*
418+
* If parent object is a telemetry object, subscribe to it. Do not
419+
* test composees.
420+
*/
421+
if (telemetryApi.canProvideTelemetry(this.domainObject)) {
422+
return Promise.resolve([this.domainObject]);
423+
} else {
424+
/*
425+
* If parent object is not a telemetry object, subscribe to all
426+
* composees that are telemetry producing objects.
427+
*/
428+
var composition = compositionApi.get(this.domainObject);
429+
430+
if (composition) {
431+
return composition
432+
.load()
433+
.then(filterForTelemetry);
434+
}
435+
}
436+
};
437+
402438
/**
403439
* Request historical data, and subscribe to for real-time data.
404440
* @private
405441
* @returns {Promise} A promise that is resolved once subscription is
406442
* established, and historical telemetry is received and processed.
407443
*/
408444
TelemetryTableController.prototype.getData = function () {
409-
var telemetryApi = this.openmct.telemetry;
410-
var compositionApi = this.openmct.composition;
411445
var scope = this.$scope;
412-
var newObject = this.newObject;
413446

414447
this.telemetry.clear();
415448
this.telemetry.bounds(this.openmct.conductor.bounds());
@@ -421,28 +454,9 @@ define(
421454
console.error(e.stack);
422455
}
423456

424-
function filterForTelemetry(objects) {
425-
return objects.filter(telemetryApi.canProvideTelemetry.bind(telemetryApi));
426-
}
427-
428-
function getDomainObjects() {
429-
var objects = [newObject];
430-
var composition = compositionApi.get(newObject);
431-
432-
if (composition) {
433-
return composition
434-
.load()
435-
.then(function (children) {
436-
return objects.concat(children);
437-
});
438-
} else {
439-
return Promise.resolve(objects);
440-
}
441-
}
442457
scope.rows = [];
443458

444-
return getDomainObjects()
445-
.then(filterForTelemetry)
459+
return this.getTelemetryObjects()
446460
.then(this.loadColumns)
447461
.then(this.subscribeToNewData)
448462
.then(this.getHistoricalData)

platform/features/table/test/controllers/TelemetryTableControllerSpec.js

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ define(
161161
});
162162
});
163163

164-
describe ('Subscribes to new data', function () {
164+
describe ('when getting telemetry', function () {
165165
var mockComposition,
166166
mockTelemetryObject,
167167
mockChildren,
@@ -173,9 +173,7 @@ define(
173173
"load"
174174
]);
175175

176-
mockTelemetryObject = jasmine.createSpyObj("mockTelemetryObject", [
177-
"something"
178-
]);
176+
mockTelemetryObject = {};
179177
mockTelemetryObject.identifier = {
180178
key: "mockTelemetryObject"
181179
};
@@ -192,22 +190,41 @@ define(
192190
});
193191

194192
done = false;
193+
});
194+
195+
it('fetches historical data for the time period specified by the conductor bounds', function () {
195196
controller.getData().then(function () {
196197
done = true;
197198
});
199+
waitsFor(function () {
200+
return done;
201+
}, "getData to return", 100);
202+
203+
runs(function () {
204+
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, mockBounds);
205+
});
198206
});
199207

200-
it('fetches historical data', function () {
208+
it('unsubscribes on view destruction', function () {
209+
controller.getData().then(function () {
210+
done = true;
211+
});
212+
201213
waitsFor(function () {
202214
return done;
203215
}, "getData to return", 100);
204216

205217
runs(function () {
206-
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
218+
var destroy = getCallback(mockScope.$on, "$destroy");
219+
destroy();
220+
221+
expect(unsubscribe).toHaveBeenCalled();
207222
});
208223
});
209-
210224
it('fetches historical data for the time period specified by the conductor bounds', function () {
225+
controller.getData().then(function () {
226+
done = true;
227+
});
211228
waitsFor(function () {
212229
return done;
213230
}, "getData to return", 100);
@@ -217,26 +234,72 @@ define(
217234
});
218235
});
219236

220-
it('subscribes to new data', function () {
237+
it('fetches data for, and subscribes to parent object if it is a telemetry object', function () {
238+
controller.getData().then(function () {
239+
done = true;
240+
});
221241
waitsFor(function () {
222242
return done;
223243
}, "getData to return", 100);
224244

225245
runs(function () {
226246
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {});
247+
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
227248
});
249+
});
250+
it('fetches data for, and subscribes to parent object if it is a telemetry object', function () {
251+
controller.getData().then(function () {
252+
done = true;
253+
});
254+
waitsFor(function () {
255+
return done;
256+
}, "getData to return", 100);
228257

258+
runs(function () {
259+
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Function), {});
260+
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(mockTelemetryObject, jasmine.any(Object));
261+
});
229262
});
230-
it('and unsubscribes on view destruction', function () {
263+
264+
it('fetches data for, and subscribes to any composees that are telemetry objects if parent is not', function () {
265+
mockChildren = [
266+
{name: "child 1"}
267+
];
268+
var mockTelemetryChildren = [
269+
{name: "child 2"},
270+
{name: "child 3"},
271+
{name: "child 4"}
272+
];
273+
mockChildren = mockChildren.concat(mockTelemetryChildren);
274+
mockComposition.load.andReturn(Promise.resolve(mockChildren));
275+
276+
mockTelemetryAPI.canProvideTelemetry.andCallFake(function (object) {
277+
if (object === mockTelemetryObject) {
278+
return false;
279+
} else {
280+
return mockTelemetryChildren.indexOf(object) !== -1;
281+
}
282+
});
283+
284+
controller.getData().then(function () {
285+
done = true;
286+
});
287+
231288
waitsFor(function () {
232289
return done;
233290
}, "getData to return", 100);
234291

235292
runs(function () {
236-
var destroy = getCallback(mockScope.$on, "$destroy");
237-
destroy();
293+
mockTelemetryChildren.forEach(function (child) {
294+
expect(mockTelemetryAPI.subscribe).toHaveBeenCalledWith(child, jasmine.any(Function), {});
295+
});
238296

239-
expect(unsubscribe).toHaveBeenCalled();
297+
mockTelemetryChildren.forEach(function (child) {
298+
expect(mockTelemetryAPI.request).toHaveBeenCalledWith(child, jasmine.any(Object));
299+
});
300+
301+
expect(mockTelemetryAPI.subscribe).not.toHaveBeenCalledWith(mockChildren[0], jasmine.any(Function), {});
302+
expect(mockTelemetryAPI.subscribe).not.toHaveBeenCalledWith(mockTelemetryObject[0], jasmine.any(Function), {});
240303
});
241304
});
242305
});

0 commit comments

Comments
 (0)