diff --git a/platform/features/layout/src/FixedController.js b/platform/features/layout/src/FixedController.js index 29fb15fafb..928dd770e8 100644 --- a/platform/features/layout/src/FixedController.js +++ b/platform/features/layout/src/FixedController.js @@ -90,9 +90,9 @@ define( } // Compute panel positions based on the layout's object model - function lookupPanels(model) { - var configuration = $scope.configuration || {}, - ids = (model || {}).composition || []; + function lookupPanels(ids) { + var configuration = $scope.configuration || {}; + ids = ids || []; // Pull panel positions from configuration rawPositions = shallowCopy(configuration.elements || {}, ids); @@ -101,7 +101,7 @@ define( positions = {}; // Update width/height that we are tracking - gridSize = (model || {}).layoutGrid || DEFAULT_GRID_SIZE; + gridSize = ($scope.model || {}).layoutGrid || DEFAULT_GRID_SIZE; // Compute positions and add defaults where needed ids.forEach(populatePosition); @@ -147,6 +147,14 @@ define( telemetrySubscriber.subscribe(domainObject, updateValues); } + // Handle changes in the object's composition + function updateComposition(ids) { + // Populate panel positions + lookupPanels(ids); + // Resubscribe - objects in view have changed + subscribe($scope.domainObject); + } + // Position a panel after a drop event function handleDrop(e, id, position) { // Make sure there is a "elements" field in the @@ -168,7 +176,7 @@ define( } // Position panes when the model field changes - $scope.$watch("model", lookupPanels); + $scope.$watch("model.composition", updateComposition); // Subscribe to telemetry when an object is available $scope.$watch("domainObject", subscribe); diff --git a/platform/features/layout/test/FixedControllerSpec.js b/platform/features/layout/test/FixedControllerSpec.js index 0293905909..8b5990069c 100644 --- a/platform/features/layout/test/FixedControllerSpec.js +++ b/platform/features/layout/test/FixedControllerSpec.js @@ -113,7 +113,7 @@ define( it("configures view based on model", function () { mockScope.model = testModel; - findWatch("model")(mockScope.model); + findWatch("model.composition")(mockScope.model.composition); // Should have styles for all elements of composition expect(controller.getStyle('a')).toBeDefined(); expect(controller.getStyle('b')).toBeDefined(); @@ -126,7 +126,7 @@ define( mockScope.domainObject = mockDomainObject; mockScope.model = testModel; findWatch("domainObject")(mockDomainObject); - findWatch("model")(mockScope.model); + findWatch("model.composition")(mockScope.model.composition); // Invoke the subscription callback mockSubscriber.subscribe.mostRecentCall.args[1](); @@ -148,7 +148,7 @@ define( }; mockScope.model = testModel; - findWatch("model")(mockScope.model); + findWatch("model.composition")(mockScope.model.composition); // Set first bounds controller.setBounds(s1);