From 4db2febbb3d0677d58f75c0381731a179e6c94fc Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 4 Dec 2014 13:22:39 -0800 Subject: [PATCH] [Layout] Add LayoutController Add a controller for Layouts to choose frame positions. WTD-535. --- platform/features/layout/bundle.json | 10 +++- .../features/layout/res/templates/frame.html | 10 ++-- .../features/layout/res/templates/layout.html | 19 ++++-- .../features/layout/src/LayoutController.js | 59 +++++++++++++++++++ 4 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 platform/features/layout/src/LayoutController.js diff --git a/platform/features/layout/bundle.json b/platform/features/layout/bundle.json index 7b918b3c26..67d91281fe 100644 --- a/platform/features/layout/bundle.json +++ b/platform/features/layout/bundle.json @@ -8,7 +8,8 @@ "name": "Layout", "glyph": "L", "type": "layout", - "templateUrl": "templates/layout.html" + "templateUrl": "templates/layout.html", + "uses": [ "composition" ] } ], "representations": [ @@ -17,6 +18,13 @@ "templateUrl": "templates/frame.html" } ], + "controllers": [ + { + "key": "LayoutController", + "implementation": "LayoutController.js", + "depends": [ "$scope" ] + } + ], "types": [ { "key": "layout", diff --git a/platform/features/layout/res/templates/frame.html b/platform/features/layout/res/templates/frame.html index 8140c3e1d0..8346615505 100644 --- a/platform/features/layout/res/templates/frame.html +++ b/platform/features/layout/res/templates/frame.html @@ -1,4 +1,4 @@ -
+
- - + +
diff --git a/platform/features/layout/res/templates/layout.html b/platform/features/layout/res/templates/layout.html index e4a33abdcc..4899dcf3f2 100644 --- a/platform/features/layout/res/templates/layout.html +++ b/platform/features/layout/res/templates/layout.html @@ -1,9 +1,16 @@ -
+
- - - - +
+ +
+ + +
+ +
\ No newline at end of file diff --git a/platform/features/layout/src/LayoutController.js b/platform/features/layout/src/LayoutController.js new file mode 100644 index 0000000000..f21502b495 --- /dev/null +++ b/platform/features/layout/src/LayoutController.js @@ -0,0 +1,59 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + var DEFAULT_DIMENSIONS = [ 4, 2 ]; + + function LayoutController($scope) { + var width = 16, + height = 16, + positions = {}; + + function convertPosition(position, dimensions) { + return { + left: (width * position[0]) + 'px', + top: (width * position[1]) + 'px', + width: (width * dimensions[0]) + 'px', + height: (height * dimensions[1]) + 'px' + }; + } + + function defaultPosition(index) { + return convertPosition([index, index], DEFAULT_DIMENSIONS); + } + + function lookupPanels(model) { + var configuration = + ((model || {}).configuration || {}).layout || {}; + + // Clear prior positions + positions = {}; + + // Update width/height that we are tracking + + // Pull values from panels field + + // Add defaults where needed + ((model || {}).composition || []).forEach(function (id, i) { + positions[id] = positions[id] || defaultPosition(i); + }); + } + + + + $scope.$watch("model", lookupPanels); + + return { + getFrameStyle: function (id) { + return positions[id]; + } + }; + + } + + return LayoutController; + } +); \ No newline at end of file