diff --git a/platform/features/layout/src/FixedController.js b/platform/features/layout/src/FixedController.js index cec05fb800..fb9015db89 100644 --- a/platform/features/layout/src/FixedController.js +++ b/platform/features/layout/src/FixedController.js @@ -5,8 +5,7 @@ define( function (LayoutSelection, FixedProxy, ElementProxies, FixedDragHandle) { "use strict"; - var DEFAULT_DIMENSIONS = [ 2, 1 ], - DEFAULT_GRID_SIZE = [64, 16], + var DEFAULT_GRID_SIZE = [64, 16], DEFAULT_GRID_EXTENT = [4, 4]; /** @@ -29,6 +28,7 @@ define( elementProxiesById = {}, handles = [], moveHandle, + viewProxy, selection; // Refresh cell styles (e.g. because grid extent changed) @@ -198,14 +198,6 @@ define( telemetrySubscriber.subscribe(domainObject, updateValues); } - // Handle changes in the object's composition - function updateComposition(ids) { - // Populate panel positions - // TODO: Ensure defaults here - // Resubscribe - objects in view have changed - subscribe($scope.domainObject); - } - // Add an element to this view function addElement(element) { // Ensure that configuration field is populated @@ -226,29 +218,62 @@ define( } } + // Add a telemetry element to this view + function addTelemetryElement(id, x, y) { + viewProxy.add("fixed.telemetry", { id: id, x: x, y: y }); + } + + // Ensure that all telemetry elements have elements in view + function ensureElements(ids) { + var found = {}; + + // Track that a telemetry element is in the view + function track(element) { + if (element.type === 'fixed.telemetry') { + found[element.id] = true; + } + } + + // Used to filter down to elements not yet present + function notFound(id) { + return !found[id]; + } + + // Add a telemetry element + function add(id, index) { + addTelemetryElement(id, 0, index); + } + + // Build list of all found elements + (($scope.configuration || {}).elements || []).forEach(track); + + // Add in telemetry elements where needed + (ids || []).filter(notFound).forEach(add); + } + + // Handle changes in the object's composition + function updateComposition(ids) { + // Populate panel positions + ensureElements(ids); + // Resubscribe - objects in view have changed + subscribe($scope.domainObject); + } + // Position a panel after a drop event function handleDrop(e, id, position) { // Store the position of this element. - addElement({ - type: "fixed.telemetry", - x: Math.floor(position.x / gridSize[0]), - y: Math.floor(position.y / gridSize[1]), - id: id, - stroke: "transparent", - color: "#717171", - titled: true, - width: DEFAULT_DIMENSIONS[0], - height: DEFAULT_DIMENSIONS[1] - }); + addTelemetryElement( + id, + Math.floor(position.x / gridSize[0]), + Math.floor(position.y / gridSize[1]) + ); } // Track current selection state + viewProxy = new FixedProxy(addElement, $q, dialogService); if (Array.isArray($scope.selection)) { - selection = new LayoutSelection( - $scope.selection, - new FixedProxy(addElement, $q, dialogService) - ); + selection = new LayoutSelection($scope.selection, viewProxy); } // Refresh list of elements whenever model changes diff --git a/platform/features/layout/src/FixedProxy.js b/platform/features/layout/src/FixedProxy.js index 4b5b4312e0..846f16aa84 100644 --- a/platform/features/layout/src/FixedProxy.js +++ b/platform/features/layout/src/FixedProxy.js @@ -21,9 +21,14 @@ define( /** * Add a new visual element to this view. */ - add: function (type) { + add: function (type, state) { // Place a configured element into the view configuration function addElement(element) { + // Populate element with additional state + Object.keys(state || {}).forEach(function (k) { + element[k] = state[k]; + }); + // Configure common properties of the element element.x = element.x || 0; element.y = element.y || 0; diff --git a/platform/features/layout/src/elements/ElementFactory.js b/platform/features/layout/src/elements/ElementFactory.js index 3ae8cad80a..708d7c6d24 100644 --- a/platform/features/layout/src/elements/ElementFactory.js +++ b/platform/features/layout/src/elements/ElementFactory.js @@ -25,6 +25,13 @@ define( fill: "transparent", stroke: "transparent", color: "#717171" + }, + "fixed.telemetry": { + stroke: "transparent", + color: "#717171", + titled: true, + width: 2, + height: 1 } }, DIALOGS = {