From 5b6f95bd4ae52df3fb7d9156a5fdc3e02b2e8770 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 8 Nov 2016 14:59:09 -0800 Subject: [PATCH] [Fixed] Specify default layout grid (#1296) * [Fixed] Specify default layout grid Previously users would see blank values for grid size even though a default was applied. Users will now see default values for grid size which should prevent them from accidentally changing grid size. Fixes https://github.com/nasa/openmct/issues/1285 * [Fixed] Don't hardcode grid size Remove hardcoded grid size per comments. https://github.com/nasa/openmct/pull/1296#issuecomment-259231499 * [Fixed] read layout before initial refresh Read the layoutGrid sizes from scope (when watch is registered) before refreshing elements, to ensure that layoutGrid is set properly. https://github.com/nasa/openmct/pull/1296#issuecomment-259231499 * [Spec] Update spec to match Update spec to trigger watch on initialization to ensure layoutGrid is set. https://github.com/nasa/openmct/pull/1296 --- platform/features/fixed/bundle.js | 1 + platform/features/layout/src/FixedController.js | 12 +++++------- platform/features/layout/test/FixedControllerSpec.js | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/features/fixed/bundle.js b/platform/features/fixed/bundle.js index e2e40ff511..9f98750178 100644 --- a/platform/features/fixed/bundle.js +++ b/platform/features/fixed/bundle.js @@ -204,6 +204,7 @@ define([ } ], "model": { + "layoutGrid": [64, 16], "composition": [] }, "properties": [ diff --git a/platform/features/layout/src/FixedController.js b/platform/features/layout/src/FixedController.js index 42c9565a68..e5345cb46a 100644 --- a/platform/features/layout/src/FixedController.js +++ b/platform/features/layout/src/FixedController.js @@ -24,8 +24,7 @@ define( ['./FixedProxy', './elements/ElementProxies', './FixedDragHandle'], function (FixedProxy, ElementProxies, FixedDragHandle) { - var DEFAULT_DIMENSIONS = [2, 1], - DEFAULT_GRID_SIZE = [64, 16]; + var DEFAULT_DIMENSIONS = [2, 1]; /** * The FixedController is responsible for supporting the @@ -132,7 +131,7 @@ define( // Update element positions when grid size changes function updateElementPositions(layoutGrid) { // Update grid size from model - self.gridSize = layoutGrid || DEFAULT_GRID_SIZE; + self.gridSize = layoutGrid; self.elementProxies.forEach(function (elementProxy) { elementProxy.style = convertPosition(elementProxy); @@ -293,7 +292,6 @@ define( }); } - this.gridSize = DEFAULT_GRID_SIZE; this.elementProxies = []; this.generateDragHandle = generateDragHandle; this.generateDragHandles = generateDragHandles; @@ -310,15 +308,15 @@ define( } }.bind(this)); + // Detect changes to grid size + $scope.$watch("model.layoutGrid", updateElementPositions); + // Refresh list of elements whenever model changes $scope.$watch("model.modified", refreshElements); // Position panes when the model field changes $scope.$watch("model.composition", updateComposition); - // Detect changes to grid size - $scope.$watch("model.layoutGrid", updateElementPositions); - // 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 12b1b63b55..190658b4f9 100644 --- a/platform/features/layout/test/FixedControllerSpec.js +++ b/platform/features/layout/test/FixedControllerSpec.js @@ -147,6 +147,7 @@ define( mockFormatter ); + findWatch("model.layoutGrid")(testModel.layoutGrid); findWatch("selection")(mockScope.selection); });