mirror of
https://github.com/nasa/openmct.git
synced 2025-01-30 16:13:53 +00:00
[Inspector] Listen for mutation and refresh composition
...so that elements pool is updated when selected object's composition changes. Fixes #1869
This commit is contained in:
parent
0363d0e8ad
commit
d4e3e6689c
@ -52,8 +52,20 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setSelection(selection) {
|
function setSelection(selection) {
|
||||||
self.scope.selection = selection;
|
if (!selection[0]) {
|
||||||
self.refreshComposition(selection);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.mutationListener) {
|
||||||
|
self.mutationListener();
|
||||||
|
delete self.mutationListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
var domainObject = selection[0].context.oldItem;
|
||||||
|
self.refreshComposition(domainObject);
|
||||||
|
|
||||||
|
self.mutationListener = domainObject.getCapability('mutation')
|
||||||
|
.listen(self.refreshComposition.bind(self, domainObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.filterBy = filterBy;
|
$scope.filterBy = filterBy;
|
||||||
@ -70,16 +82,11 @@ define(
|
|||||||
/**
|
/**
|
||||||
* Gets the composition for the selected object and populates the scope with it.
|
* Gets the composition for the selected object and populates the scope with it.
|
||||||
*
|
*
|
||||||
* @param selection the selection object
|
* @param domainObject the selected object
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ElementsController.prototype.refreshComposition = function (selection) {
|
ElementsController.prototype.refreshComposition = function (domainObject) {
|
||||||
if (!selection[0]) {
|
var selectedObjectComposition = domainObject.useCapability('composition');
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selected = selection[0].context.oldItem;
|
|
||||||
var selectedObjectComposition = selected && selected.useCapability('composition');
|
|
||||||
|
|
||||||
if (selectedObjectComposition) {
|
if (selectedObjectComposition) {
|
||||||
selectedObjectComposition.then(function (composition) {
|
selectedObjectComposition.then(function (composition) {
|
||||||
|
@ -29,9 +29,25 @@ define(
|
|||||||
var mockScope,
|
var mockScope,
|
||||||
mockOpenMCT,
|
mockOpenMCT,
|
||||||
mockSelection,
|
mockSelection,
|
||||||
|
mockDomainObject,
|
||||||
|
mockMutationCapability,
|
||||||
|
mockUnlisten,
|
||||||
|
selectable = [],
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
mockUnlisten = jasmine.createSpy('unlisten');
|
||||||
|
mockMutationCapability = jasmine.createSpyObj("mutationCapability", [
|
||||||
|
"listen"
|
||||||
|
]);
|
||||||
|
mockMutationCapability.listen.andReturn(mockUnlisten);
|
||||||
|
mockDomainObject = jasmine.createSpyObj("domainObject", [
|
||||||
|
"getCapability",
|
||||||
|
"useCapability"
|
||||||
|
]);
|
||||||
|
mockDomainObject.useCapability.andCallThrough();
|
||||||
|
mockDomainObject.getCapability.andReturn(mockMutationCapability);
|
||||||
|
|
||||||
mockScope = jasmine.createSpyObj("$scope", ['$on']);
|
mockScope = jasmine.createSpyObj("$scope", ['$on']);
|
||||||
mockSelection = jasmine.createSpyObj("selection", [
|
mockSelection = jasmine.createSpyObj("selection", [
|
||||||
'on',
|
'on',
|
||||||
@ -43,6 +59,14 @@ define(
|
|||||||
selection: mockSelection
|
selection: mockSelection
|
||||||
};
|
};
|
||||||
|
|
||||||
|
selectable[0] = {
|
||||||
|
context: {
|
||||||
|
oldItem: mockDomainObject
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(ElementsController.prototype, 'refreshComposition');
|
||||||
|
|
||||||
controller = new ElementsController(mockScope, mockOpenMCT);
|
controller = new ElementsController(mockScope, mockOpenMCT);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -75,6 +99,34 @@ define(
|
|||||||
expect(objects.filter(mockScope.searchElements).length).toBe(4);
|
expect(objects.filter(mockScope.searchElements).length).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("refreshes composition on selection", function () {
|
||||||
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
||||||
|
|
||||||
|
expect(ElementsController.prototype.refreshComposition).toHaveBeenCalledWith(mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("listens on mutation and refreshes composition", function () {
|
||||||
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
||||||
|
|
||||||
|
expect(mockDomainObject.getCapability).toHaveBeenCalledWith('mutation');
|
||||||
|
expect(mockMutationCapability.listen).toHaveBeenCalled();
|
||||||
|
expect(ElementsController.prototype.refreshComposition.calls.length).toBe(1);
|
||||||
|
|
||||||
|
mockMutationCapability.listen.mostRecentCall.args[0](mockDomainObject);
|
||||||
|
|
||||||
|
expect(ElementsController.prototype.refreshComposition.calls.length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("cleans up mutation listener when selection changes", function () {
|
||||||
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
||||||
|
|
||||||
|
expect(mockMutationCapability.listen).toHaveBeenCalled();
|
||||||
|
|
||||||
|
mockOpenMCT.selection.on.mostRecentCall.args[1](selectable);
|
||||||
|
|
||||||
|
expect(mockUnlisten).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user