From 06b599ee3799e5ba809f803e18ed85ff7b1a458f Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Jan 2015 16:25:16 -0800 Subject: [PATCH 1/5] [Browse] Begin implementing splitter movement Begin implementing moveable splitter, WTD-747. --- .../commonUI/browse/res/templates/browse.html | 7 ++-- platform/commonUI/general/bundle.json | 8 +++++ .../res/templates/containers/split-pane.html | 9 +++++ .../src/controllers/SplitPaneController.js | 36 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 platform/commonUI/general/res/templates/containers/split-pane.html create mode 100644 platform/commonUI/general/src/controllers/SplitPaneController.js diff --git a/platform/commonUI/browse/res/templates/browse.html b/platform/commonUI/browse/res/templates/browse.html index f7faeede26..db8d015ac8 100644 --- a/platform/commonUI/browse/res/templates/browse.html +++ b/platform/commonUI/browse/res/templates/browse.html @@ -2,7 +2,7 @@
-
+
@@ -12,13 +12,12 @@
-
-
+
-
+
diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 00e73a1568..58ba7c61f1 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -84,6 +84,10 @@ "key": "GetterSetterController", "implementation": "controllers/GetterSetterController.js", "depends": [ "$scope" ] + }, + { + "key": "SplitPaneController", + "implementation": "controllers/SplitPaneController.js" } ], "directives": [ @@ -108,6 +112,10 @@ "key": "accordion", "templateUrl": "templates/containers/accordion.html", "attributes": [ "title" ] + }, + { + "key": "splitter", + "templateUrl": "templates/containers/split-pane.html" } ], "representations": [ diff --git a/platform/commonUI/general/res/templates/containers/split-pane.html b/platform/commonUI/general/res/templates/containers/split-pane.html new file mode 100644 index 0000000000..05dc2a5df3 --- /dev/null +++ b/platform/commonUI/general/res/templates/containers/split-pane.html @@ -0,0 +1,9 @@ + +
+
+
+
+
\ No newline at end of file diff --git a/platform/commonUI/general/src/controllers/SplitPaneController.js b/platform/commonUI/general/src/controllers/SplitPaneController.js new file mode 100644 index 0000000000..0f7b314f13 --- /dev/null +++ b/platform/commonUI/general/src/controllers/SplitPaneController.js @@ -0,0 +1,36 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + function SplitPaneController() { + var minimum = 8, + maximum = 600, + current = 200, + style; + + function updateStyle() { + style = { left: current + 'px' }; + } + + updateStyle(); + + return { + style: function () { + return style; + }, + move: function (delta) { + current = Math.min( + maximum, + Math.max(minimum, current + delta) + ); + updateStyle(); + } + }; + } + + return SplitPaneController; + } +); \ No newline at end of file From 8fecaaf4f813f9934ef60167bec32f92af58af14 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Jan 2015 16:34:03 -0800 Subject: [PATCH 2/5] [Browse] Utilize splite pane directly Utilize split pane controller directly from browse template; quick fix for need to see more information about packet/point names, WTD-747. --- .../commonUI/browse/res/templates/browse.html | 15 +++++++++++---- .../src/controllers/SplitPaneController.js | 11 +++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/platform/commonUI/browse/res/templates/browse.html b/platform/commonUI/browse/res/templates/browse.html index db8d015ac8..89fdc122b2 100644 --- a/platform/commonUI/browse/res/templates/browse.html +++ b/platform/commonUI/browse/res/templates/browse.html @@ -1,8 +1,10 @@
-
-
+
+
@@ -12,12 +14,17 @@
- +
+
- +
diff --git a/platform/commonUI/general/src/controllers/SplitPaneController.js b/platform/commonUI/general/src/controllers/SplitPaneController.js index 0f7b314f13..4a2e06bda8 100644 --- a/platform/commonUI/general/src/controllers/SplitPaneController.js +++ b/platform/commonUI/general/src/controllers/SplitPaneController.js @@ -6,9 +6,10 @@ define( "use strict"; function SplitPaneController() { - var minimum = 8, + var minimum = 120, maximum = 600, current = 200, + start = 200, style; function updateStyle() { @@ -21,10 +22,16 @@ define( style: function () { return style; }, + state: function () { + return current; + }, + startMove: function () { + start = current; + }, move: function (delta) { current = Math.min( maximum, - Math.max(minimum, current + delta) + Math.max(minimum, start + delta) ); updateStyle(); } From 14571ebb6ea77d6b9c8e39a003d0431300db63f7 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Jan 2015 16:38:32 -0800 Subject: [PATCH 3/5] [Browse] Add JSDoc Add in-line documentation to controller which supports the moveable splitter in Browse mode, WTD-747. --- .../src/controllers/SplitPaneController.js | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/platform/commonUI/general/src/controllers/SplitPaneController.js b/platform/commonUI/general/src/controllers/SplitPaneController.js index 4a2e06bda8..85ecb6061a 100644 --- a/platform/commonUI/general/src/controllers/SplitPaneController.js +++ b/platform/commonUI/general/src/controllers/SplitPaneController.js @@ -5,35 +5,46 @@ define( function () { "use strict"; + /** + * Controller for the splitter in Browse mode. Current implementation + * uses many hard-coded constants; this could be generalized. + * @constructor + */ function SplitPaneController() { var minimum = 120, maximum = 600, current = 200, - start = 200, - style; - - function updateStyle() { - style = { left: current + 'px' }; - } - - updateStyle(); + start = 200; return { - style: function () { - return style; - }, + /** + * Get the current position of the splitter, in pixels + * from the left edge. + * @returns {number} position of the splitter, in pixels + */ state: function () { return current; }, + /** + * Begin moving the splitter; this will note the splitter's + * current position, which is necessary for correct + * interpretation of deltas provided by mct-drag. + */ startMove: function () { start = current; }, + /** + * Move the splitter a number of pixels to the right + * (negative numbers move the splitter to the left.) + * This movement is relative to the position of the + * splitter when startMove was last invoked. + * @param {number} delta number of pixels to move + */ move: function (delta) { current = Math.min( maximum, Math.max(minimum, start + delta) ); - updateStyle(); } }; } From c0a1e0a0d4885cbe8526b10b3387714b2f8db045 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Jan 2015 16:43:18 -0800 Subject: [PATCH 4/5] [Browse] Add spec for SplitPaneController Add unit test for controller which supports the moveable splitter in Browse mode, WTD-747. --- .../controllers/SplitPaneControllerSpec.js | 46 +++++++++++++++++++ platform/commonUI/general/test/suite.json | 1 + 2 files changed, 47 insertions(+) create mode 100644 platform/commonUI/general/test/controllers/SplitPaneControllerSpec.js diff --git a/platform/commonUI/general/test/controllers/SplitPaneControllerSpec.js b/platform/commonUI/general/test/controllers/SplitPaneControllerSpec.js new file mode 100644 index 0000000000..03b65dac62 --- /dev/null +++ b/platform/commonUI/general/test/controllers/SplitPaneControllerSpec.js @@ -0,0 +1,46 @@ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +define( + ["../../src/controllers/SplitPaneController"], + function (SplitPaneController) { + "use strict"; + + describe("The split pane controller", function () { + var controller; + + beforeEach(function () { + controller = new SplitPaneController(); + }); + + it("has an initial position", function () { + expect(controller.state() > 0).toBeTruthy(); + }); + + it("can be moved", function () { + var initialState = controller.state(); + controller.startMove(); + controller.move(50); + expect(controller.state()).toEqual(initialState + 50); + }); + + it("clamps its position", function () { + var initialState = controller.state(); + controller.startMove(); + // Move some really extreme number + controller.move(-100000); + // Shouldn't have moved below 0... + expect(controller.state() > 0).toBeTruthy(); + // ...but should have moved left somewhere + expect(controller.state() < initialState).toBeTruthy(); + + // Then do the same to the right + controller.move(100000); + // Shouldn't have moved below 0... + expect(controller.state() < 100000).toBeTruthy(); + // ...but should have moved left somewhere + expect(controller.state() > initialState).toBeTruthy(); + }); + + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/general/test/suite.json b/platform/commonUI/general/test/suite.json index 0aa52f1503..ae3a54f37b 100644 --- a/platform/commonUI/general/test/suite.json +++ b/platform/commonUI/general/test/suite.json @@ -4,6 +4,7 @@ "controllers/ClickAwayController", "controllers/ContextMenuController", "controllers/GetterSetterController", + "controllers/SplitPaneController", "controllers/ToggleController", "controllers/TreeNodeController", "controllers/ViewSwitcherController", From 92252b41d498ef2b470d2ada5b104952e869499a Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Jan 2015 16:45:20 -0800 Subject: [PATCH 5/5] [Browse] Remove unused container Remove unused container definition for split pane; this turned out not to be a suitable quick-fix approach to WTD-747 (implementation of this behavior directly from the browse template turned out to be more convenient.) --- platform/commonUI/general/bundle.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 58ba7c61f1..9a914b6e71 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -112,10 +112,6 @@ "key": "accordion", "templateUrl": "templates/containers/accordion.html", "attributes": [ "title" ] - }, - { - "key": "splitter", - "templateUrl": "templates/containers/split-pane.html" } ], "representations": [