From 2b4517cff634ce7247bc5c93b839fac126360737 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 27 Jan 2015 10:22:50 -0800 Subject: [PATCH] [Layout] Update on composition change Update frame positions when model.composition changes, instead of when model changes. Ensures correct display after changes to avoid redrawing on every update, WTD-716. --- platform/features/layout/src/LayoutController.js | 9 ++++----- .../features/layout/test/LayoutControllerSpec.js | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/platform/features/layout/src/LayoutController.js b/platform/features/layout/src/LayoutController.js index 9ebab58017..70a5126d78 100644 --- a/platform/features/layout/src/LayoutController.js +++ b/platform/features/layout/src/LayoutController.js @@ -66,9 +66,8 @@ 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 || {}; // Pull panel positions from configuration rawPositions = shallowCopy(configuration.panels || {}, ids); @@ -77,14 +76,14 @@ 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); } // Position panes when the model field changes - $scope.$watch("model", lookupPanels); + $scope.$watch("model.composition", lookupPanels); return { /** diff --git a/platform/features/layout/test/LayoutControllerSpec.js b/platform/features/layout/test/LayoutControllerSpec.js index ba21822dec..f80b356d74 100644 --- a/platform/features/layout/test/LayoutControllerSpec.js +++ b/platform/features/layout/test/LayoutControllerSpec.js @@ -38,15 +38,15 @@ define( // Model changes will indicate that panel positions // may have changed, for instance. - it("watches for changes to model", function () { + it("watches for changes to composition", function () { expect(mockScope.$watch).toHaveBeenCalledWith( - "model", + "model.composition", jasmine.any(Function) ); }); it("provides styles for frames, from configuration", function () { - mockScope.$watch.mostRecentCall.args[1](testModel); + mockScope.$watch.mostRecentCall.args[1](testModel.composition); expect(controller.getFrameStyle("a")).toEqual({ top: "320px", left: "640px", @@ -59,7 +59,7 @@ define( var styleB, styleC; // b and c do not have configured positions - mockScope.$watch.mostRecentCall.args[1](testModel); + mockScope.$watch.mostRecentCall.args[1](testModel.composition); styleB = controller.getFrameStyle("b"); styleC = controller.getFrameStyle("c"); @@ -76,7 +76,7 @@ define( it("allows panels to be dragged", function () { // Populate scope - mockScope.$watch.mostRecentCall.args[1](testModel); + mockScope.$watch.mostRecentCall.args[1](testModel.composition); // Verify precondtion expect(testConfiguration.panels.b).not.toBeDefined(); @@ -95,7 +95,7 @@ define( it("invokes commit after drag", function () { // Populate scope - mockScope.$watch.mostRecentCall.args[1](testModel); + mockScope.$watch.mostRecentCall.args[1](testModel.composition); // Add a commit method to scope mockScope.commit = jasmine.createSpy("commit");