From 57eefd73164fbf0f008c5e2e162f8fa7e333c23a Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 30 Jun 2015 11:18:56 -0700 Subject: [PATCH 01/20] [Browse] Context menu gesture called The context menu gesture is called when the user clicks the arrow next to the title of a domain object. This does not yet display the context menu. It also does not yet distinguish between edit and browse mode. #33. --- platform/commonUI/general/bundle.json | 2 +- .../general/res/templates/tree-node.html | 2 +- .../src/controllers/TreeNodeController.js | 24 +++++++++++++++++-- .../src/gestures/ContextMenuGesture.js | 6 ++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 2093a988cd..e5da0b81ef 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -60,7 +60,7 @@ { "key": "TreeNodeController", "implementation": "controllers/TreeNodeController.js", - "depends": [ "$scope", "$timeout" ] + "depends": [ "$scope", "$timeout", "$rootScope" ] }, { "key": "ActionGroupController", diff --git a/platform/commonUI/general/res/templates/tree-node.html b/platform/commonUI/general/res/templates/tree-node.html index f584befb1a..e61cd405cd 100644 --- a/platform/commonUI/general/res/templates/tree-node.html +++ b/platform/commonUI/general/res/templates/tree-node.html @@ -27,7 +27,7 @@ > {{toggle.isActive() ? "v" : ">"}} diff --git a/platform/commonUI/general/src/controllers/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js index cfb70357bb..a51d85448e 100644 --- a/platform/commonUI/general/src/controllers/TreeNodeController.js +++ b/platform/commonUI/general/src/controllers/TreeNodeController.js @@ -50,7 +50,7 @@ define( * expand-to-show-navigated-object behavior.) * @constructor */ - function TreeNodeController($scope, $timeout) { + function TreeNodeController($scope, $timeout, $rootScope) { var selectedObject = ($scope.ngModel || {}).selectedObject, isSelected = false, hasBeenExpanded = false; @@ -138,6 +138,20 @@ define( selectedObject = object; checkSelection(); } + + // If we are in edit mode, then a left-click on the + // down arrow next to a domain object's title should display + // a context menu + function contextMenu() { + //console.log('contextMenu() called'); + + if ($scope.domainObject.hasCapability('editor') || true) { + //console.log('contextMenu() believes in edit mode'); + + $rootScope.$broadcast('leftContextual'); + console.log('contextMenu() broadcasted from root'); + } + } // Listen for changes which will effect display parameters $scope.$watch("ngModel.selectedObject", setSelection); @@ -166,7 +180,13 @@ define( */ isSelected: function () { return isSelected; - } + }, + /** + * This method should be called when the down arrow next + * to a domain object's title is (left) clicked. If in edit + * mode, this activates a context menu. + */ + contextMenu: contextMenu }; } diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 83ea1ddc23..28e0f1ad30 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -60,7 +60,10 @@ define( goLeft = eventCoors[0] + menuDim[0] > winDim[0], goUp = eventCoors[1] + menuDim[1] > winDim[1], menu; - + + //console.log('in showMenu() in ContextMenuGesture'); + //console.log('domainObject is ', domainObject); + // Remove the context menu function dismiss() { menu.remove(); @@ -104,6 +107,7 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', showMenu); + $rootScope.$on('leftContextual', showMenu); return { /** From 7b4ef142f56c11df1485a2c2e45b83b0f47fde82 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 30 Jun 2015 13:32:25 -0700 Subject: [PATCH 02/20] [Browse] Fixed tree nodes Realized that this refers to a previously hidden arrow at the main title at the top of the page. Reverted the changes done to the tree nodes. #33. --- .../general/res/templates/tree-node.html | 2 +- .../src/controllers/TreeNodeController.js | 22 +------------------ 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/platform/commonUI/general/res/templates/tree-node.html b/platform/commonUI/general/res/templates/tree-node.html index e61cd405cd..f584befb1a 100644 --- a/platform/commonUI/general/res/templates/tree-node.html +++ b/platform/commonUI/general/res/templates/tree-node.html @@ -27,7 +27,7 @@ > {{toggle.isActive() ? "v" : ">"}} diff --git a/platform/commonUI/general/src/controllers/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js index a51d85448e..77124bb6e3 100644 --- a/platform/commonUI/general/src/controllers/TreeNodeController.js +++ b/platform/commonUI/general/src/controllers/TreeNodeController.js @@ -139,20 +139,6 @@ define( checkSelection(); } - // If we are in edit mode, then a left-click on the - // down arrow next to a domain object's title should display - // a context menu - function contextMenu() { - //console.log('contextMenu() called'); - - if ($scope.domainObject.hasCapability('editor') || true) { - //console.log('contextMenu() believes in edit mode'); - - $rootScope.$broadcast('leftContextual'); - console.log('contextMenu() broadcasted from root'); - } - } - // Listen for changes which will effect display parameters $scope.$watch("ngModel.selectedObject", setSelection); $scope.$watch("domainObject", checkSelection); @@ -180,13 +166,7 @@ define( */ isSelected: function () { return isSelected; - }, - /** - * This method should be called when the down arrow next - * to a domain object's title is (left) clicked. If in edit - * mode, this activates a context menu. - */ - contextMenu: contextMenu + } }; } From 917d98bd3e744c9497a7131cda601369da05e18b Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 30 Jun 2015 13:33:40 -0700 Subject: [PATCH 03/20] [Browse] Created Menu Arrow Created a menu-arrow respresentation. #33. --- platform/commonUI/browse/bundle.json | 10 ++++ .../res/templates/browse/object-header.html | 5 +- .../browse/res/templates/menu-arrow.html | 26 +++++++++ .../browse/src/MenuArrowController.js | 53 +++++++++++++++++++ platform/commonUI/general/bundle.json | 2 +- .../src/gestures/ContextMenuGesture.js | 10 ++-- 6 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 platform/commonUI/browse/res/templates/menu-arrow.html create mode 100644 platform/commonUI/browse/src/MenuArrowController.js diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index e10f3e9048..9221ac049d 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -32,6 +32,11 @@ "key": "LocatorController", "implementation": "creation/LocatorController", "depends": [ "$scope" ] + }, + { + "key": "MenuArrowController", + "implementation": "MenuArrowController", + "depends": [ "$rootScope" ] } ], "controls": [ @@ -71,6 +76,11 @@ "key": "object-header", "templateUrl": "templates/browse/object-header.html", "uses": [ "type" ] + }, + { + "key": "menu-arrow", + "templateUrl": "templates/menu-arrow.html", + "uses": [ "type" ] } ], "services": [ diff --git a/platform/commonUI/browse/res/templates/browse/object-header.html b/platform/commonUI/browse/res/templates/browse/object-header.html index eb13bb3764..48f494466e 100644 --- a/platform/commonUI/browse/res/templates/browse/object-header.html +++ b/platform/commonUI/browse/res/templates/browse/object-header.html @@ -25,6 +25,9 @@ {{parameters.mode}} {{type.getName()}} {{model.name}} - + + \ No newline at end of file diff --git a/platform/commonUI/browse/res/templates/menu-arrow.html b/platform/commonUI/browse/res/templates/menu-arrow.html new file mode 100644 index 0000000000..dc92358e0c --- /dev/null +++ b/platform/commonUI/browse/res/templates/menu-arrow.html @@ -0,0 +1,26 @@ + + + + v + \ No newline at end of file diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js new file mode 100644 index 0000000000..55ae7632c0 --- /dev/null +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -0,0 +1,53 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define*/ + +/** + * Module defining ObjectHeaderController. Created by shale on 06/30/2015. + */ +define( + [], + function () { + "use strict"; + + /** + * A left-click on the menu arrow should display a + * context menu. This controller launches the context + * menu. + * @constructor + */ + function MenuArrowController($rootScope) { + + function contextMenu() { + console.log('contextMenu() called'); + + $rootScope.$broadcast('contextmenu'); + } + + return { + contextMenu: contextMenu + }; + } + + return MenuArrowController; + } +); \ No newline at end of file diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index e5da0b81ef..2093a988cd 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -60,7 +60,7 @@ { "key": "TreeNodeController", "implementation": "controllers/TreeNodeController.js", - "depends": [ "$scope", "$timeout", "$rootScope" ] + "depends": [ "$scope", "$timeout" ] }, { "key": "ActionGroupController", diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 28e0f1ad30..58b08e12b9 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -61,8 +61,7 @@ define( goUp = eventCoors[1] + menuDim[1] > winDim[1], menu; - //console.log('in showMenu() in ContextMenuGesture'); - //console.log('domainObject is ', domainObject); + console.log('in showMenu() in ContextMenuGesture'); // Remove the context menu function dismiss() { @@ -92,6 +91,8 @@ define( "context-menu-holder": true }; + console.log(scope); + // Create the context menu menu = $compile(MENU_TEMPLATE)(scope); @@ -107,7 +108,10 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', showMenu); - $rootScope.$on('leftContextual', showMenu); + + // This allows actions besides only right-clicks to trigger a + // context menu + $rootScope.$on('contextmenu', showMenu); return { /** From 4840345524be019bbfe069fe48f2b45b7ce1a2c2 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 30 Jun 2015 15:22:10 -0700 Subject: [PATCH 04/20] [Browse] Stopped multiple broadcasts Stopped the menu arrow from making multiple broadcasts of contextmenu. #33. --- platform/commonUI/browse/bundle.json | 5 +++-- .../commonUI/browse/src/MenuArrowController.js | 8 ++++++-- .../src/gestures/ContextMenuGesture.js | 15 ++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 9221ac049d..d9a7b006c3 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -36,7 +36,7 @@ { "key": "MenuArrowController", "implementation": "MenuArrowController", - "depends": [ "$rootScope" ] + "depends": [ "$rootScope", "$scope" ] } ], "controls": [ @@ -80,7 +80,8 @@ { "key": "menu-arrow", "templateUrl": "templates/menu-arrow.html", - "uses": [ "type" ] + "uses": [ "action" ], + "gestures": [ "menu" ] } ], "services": [ diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 55ae7632c0..7ac009872c 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -35,12 +35,16 @@ define( * menu. * @constructor */ - function MenuArrowController($rootScope) { + function MenuArrowController($rootScope, $scope) { function contextMenu() { console.log('contextMenu() called'); + //console.log('editor? ', $scope.domainObject.hasCapability('editor')); - $rootScope.$broadcast('contextmenu'); + if (true || $scope.domainObject.hasCapability('editor')) { + //$rootScope.$broadcast('contextmenu'); + $scope.$emit('contextmenu'); + } } return { diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 58b08e12b9..70e518fddc 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -51,6 +51,8 @@ define( * in the context menu will be performed */ function ContextMenuGesture($compile, $document, $window, $rootScope, element, domainObject) { + var turnOffMenu; + function showMenu(event) { var winDim = [$window.innerWidth, $window.innerHeight], eventCoors = [event.pageX, event.pageY], @@ -91,10 +93,12 @@ define( "context-menu-holder": true }; - console.log(scope); + console.log("scope ", scope); // Create the context menu menu = $compile(MENU_TEMPLATE)(scope); + + console.log("menu ", menu); // Add the menu to the body body.append(menu); @@ -109,10 +113,10 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', showMenu); - // This allows actions besides only right-clicks to trigger a - // context menu - $rootScope.$on('contextmenu', showMenu); - + // This allows actions besides right-clicks to trigger a context menu + // Assigning turnOffMenu to stop multiple pickups of the broadcast + turnOffMenu = $rootScope.$on('contextmenu', showMenu); + return { /** * Detach any event handlers associated with this gesture, @@ -126,6 +130,7 @@ define( dismissExistingMenu(); } element.off('contextmenu', showMenu); + turnOffMenu(); } }; } From 9ad1c25d5366e870a0f5b95597c090d56a5755ba Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 30 Jun 2015 16:17:00 -0700 Subject: [PATCH 05/20] [Browse] Splitting up Menu Gesture Splitting up the context menu gesture's functionality into separate context menu gesture and context menu actions. The gesture watches for right-clicks, while the action displays the menu. #33. --- platform/commonUI/browse/bundle.json | 2 +- .../browse/res/templates/menu-arrow.html | 2 +- .../browse/src/MenuArrowController.js | 14 +- platform/representation/bundle.json | 7 + .../src/actions/ContextMenuAction.js | 135 ++++++++++++++++++ .../src/gestures/ContextMenuGesture.js | 106 ++------------ 6 files changed, 161 insertions(+), 105 deletions(-) create mode 100644 platform/representation/src/actions/ContextMenuAction.js diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index d9a7b006c3..1869e0d8f9 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -36,7 +36,7 @@ { "key": "MenuArrowController", "implementation": "MenuArrowController", - "depends": [ "$rootScope", "$scope" ] + "depends": [ "$scope" ] } ], "controls": [ diff --git a/platform/commonUI/browse/res/templates/menu-arrow.html b/platform/commonUI/browse/res/templates/menu-arrow.html index dc92358e0c..e266d92d68 100644 --- a/platform/commonUI/browse/res/templates/menu-arrow.html +++ b/platform/commonUI/browse/res/templates/menu-arrow.html @@ -22,5 +22,5 @@ v + ng-click='menuArrow.showMenu($event)'>v \ No newline at end of file diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 7ac009872c..5507cf67f6 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -35,20 +35,22 @@ define( * menu. * @constructor */ - function MenuArrowController($rootScope, $scope) { + function MenuArrowController($scope) { - function contextMenu() { + function showMenu(event) { console.log('contextMenu() called'); //console.log('editor? ', $scope.domainObject.hasCapability('editor')); - + /* if (true || $scope.domainObject.hasCapability('editor')) { - //$rootScope.$broadcast('contextmenu'); - $scope.$emit('contextmenu'); + $scope.$emit('contextmenu', event); } + */ + + $scope.domainObject.getCapability('action').perform({key: 'contextMenu', event: event}); } return { - contextMenu: contextMenu + showMenu: showMenu }; } diff --git a/platform/representation/bundle.json b/platform/representation/bundle.json index c9872367aa..b3d24a790d 100644 --- a/platform/representation/bundle.json +++ b/platform/representation/bundle.json @@ -49,6 +49,13 @@ "implementation": "services/DndService.js", "depends": [ "$log" ] } + ], + "actions": [ + { + "key": "contextMenu", + "implementation": "actions/ContextMenuAction.js", + "depends": [ "$compile", "$document", "$window", "$rootScope" ] + } ] } } diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js new file mode 100644 index 0000000000..cc08936edd --- /dev/null +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -0,0 +1,135 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,Promise*/ + +/** + * Module defining ContextMenuAction. Created by shale on 06/30/2015. + */ +define( + ["../gestures/GestureConstants"], + function (GestureConstants) { + "use strict"; + + var MENU_TEMPLATE = "" + + "", + dismissExistingMenu; + + /** + * Add listeners to a representation such that it launches a + * custom context menu for the domain object it contains. + * + * @constructor + * @param $compile Angular's $compile service + * @param $document the current document + * @param $window the active window + * @param $rootScope Angular's root scope + * @param element the jqLite-wrapped element which should exhibit + * the context mennu + * @param {DomainObject} domainObject the object on which actions + * in the context menu will be performed + */ + function ContextMenuAction($compile, $document, $window, $rootScope, element, domainObject) { + var turnOffMenu; + + function showMenu(event) { + var winDim = [$window.innerWidth, $window.innerHeight], + eventCoors = [event.pageX, event.pageY], + menuDim = GestureConstants.MCT_MENU_DIMENSIONS, + body = $document.find('body'), + scope = $rootScope.$new(), + goLeft = eventCoors[0] + menuDim[0] > winDim[0], + goUp = eventCoors[1] + menuDim[1] > winDim[1], + menu; + + console.log('in showMenu() in ContextMenuAction'); + + // Remove the context menu + function dismiss() { + menu.remove(); + body.off("click", dismiss); + dismissExistingMenu = undefined; + } + + // Dismiss any menu which was already showing + if (dismissExistingMenu) { + dismissExistingMenu(); + } + + // ...and record the presence of this menu. + dismissExistingMenu = dismiss; + + // Set up the scope, including menu positioning + scope.domainObject = domainObject; + scope.menuStyle = {}; + scope.menuStyle[goLeft ? "right" : "left"] = + (goLeft ? (winDim[0] - eventCoors[0]) : eventCoors[0]) + 'px'; + scope.menuStyle[goUp ? "bottom" : "top"] = + (goUp ? (winDim[1] - eventCoors[1]) : eventCoors[1]) + 'px'; + scope.menuClass = { + "go-left": goLeft, + "go-up": goUp, + "context-menu-holder": true + }; + + console.log("ContextMenuAction scope ", scope); + + // Create the context menu + menu = $compile(MENU_TEMPLATE)(scope); + + console.log("ContextMenuAction menu ", menu); + + // Add the menu to the body + body.append(menu); + + // Dismiss the menu when body is clicked elsewhere + body.on('click', dismiss); + + // Don't launch browser's context menu + event.preventDefault(); + } + + return { + /** + * Detach any event handlers associated with this gesture, + * and dismiss any visible menu. + * @method + * @memberof ContextMenuGesture + */ + destroy: function () { + // Scope has been destroyed, so remove all listeners. + if (dismissExistingMenu) { + dismissExistingMenu(); + } + element.off('contextmenu', showMenu); + if (turnOffMenu) { + turnOffMenu(); + } + } + }; + } + + return ContextMenuAction; + } +); \ No newline at end of file diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 70e518fddc..d390fdc386 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -22,117 +22,29 @@ /*global define,Promise*/ /** - * Module defining ContextMenuGesture. Created by vwoeltje on 11/17/14. + * Module defining ContextMenuGesture. + * Created by vwoeltje on 11/17/14. Modified by shale on 06/30/2015. */ define( - ["./GestureConstants"], - function (GestureConstants) { + function () { "use strict"; - var MENU_TEMPLATE = "" + - "", - dismissExistingMenu; - /** - * Add listeners to a representation such that it launches a - * custom context menu for the domain object it contains. + * Add listeners to a representation such that it calls the + * context menu action for the domain object it contains. * * @constructor - * @param $compile Angular's $compile service - * @param $document the current document - * @param $window the active window - * @param $rootScope Angular's root scope * @param element the jqLite-wrapped element which should exhibit * the context mennu * @param {DomainObject} domainObject the object on which actions * in the context menu will be performed */ - function ContextMenuGesture($compile, $document, $window, $rootScope, element, domainObject) { - var turnOffMenu; + function ContextMenuGesture(element, domainObject) { - function showMenu(event) { - var winDim = [$window.innerWidth, $window.innerHeight], - eventCoors = [event.pageX, event.pageY], - menuDim = GestureConstants.MCT_MENU_DIMENSIONS, - body = $document.find('body'), - scope = $rootScope.$new(), - goLeft = eventCoors[0] + menuDim[0] > winDim[0], - goUp = eventCoors[1] + menuDim[1] > winDim[1], - menu; - - console.log('in showMenu() in ContextMenuGesture'); - - // Remove the context menu - function dismiss() { - menu.remove(); - body.off("click", dismiss); - dismissExistingMenu = undefined; - } - - // Dismiss any menu which was already showing - if (dismissExistingMenu) { - dismissExistingMenu(); - } - - // ...and record the presence of this menu. - dismissExistingMenu = dismiss; - - // Set up the scope, including menu positioning - scope.domainObject = domainObject; - scope.menuStyle = {}; - scope.menuStyle[goLeft ? "right" : "left"] = - (goLeft ? (winDim[0] - eventCoors[0]) : eventCoors[0]) + 'px'; - scope.menuStyle[goUp ? "bottom" : "top"] = - (goUp ? (winDim[1] - eventCoors[1]) : eventCoors[1]) + 'px'; - scope.menuClass = { - "go-left": goLeft, - "go-up": goUp, - "context-menu-holder": true - }; - - console.log("scope ", scope); - - // Create the context menu - menu = $compile(MENU_TEMPLATE)(scope); - - console.log("menu ", menu); - - // Add the menu to the body - body.append(menu); - - // Dismiss the menu when body is clicked elsewhere - body.on('click', dismiss); - - // Don't launch browser's context menu - event.preventDefault(); - } - // When context menu event occurs, show object actions instead - element.on('contextmenu', showMenu); - - // This allows actions besides right-clicks to trigger a context menu - // Assigning turnOffMenu to stop multiple pickups of the broadcast - turnOffMenu = $rootScope.$on('contextmenu', showMenu); - - return { - /** - * Detach any event handlers associated with this gesture, - * and dismiss any visible menu. - * @method - * @memberof ContextMenuGesture - */ - destroy: function () { - // Scope has been destroyed, so remove all listeners. - if (dismissExistingMenu) { - dismissExistingMenu(); - } - element.off('contextmenu', showMenu); - turnOffMenu(); - } - }; + element.on('contextmenu', function () { + domainObject.getCapability('action').perform({key: "contextMenu", event: $event}); + }); } return ContextMenuGesture; From e9989ae00df73036e707a25a6ad5704355b00903 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Wed, 1 Jul 2015 14:32:49 -0700 Subject: [PATCH 06/20] [Browse] Some progress Still doesn't work. --- platform/commonUI/browse/bundle.json | 2 +- .../res/templates/browse/object-header.html | 3 - .../browse/src/MenuArrowController.js | 18 ++- platform/representation/bundle.json | 2 +- .../src/actions/ContextMenuAction.js | 121 +++++++++--------- .../src/gestures/ContextMenuGesture.js | 24 +++- 6 files changed, 95 insertions(+), 75 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 1869e0d8f9..20ccbbe5ad 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -36,7 +36,7 @@ { "key": "MenuArrowController", "implementation": "MenuArrowController", - "depends": [ "$scope" ] + "depends": [ "$scope", "$route", "objectService" ] } ], "controls": [ diff --git a/platform/commonUI/browse/res/templates/browse/object-header.html b/platform/commonUI/browse/res/templates/browse/object-header.html index 48f494466e..895761f514 100644 --- a/platform/commonUI/browse/res/templates/browse/object-header.html +++ b/platform/commonUI/browse/res/templates/browse/object-header.html @@ -25,9 +25,6 @@ {{parameters.mode}} {{type.getName()}} {{model.name}} - \ No newline at end of file diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 5507cf67f6..0623b62400 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -22,12 +22,15 @@ /*global define*/ /** - * Module defining ObjectHeaderController. Created by shale on 06/30/2015. + * Module defining MenuArrowController. Created by shale on 06/30/2015. */ define( [], function () { "use strict"; + + var ROOT_ID = "ROOT", + DEFAULT_PATH = "mine"; /** * A left-click on the menu arrow should display a @@ -35,10 +38,10 @@ define( * menu. * @constructor */ - function MenuArrowController($scope) { + function MenuArrowController($scope, $route, domainObject) { function showMenu(event) { - console.log('contextMenu() called'); + console.log('showMenu() called'); //console.log('editor? ', $scope.domainObject.hasCapability('editor')); /* if (true || $scope.domainObject.hasCapability('editor')) { @@ -46,9 +49,14 @@ define( } */ - $scope.domainObject.getCapability('action').perform({key: 'contextMenu', event: event}); + //console.log('domainObject ', domainObject); + //console.log('$scope.domainObject ', $scope.domainObject); + console.log('event ', event); + + //$scope.domainObject.getCapability('action').perform({key: 'contextMenu', event: event}); + domainObject.getCapability('action').perform({key: 'contextMenu', event: event}); } - + return { showMenu: showMenu }; diff --git a/platform/representation/bundle.json b/platform/representation/bundle.json index b3d24a790d..231a73c461 100644 --- a/platform/representation/bundle.json +++ b/platform/representation/bundle.json @@ -26,7 +26,7 @@ { "key": "menu", "implementation": "gestures/ContextMenuGesture.js", - "depends": [ "$compile", "$document", "$window", "$rootScope" ] + "depends": [] } ], "components": [ diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index cc08936edd..ba929bb170 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -50,82 +50,77 @@ define( * @param {DomainObject} domainObject the object on which actions * in the context menu will be performed */ - function ContextMenuAction($compile, $document, $window, $rootScope, element, domainObject) { - var turnOffMenu; + function ContextMenuAction($compile, $document, $window, $rootScope, element, domainObject, event) { + //var turnOffMenu; + console.log('in ContextMenuAction'); + console.log('contextMenuAction event ', event); - function showMenu(event) { - var winDim = [$window.innerWidth, $window.innerHeight], - eventCoors = [event.pageX, event.pageY], - menuDim = GestureConstants.MCT_MENU_DIMENSIONS, - body = $document.find('body'), - scope = $rootScope.$new(), - goLeft = eventCoors[0] + menuDim[0] > winDim[0], - goUp = eventCoors[1] + menuDim[1] > winDim[1], - menu; - - console.log('in showMenu() in ContextMenuAction'); - - // Remove the context menu - function dismiss() { - menu.remove(); - body.off("click", dismiss); - dismissExistingMenu = undefined; - } + //function showMenu(event) { + var winDim = [$window.innerWidth, $window.innerHeight], + eventCoors = [event.pageX, event.pageY], + menuDim = GestureConstants.MCT_MENU_DIMENSIONS, + body = $document.find('body'), + scope = $rootScope.$new(), + goLeft = eventCoors[0] + menuDim[0] > winDim[0], + goUp = eventCoors[1] + menuDim[1] > winDim[1], + menu; - // Dismiss any menu which was already showing - if (dismissExistingMenu) { - dismissExistingMenu(); - } - - // ...and record the presence of this menu. - dismissExistingMenu = dismiss; - - // Set up the scope, including menu positioning - scope.domainObject = domainObject; - scope.menuStyle = {}; - scope.menuStyle[goLeft ? "right" : "left"] = - (goLeft ? (winDim[0] - eventCoors[0]) : eventCoors[0]) + 'px'; - scope.menuStyle[goUp ? "bottom" : "top"] = - (goUp ? (winDim[1] - eventCoors[1]) : eventCoors[1]) + 'px'; - scope.menuClass = { - "go-left": goLeft, - "go-up": goUp, - "context-menu-holder": true - }; - - console.log("ContextMenuAction scope ", scope); - - // Create the context menu - menu = $compile(MENU_TEMPLATE)(scope); - - console.log("ContextMenuAction menu ", menu); - - // Add the menu to the body - body.append(menu); - - // Dismiss the menu when body is clicked elsewhere - body.on('click', dismiss); - - // Don't launch browser's context menu - event.preventDefault(); + // Remove the context menu + function dismiss() { + menu.remove(); + body.off("click", dismiss); + dismissExistingMenu = undefined; } + + // Dismiss any menu which was already showing + if (dismissExistingMenu) { + dismissExistingMenu(); + } + + // ...and record the presence of this menu. + dismissExistingMenu = dismiss; + + // Set up the scope, including menu positioning + scope.domainObject = domainObject; + scope.menuStyle = {}; + scope.menuStyle[goLeft ? "right" : "left"] = + (goLeft ? (winDim[0] - eventCoors[0]) : eventCoors[0]) + 'px'; + scope.menuStyle[goUp ? "bottom" : "top"] = + (goUp ? (winDim[1] - eventCoors[1]) : eventCoors[1]) + 'px'; + scope.menuClass = { + "go-left": goLeft, + "go-up": goUp, + "context-menu-holder": true + }; + + console.log("ContextMenuAction scope ", scope); + + // Create the context menu + menu = $compile(MENU_TEMPLATE)(scope); + + console.log("ContextMenuAction menu ", menu); + + // Add the menu to the body + body.append(menu); + + // Dismiss the menu when body is clicked elsewhere + body.on('click', dismiss); + + // Don't launch browser's context menu + event.preventDefault(); + //} return { /** - * Detach any event handlers associated with this gesture, - * and dismiss any visible menu. + * Dismiss any visible menu. * @method - * @memberof ContextMenuGesture + * @memberof ContextMenuAction */ destroy: function () { // Scope has been destroyed, so remove all listeners. if (dismissExistingMenu) { dismissExistingMenu(); } - element.off('contextmenu', showMenu); - if (turnOffMenu) { - turnOffMenu(); - } } }; } diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index d390fdc386..4b182d00b3 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -40,11 +40,31 @@ define( * in the context menu will be performed */ function ContextMenuGesture(element, domainObject) { + var actionContext, + stop; // When context menu event occurs, show object actions instead - element.on('contextmenu', function () { - domainObject.getCapability('action').perform({key: "contextMenu", event: $event}); + element.on('contextmenu', function (event) { + console.log('in ContextMenuGesture'); + console.log('domainObject ', domainObject); + console.log('domainObject action', domainObject.getCapability('action')); + console.log('domainObject actions', domainObject.getCapability('action').getActions('contextMenu')); + + + actionContext = {key: 'contextMenu', /*element: element,*/ domainObject: domainObject, event: event}; + stop = domainObject.getCapability('action').perform(actionContext); }); + + return { + /** + * Detach any event handlers associated with this gesture. + * @method + * @memberof ContextMenuGesture + */ + destroy: function () { + //element.off('contextmenu', stop.destroy); + } + }; } return ContextMenuGesture; From bb80b2175ce92a50d7764dc4b26528088e9a79ab Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 09:36:19 -0700 Subject: [PATCH 07/20] [Browse] Gesture calling action The context menu gesture (attempts) to call the context menu action. The menu arrow still fails to call. #33. --- platform/commonUI/browse/bundle.json | 2 +- .../browse/src/MenuArrowController.js | 31 +++++++++++-------- .../src/actions/ContextMenuAction.js | 7 +++-- .../src/gestures/ContextMenuGesture.js | 6 ++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 20ccbbe5ad..1869e0d8f9 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -36,7 +36,7 @@ { "key": "MenuArrowController", "implementation": "MenuArrowController", - "depends": [ "$scope", "$route", "objectService" ] + "depends": [ "$scope" ] } ], "controls": [ diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 0623b62400..7eae522810 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -38,25 +38,30 @@ define( * menu. * @constructor */ - function MenuArrowController($scope, $route, domainObject) { + function MenuArrowController($scope) { + var domainObject = $scope.domainObject, + context; function showMenu(event) { - console.log('showMenu() called'); - //console.log('editor? ', $scope.domainObject.hasCapability('editor')); /* - if (true || $scope.domainObject.hasCapability('editor')) { - $scope.$emit('contextmenu', event); - } + console.log('showMenu() called'); + + console.log('$scope ', $scope); + console.log('$scope.domainObject ', $scope.domainObject); + console.log('domainObject ', domainObject); + console.log('event ', event); */ - //console.log('domainObject ', domainObject); - //console.log('$scope.domainObject ', $scope.domainObject); - console.log('event ', event); - - //$scope.domainObject.getCapability('action').perform({key: 'contextMenu', event: event}); - domainObject.getCapability('action').perform({key: 'contextMenu', event: event}); + context = {key: 'contextMenu', event: event, domainObject: domainObject}; + domainObject.getCapability('action').perform(context); } - + + // attempt to set the domain object + $scope.$watch('domainObject', function (c) { + domainObject = c; + console.log('watcher called'); + }); + return { showMenu: showMenu }; diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index ba929bb170..42764af0d7 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -52,8 +52,11 @@ define( */ function ContextMenuAction($compile, $document, $window, $rootScope, element, domainObject, event) { //var turnOffMenu; + + /* console.log('in ContextMenuAction'); console.log('contextMenuAction event ', event); + */ //function showMenu(event) { var winDim = [$window.innerWidth, $window.innerHeight], @@ -93,12 +96,12 @@ define( "context-menu-holder": true }; - console.log("ContextMenuAction scope ", scope); + //console.log("ContextMenuAction scope ", scope); // Create the context menu menu = $compile(MENU_TEMPLATE)(scope); - console.log("ContextMenuAction menu ", menu); + //console.log("ContextMenuAction menu ", menu); // Add the menu to the body body.append(menu); diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 4b182d00b3..2cd7ea3afb 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -45,13 +45,15 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', function (event) { + /* console.log('in ContextMenuGesture'); + console.log('event ', event); console.log('domainObject ', domainObject); console.log('domainObject action', domainObject.getCapability('action')); console.log('domainObject actions', domainObject.getCapability('action').getActions('contextMenu')); + */ - - actionContext = {key: 'contextMenu', /*element: element,*/ domainObject: domainObject, event: event}; + actionContext = {key: 'contextMenu', domainObject: domainObject, event: event}; stop = domainObject.getCapability('action').perform(actionContext); }); From 3edd967e2763d099077fd939e1a1c60831ce948a Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 10:01:38 -0700 Subject: [PATCH 08/20] [Browse] Changed action key Changed the key for the context menu action from 'contextMenu' to 'menu'. #33. --- platform/commonUI/browse/src/MenuArrowController.js | 4 ++-- platform/representation/bundle.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 7eae522810..daa6527b77 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -52,14 +52,14 @@ define( console.log('event ', event); */ - context = {key: 'contextMenu', event: event, domainObject: domainObject}; + context = {key: 'menu', event: event, domainObject: domainObject}; domainObject.getCapability('action').perform(context); } // attempt to set the domain object $scope.$watch('domainObject', function (c) { domainObject = c; - console.log('watcher called'); + //console.log('watcher called'); }); return { diff --git a/platform/representation/bundle.json b/platform/representation/bundle.json index 231a73c461..5e94d5ab95 100644 --- a/platform/representation/bundle.json +++ b/platform/representation/bundle.json @@ -52,7 +52,7 @@ ], "actions": [ { - "key": "contextMenu", + "key": "menu", "implementation": "actions/ContextMenuAction.js", "depends": [ "$compile", "$document", "$window", "$rootScope" ] } From b965c48ff2ef30800a3a0418c0b21a139ace0eb5 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 10:54:43 -0700 Subject: [PATCH 09/20] [Browse] Fixed multiple clicks Fixed having multiple calls to ContextMenuGesture. #33. --- platform/commonUI/browse/src/MenuArrowController.js | 7 +------ .../representation/src/actions/ContextMenuAction.js | 12 +++++------- .../src/gestures/ContextMenuGesture.js | 4 +--- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index daa6527b77..e6ab84b5d3 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -29,9 +29,6 @@ define( function () { "use strict"; - var ROOT_ID = "ROOT", - DEFAULT_PATH = "mine"; - /** * A left-click on the menu arrow should display a * context menu. This controller launches the context @@ -43,14 +40,12 @@ define( context; function showMenu(event) { - /* console.log('showMenu() called'); console.log('$scope ', $scope); console.log('$scope.domainObject ', $scope.domainObject); console.log('domainObject ', domainObject); console.log('event ', event); - */ context = {key: 'menu', event: event, domainObject: domainObject}; domainObject.getCapability('action').perform(context); @@ -59,7 +54,7 @@ define( // attempt to set the domain object $scope.$watch('domainObject', function (c) { domainObject = c; - //console.log('watcher called'); + console.log('watcher called'); }); return { diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index 42764af0d7..432264e852 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -50,17 +50,15 @@ define( * @param {DomainObject} domainObject the object on which actions * in the context menu will be performed */ - function ContextMenuAction($compile, $document, $window, $rootScope, element, domainObject, event) { + function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) { //var turnOffMenu; - /* console.log('in ContextMenuAction'); console.log('contextMenuAction event ', event); - */ //function showMenu(event) { var winDim = [$window.innerWidth, $window.innerHeight], - eventCoors = [event.pageX, event.pageY], + eventCoors = [actionContext.event.pageX, actionContext.event.pageY], menuDim = GestureConstants.MCT_MENU_DIMENSIONS, body = $document.find('body'), scope = $rootScope.$new(), @@ -96,12 +94,12 @@ define( "context-menu-holder": true }; - //console.log("ContextMenuAction scope ", scope); + console.log("ContextMenuAction scope ", scope); // Create the context menu menu = $compile(MENU_TEMPLATE)(scope); - //console.log("ContextMenuAction menu ", menu); + console.log("ContextMenuAction menu ", menu); // Add the menu to the body body.append(menu); @@ -110,7 +108,7 @@ define( body.on('click', dismiss); // Don't launch browser's context menu - event.preventDefault(); + actionContext.event.preventDefault(); //} return { diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 2cd7ea3afb..592569f49b 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -45,13 +45,11 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', function (event) { - /* console.log('in ContextMenuGesture'); console.log('event ', event); console.log('domainObject ', domainObject); console.log('domainObject action', domainObject.getCapability('action')); console.log('domainObject actions', domainObject.getCapability('action').getActions('contextMenu')); - */ actionContext = {key: 'contextMenu', domainObject: domainObject, event: event}; stop = domainObject.getCapability('action').perform(actionContext); @@ -64,7 +62,7 @@ define( * @memberof ContextMenuGesture */ destroy: function () { - //element.off('contextmenu', stop.destroy); + element.off('contextmenu', stop); } }; } From 4e6301edb45d0674bc747e9d3d001f485ed6f2e3 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 10:54:43 -0700 Subject: [PATCH 10/20] [Browse] Fixed multiple clicks Fixed having multiple calls to ContextMenuGesture. #33. --- platform/commonUI/browse/src/MenuArrowController.js | 7 +------ .../representation/src/actions/ContextMenuAction.js | 12 +++++------- .../src/gestures/ContextMenuGesture.js | 6 ++---- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index daa6527b77..e6ab84b5d3 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -29,9 +29,6 @@ define( function () { "use strict"; - var ROOT_ID = "ROOT", - DEFAULT_PATH = "mine"; - /** * A left-click on the menu arrow should display a * context menu. This controller launches the context @@ -43,14 +40,12 @@ define( context; function showMenu(event) { - /* console.log('showMenu() called'); console.log('$scope ', $scope); console.log('$scope.domainObject ', $scope.domainObject); console.log('domainObject ', domainObject); console.log('event ', event); - */ context = {key: 'menu', event: event, domainObject: domainObject}; domainObject.getCapability('action').perform(context); @@ -59,7 +54,7 @@ define( // attempt to set the domain object $scope.$watch('domainObject', function (c) { domainObject = c; - //console.log('watcher called'); + console.log('watcher called'); }); return { diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index 42764af0d7..432264e852 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -50,17 +50,15 @@ define( * @param {DomainObject} domainObject the object on which actions * in the context menu will be performed */ - function ContextMenuAction($compile, $document, $window, $rootScope, element, domainObject, event) { + function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) { //var turnOffMenu; - /* console.log('in ContextMenuAction'); console.log('contextMenuAction event ', event); - */ //function showMenu(event) { var winDim = [$window.innerWidth, $window.innerHeight], - eventCoors = [event.pageX, event.pageY], + eventCoors = [actionContext.event.pageX, actionContext.event.pageY], menuDim = GestureConstants.MCT_MENU_DIMENSIONS, body = $document.find('body'), scope = $rootScope.$new(), @@ -96,12 +94,12 @@ define( "context-menu-holder": true }; - //console.log("ContextMenuAction scope ", scope); + console.log("ContextMenuAction scope ", scope); // Create the context menu menu = $compile(MENU_TEMPLATE)(scope); - //console.log("ContextMenuAction menu ", menu); + console.log("ContextMenuAction menu ", menu); // Add the menu to the body body.append(menu); @@ -110,7 +108,7 @@ define( body.on('click', dismiss); // Don't launch browser's context menu - event.preventDefault(); + actionContext.event.preventDefault(); //} return { diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 2cd7ea3afb..30f6905084 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -45,15 +45,13 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', function (event) { - /* console.log('in ContextMenuGesture'); console.log('event ', event); console.log('domainObject ', domainObject); console.log('domainObject action', domainObject.getCapability('action')); console.log('domainObject actions', domainObject.getCapability('action').getActions('contextMenu')); - */ - actionContext = {key: 'contextMenu', domainObject: domainObject, event: event}; + actionContext = {key: 'menu', domainObject: domainObject, event: event}; stop = domainObject.getCapability('action').perform(actionContext); }); @@ -64,7 +62,7 @@ define( * @memberof ContextMenuGesture */ destroy: function () { - //element.off('contextmenu', stop.destroy); + element.off('contextmenu', stop); } }; } From 30d8c1647c485397bddf1ef9a7e482928ffbeec0 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 11:30:45 -0700 Subject: [PATCH 11/20] [Browse] Right click works Right clicking for a context menu now works again. #33. --- .../src/actions/ContextMenuAction.js | 117 ++++++++---------- .../src/gestures/ContextMenuGesture.js | 2 +- 2 files changed, 55 insertions(+), 64 deletions(-) diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index 432264e852..c2368bdf95 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -37,79 +37,69 @@ define( dismissExistingMenu; /** - * Add listeners to a representation such that it launches a - * custom context menu for the domain object it contains. + * Launches a custom context menu for the domain object it contains. * * @constructor * @param $compile Angular's $compile service * @param $document the current document * @param $window the active window * @param $rootScope Angular's root scope - * @param element the jqLite-wrapped element which should exhibit - * the context mennu - * @param {DomainObject} domainObject the object on which actions - * in the context menu will be performed + * @param actionContexr the context in which the action + * should be performed */ function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) { - //var turnOffMenu; - console.log('in ContextMenuAction'); - console.log('contextMenuAction event ', event); - - //function showMenu(event) { - var winDim = [$window.innerWidth, $window.innerHeight], - eventCoors = [actionContext.event.pageX, actionContext.event.pageY], - menuDim = GestureConstants.MCT_MENU_DIMENSIONS, - body = $document.find('body'), - scope = $rootScope.$new(), - goLeft = eventCoors[0] + menuDim[0] > winDim[0], - goUp = eventCoors[1] + menuDim[1] > winDim[1], - menu; + function perform() { + //console.log('in perform()'); + var winDim = [$window.innerWidth, $window.innerHeight], + eventCoors = [actionContext.event.pageX, actionContext.event.pageY], + menuDim = GestureConstants.MCT_MENU_DIMENSIONS, + body = $document.find('body'), + scope = $rootScope.$new(), + goLeft = eventCoors[0] + menuDim[0] > winDim[0], + goUp = eventCoors[1] + menuDim[1] > winDim[1], + menu; - // Remove the context menu - function dismiss() { - menu.remove(); - body.off("click", dismiss); - dismissExistingMenu = undefined; + // Remove the context menu + function dismiss() { + menu.remove(); + body.off("click", dismiss); + dismissExistingMenu = undefined; + } + + // Dismiss any menu which was already showing + if (dismissExistingMenu) { + dismissExistingMenu(); + } + + // ...and record the presence of this menu. + dismissExistingMenu = dismiss; + + // Set up the scope, including menu positioning + scope.domainObject = actionContext.domainObject; + scope.menuStyle = {}; + scope.menuStyle[goLeft ? "right" : "left"] = + (goLeft ? (winDim[0] - eventCoors[0]) : eventCoors[0]) + 'px'; + scope.menuStyle[goUp ? "bottom" : "top"] = + (goUp ? (winDim[1] - eventCoors[1]) : eventCoors[1]) + 'px'; + scope.menuClass = { + "go-left": goLeft, + "go-up": goUp, + "context-menu-holder": true + }; + + // Create the context menu + menu = $compile(MENU_TEMPLATE)(scope); + + // Add the menu to the body + body.append(menu); + + // Dismiss the menu when body is clicked elsewhere + body.on('click', dismiss); + + // Don't launch browser's context menu + actionContext.event.preventDefault(); } - - // Dismiss any menu which was already showing - if (dismissExistingMenu) { - dismissExistingMenu(); - } - - // ...and record the presence of this menu. - dismissExistingMenu = dismiss; - - // Set up the scope, including menu positioning - scope.domainObject = domainObject; - scope.menuStyle = {}; - scope.menuStyle[goLeft ? "right" : "left"] = - (goLeft ? (winDim[0] - eventCoors[0]) : eventCoors[0]) + 'px'; - scope.menuStyle[goUp ? "bottom" : "top"] = - (goUp ? (winDim[1] - eventCoors[1]) : eventCoors[1]) + 'px'; - scope.menuClass = { - "go-left": goLeft, - "go-up": goUp, - "context-menu-holder": true - }; - - console.log("ContextMenuAction scope ", scope); - - // Create the context menu - menu = $compile(MENU_TEMPLATE)(scope); - - console.log("ContextMenuAction menu ", menu); - - // Add the menu to the body - body.append(menu); - - // Dismiss the menu when body is clicked elsewhere - body.on('click', dismiss); - - // Don't launch browser's context menu - actionContext.event.preventDefault(); - //} return { /** @@ -122,7 +112,8 @@ define( if (dismissExistingMenu) { dismissExistingMenu(); } - } + }, + perform: perform }; } diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index 30f6905084..c9ffc2c41f 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -49,7 +49,7 @@ define( console.log('event ', event); console.log('domainObject ', domainObject); console.log('domainObject action', domainObject.getCapability('action')); - console.log('domainObject actions', domainObject.getCapability('action').getActions('contextMenu')); + console.log('domainObject actions', domainObject.getCapability('action').getActions('menu')); actionContext = {key: 'menu', domainObject: domainObject, event: event}; stop = domainObject.getCapability('action').perform(actionContext); From c08f972ab4d31cae87e43f14bf4b36daba3f2ef3 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 11:57:03 -0700 Subject: [PATCH 12/20] [Browse] Menu action called correctly Both the menu gesture and the menu arrow now correctly call the menu action. #33. --- .../browse/res/templates/browse/object-header.html | 2 +- platform/commonUI/browse/src/MenuArrowController.js | 11 ++++++----- .../representation/src/actions/ContextMenuAction.js | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/platform/commonUI/browse/res/templates/browse/object-header.html b/platform/commonUI/browse/res/templates/browse/object-header.html index 895761f514..eb3bd4f093 100644 --- a/platform/commonUI/browse/res/templates/browse/object-header.html +++ b/platform/commonUI/browse/res/templates/browse/object-header.html @@ -25,6 +25,6 @@ {{parameters.mode}} {{type.getName()}} {{model.name}} - + \ No newline at end of file diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index e6ab84b5d3..818af4fc49 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -36,7 +36,7 @@ define( * @constructor */ function MenuArrowController($scope) { - var domainObject = $scope.domainObject, + var //domainObject = $scope.domainObject, context; function showMenu(event) { @@ -44,18 +44,19 @@ define( console.log('$scope ', $scope); console.log('$scope.domainObject ', $scope.domainObject); - console.log('domainObject ', domainObject); + //console.log('domainObject ', domainObject); console.log('event ', event); - context = {key: 'menu', event: event, domainObject: domainObject}; - domainObject.getCapability('action').perform(context); + context = {key: 'menu', event: event, domainObject: $scope.domainObject}; + $scope.domainObject.getCapability('action').perform(context); } - + /* // attempt to set the domain object $scope.$watch('domainObject', function (c) { domainObject = c; console.log('watcher called'); }); + */ return { showMenu: showMenu diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index c2368bdf95..4881349952 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -50,7 +50,7 @@ define( function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) { function perform() { - //console.log('in perform()'); + console.log('in perform()'); var winDim = [$window.innerWidth, $window.innerHeight], eventCoors = [actionContext.event.pageX, actionContext.event.pageY], menuDim = GestureConstants.MCT_MENU_DIMENSIONS, From 2524c75505f9e1521b5e6911dac728b089f67e21 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 12:36:35 -0700 Subject: [PATCH 13/20] [Browse] Menu arrow works The menu arrow now displays a context menu when clicked. #33. --- .../browse/src/MenuArrowController.js | 26 +++++-------------- .../src/actions/ContextMenuAction.js | 4 +-- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 818af4fc49..309280f5fe 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -36,30 +36,18 @@ define( * @constructor */ function MenuArrowController($scope) { - var //domainObject = $scope.domainObject, - context; + var stop; function showMenu(event) { - console.log('showMenu() called'); - - console.log('$scope ', $scope); - console.log('$scope.domainObject ', $scope.domainObject); - //console.log('domainObject ', domainObject); - console.log('event ', event); - - context = {key: 'menu', event: event, domainObject: $scope.domainObject}; - $scope.domainObject.getCapability('action').perform(context); + var actionContext = {key: 'menu', domainObject: $scope.domainObject, event: event}; + stop = $scope.domainObject.getCapability('action').perform(actionContext); } - /* - // attempt to set the domain object - $scope.$watch('domainObject', function (c) { - domainObject = c; - console.log('watcher called'); - }); - */ return { - showMenu: showMenu + showMenu: showMenu, + destroy: function () { + stop(); + } }; } diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index 4881349952..ff31b9f088 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -50,7 +50,6 @@ define( function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) { function perform() { - console.log('in perform()'); var winDim = [$window.innerWidth, $window.innerHeight], eventCoors = [actionContext.event.pageX, actionContext.event.pageY], menuDim = GestureConstants.MCT_MENU_DIMENSIONS, @@ -95,7 +94,8 @@ define( body.append(menu); // Dismiss the menu when body is clicked elsewhere - body.on('click', dismiss); + // ('mousedown' because 'click' breaks left-click context menus) + body.on('mousedown', dismiss); // Don't launch browser's context menu actionContext.event.preventDefault(); From a582375e6127dd12c66d3aa578e7e371380a44b4 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 12:38:32 -0700 Subject: [PATCH 14/20] [Browse] Style All modified code follows style guides. #33. --- platform/representation/src/gestures/ContextMenuGesture.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/platform/representation/src/gestures/ContextMenuGesture.js b/platform/representation/src/gestures/ContextMenuGesture.js index c9ffc2c41f..cfab655442 100644 --- a/platform/representation/src/gestures/ContextMenuGesture.js +++ b/platform/representation/src/gestures/ContextMenuGesture.js @@ -45,12 +45,6 @@ define( // When context menu event occurs, show object actions instead element.on('contextmenu', function (event) { - console.log('in ContextMenuGesture'); - console.log('event ', event); - console.log('domainObject ', domainObject); - console.log('domainObject action', domainObject.getCapability('action')); - console.log('domainObject actions', domainObject.getCapability('action').getActions('menu')); - actionContext = {key: 'menu', domainObject: domainObject, event: event}; stop = domainObject.getCapability('action').perform(actionContext); }); From db920a7b5cd1aa24c2dd85e8ccb6e5e03620dab1 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 12:50:48 -0700 Subject: [PATCH 15/20] [Browse] Starting tests Created new test files for the additions. #33. --- .../browse/test/MenuArrowControllerSpec.js | 243 ++++++++++++++++++ platform/commonUI/browse/test/suite.json | 1 + .../test/actions/ContextMenuActionSpec.js | 163 ++++++++++++ .../test/gestures/ContextMenuGestureSpec.js | 68 +---- platform/representation/test/suite.json | 1 + 5 files changed, 414 insertions(+), 62 deletions(-) create mode 100644 platform/commonUI/browse/test/MenuArrowControllerSpec.js create mode 100644 platform/representation/test/actions/ContextMenuActionSpec.js diff --git a/platform/commonUI/browse/test/MenuArrowControllerSpec.js b/platform/commonUI/browse/test/MenuArrowControllerSpec.js new file mode 100644 index 0000000000..7a78407d36 --- /dev/null +++ b/platform/commonUI/browse/test/MenuArrowControllerSpec.js @@ -0,0 +1,243 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +/** + * MenuArrowControllerSpec. Created by shale on 07/02/2015. + */ +define( + ["../src/BrowseController"], + function (BrowseController) { + "use strict"; + + describe("The browse controller", function () { + var mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService, + mockRootObject, + mockUrlService, + mockDomainObject, + mockNextObject, + controller; + + function mockPromise(value) { + return { + then: function (callback) { + return mockPromise(callback(value)); + } + }; + } + + beforeEach(function () { + mockScope = jasmine.createSpyObj( + "$scope", + [ "$on", "$watch" ] + ); + mockRoute = { current: { params: {} } }; + mockLocation = jasmine.createSpyObj( + "$location", + [ "path" ] + ); + mockUrlService = jasmine.createSpyObj( + "urlService", + ["urlForLocation"] + ); + mockObjectService = jasmine.createSpyObj( + "objectService", + [ "getObjects" ] + ); + mockNavigationService = jasmine.createSpyObj( + "navigationService", + [ + "getNavigation", + "setNavigation", + "addListener", + "removeListener" + ] + ); + mockRootObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getCapability", "getModel", "useCapability" ] + ); + mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getCapability", "getModel", "useCapability" ] + ); + mockNextObject = jasmine.createSpyObj( + "nextObject", + [ "getId", "getCapability", "getModel", "useCapability" ] + ); + + mockObjectService.getObjects.andReturn(mockPromise({ + ROOT: mockRootObject + })); + mockRootObject.useCapability.andReturn(mockPromise([ + mockDomainObject + ])); + mockDomainObject.useCapability.andReturn(mockPromise([ + mockNextObject + ])); + mockNextObject.useCapability.andReturn(undefined); + mockNextObject.getId.andReturn("next"); + mockDomainObject.getId.andReturn("mine"); + + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService, + mockUrlService + ); + }); + + it("uses composition to set the navigated object, if there is none", function () { + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService, + mockUrlService + ); + expect(mockNavigationService.setNavigation) + .toHaveBeenCalledWith(mockDomainObject); + }); + + it("does not try to override navigation", function () { + mockNavigationService.getNavigation.andReturn(mockDomainObject); + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService, + mockUrlService + ); + expect(mockScope.navigatedObject).toBe(mockDomainObject); + }); + + it("updates scope when navigated object changes", function () { + // Should have registered a listener - call it + mockNavigationService.addListener.mostRecentCall.args[0]( + mockDomainObject + ); + expect(mockScope.navigatedObject).toEqual(mockDomainObject); + }); + + it("releases its navigation listener when its scope is destroyed", function () { + expect(mockScope.$on).toHaveBeenCalledWith( + "$destroy", + jasmine.any(Function) + ); + mockScope.$on.mostRecentCall.args[1](); + // Should remove the listener it added earlier + expect(mockNavigationService.removeListener).toHaveBeenCalledWith( + mockNavigationService.addListener.mostRecentCall.args[0] + ); + }); + + it("uses route parameters to choose initially-navigated object", function () { + mockRoute.current.params.ids = "mine/next"; + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + expect(mockScope.navigatedObject).toBe(mockNextObject); + expect(mockNavigationService.setNavigation) + .toHaveBeenCalledWith(mockNextObject); + }); + + it("handles invalid IDs by going as far as possible", function () { + // Idea here is that if we get a bad path of IDs, + // browse controller should traverse down it until + // it hits an invalid ID. + mockRoute.current.params.ids = "mine/junk"; + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + expect(mockScope.navigatedObject).toBe(mockDomainObject); + expect(mockNavigationService.setNavigation) + .toHaveBeenCalledWith(mockDomainObject); + }); + + it("handles compositionless objects by going as far as possible", function () { + // Idea here is that if we get a path which passes + // through an object without a composition, browse controller + // should stop at it since remaining IDs cannot be loaded. + mockRoute.current.params.ids = "mine/next/junk"; + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + expect(mockScope.navigatedObject).toBe(mockNextObject); + expect(mockNavigationService.setNavigation) + .toHaveBeenCalledWith(mockNextObject); + }); + + it("updates the displayed route to reflect current navigation", function () { + var mockContext = jasmine.createSpyObj('context', ['getPath']), + mockUnlisten = jasmine.createSpy('unlisten'), + mockMode = "browse"; + + mockContext.getPath.andReturn( + [mockRootObject, mockDomainObject, mockNextObject] + ); + mockNextObject.getCapability.andCallFake(function (c) { + return c === 'context' && mockContext; + }); + mockScope.$on.andReturn(mockUnlisten); + // Provide a navigation change + mockNavigationService.addListener.mostRecentCall.args[0]( + mockNextObject + ); + + // Allows the path index to be checked + // prior to setting $route.current + mockLocation.path.andReturn("/browse/"); + + // Exercise the Angular workaround + mockScope.$on.mostRecentCall.args[1](); + expect(mockUnlisten).toHaveBeenCalled(); + + // location.path to be called with the urlService's + // urlFor function with the next domainObject and mode + expect(mockLocation.path).toHaveBeenCalledWith( + mockUrlService.urlForLocation(mockMode, mockNextObject) + ); + }); + + }); + } +); diff --git a/platform/commonUI/browse/test/suite.json b/platform/commonUI/browse/test/suite.json index 6cc41900e1..e3a8f11c28 100644 --- a/platform/commonUI/browse/test/suite.json +++ b/platform/commonUI/browse/test/suite.json @@ -1,6 +1,7 @@ [ "BrowseController", "BrowseObjectController", + "MenuArrowController", "creation/CreateAction", "creation/CreateActionProvider", "creation/CreateMenuController", diff --git a/platform/representation/test/actions/ContextMenuActionSpec.js b/platform/representation/test/actions/ContextMenuActionSpec.js new file mode 100644 index 0000000000..2d65ff6414 --- /dev/null +++ b/platform/representation/test/actions/ContextMenuActionSpec.js @@ -0,0 +1,163 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ + + +/** + * Module defining ContextMenuActionSpec. Created by shale on 07/02/2015. + */ +define( + ["../../src/actions/ContextMenuAction", "../../src/gestures/GestureConstants"], + function (ContextMenuAction, GestureConstants) { + "use strict"; + + var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ], + DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ], + MENU_DIMENSIONS = GestureConstants.MCT_MENU_DIMENSIONS; + + + describe("The 'context menu' action", function () { + var mockCompile, + mockCompiledTemplate, + mockMenu, + mockDocument, + mockBody, + mockWindow, + mockRootScope, + mockScope, + mockElement, + mockDomainObject, + mockEvent, + gesture, + fireGesture; + + beforeEach(function () { + mockCompile = jasmine.createSpy("$compile"); + mockCompiledTemplate = jasmine.createSpy("template"); + mockMenu = jasmine.createSpyObj("menu", JQLITE_FUNCTIONS); + mockDocument = jasmine.createSpyObj("$document", JQLITE_FUNCTIONS); + mockBody = jasmine.createSpyObj("body", JQLITE_FUNCTIONS); + mockWindow = { innerWidth: MENU_DIMENSIONS[0] * 4, innerHeight: MENU_DIMENSIONS[1] * 4 }; + mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]); + mockScope = {}; + mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); + mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); + mockEvent = jasmine.createSpyObj("event", ["preventDefault"]); + mockEvent.pageX = 0; + mockEvent.pageY = 0; + + mockCompile.andReturn(mockCompiledTemplate); + mockCompiledTemplate.andReturn(mockMenu); + mockDocument.find.andReturn(mockBody); + mockRootScope.$new.andReturn(mockScope); + + gesture = new ContextMenuGesture( + mockCompile, + mockDocument, + mockWindow, + mockRootScope, + mockElement, + mockDomainObject + ); + + // Capture the contextmenu callback + fireGesture = mockElement.on.mostRecentCall.args[1]; + }); + + it("compiles and adds a menu to the DOM on a contextmenu event", function () { + // Make sure that callback really is for the contextmenu event + expect(mockElement.on.mostRecentCall.args[0]).toEqual("contextmenu"); + + fireGesture(mockEvent); + + expect(mockBody.append).toHaveBeenCalledWith(mockMenu); + }); + + it("prevents the default context menu behavior", function () { + fireGesture(mockEvent); + expect(mockEvent.preventDefault).toHaveBeenCalled(); + }); + + it("positions menus where clicked", function () { + mockEvent.pageX = 10; + mockEvent.pageY = 5; + fireGesture(mockEvent); + expect(mockScope.menuStyle.left).toEqual("10px"); + expect(mockScope.menuStyle.top).toEqual("5px"); + expect(mockScope.menuStyle.right).toBeUndefined(); + expect(mockScope.menuStyle.bottom).toBeUndefined(); + expect(mockScope.menuClass['go-up']).toBeFalsy(); + expect(mockScope.menuClass['go-left']).toBeFalsy(); + }); + + it("repositions menus near the screen edge", function () { + mockEvent.pageX = mockWindow.innerWidth - 10; + mockEvent.pageY = mockWindow.innerHeight - 5; + fireGesture(mockEvent); + expect(mockScope.menuStyle.right).toEqual("10px"); + expect(mockScope.menuStyle.bottom).toEqual("5px"); + expect(mockScope.menuStyle.left).toBeUndefined(); + expect(mockScope.menuStyle.top).toBeUndefined(); + expect(mockScope.menuClass['go-up']).toBeTruthy(); + expect(mockScope.menuClass['go-left']).toBeTruthy(); + }); + + it("removes a menu when body is clicked", function () { + // Show the menu + fireGesture(mockEvent); + + // Verify precondition + expect(mockBody.off).not.toHaveBeenCalled(); + + // Find and fire body's click listener + mockBody.on.calls.forEach(function (call) { + if (call.args[0] === 'click') { + call.args[1](); + } + }); + + // Menu should have been removed + expect(mockMenu.remove).toHaveBeenCalled(); + + // Listener should have been detached from body + expect(mockBody.off).toHaveBeenCalled(); + }); + + it("removes listeners from body if destroyed while menu is showing", function () { + // Show the menu + fireGesture(mockEvent); + + // Verify preconditions + expect(mockBody.off).not.toHaveBeenCalled(); + expect(mockMenu.remove).not.toHaveBeenCalled(); + + // Destroy the menu + gesture.destroy(); + + // Verify menu was removed and listener detached + expect(mockBody.off).toHaveBeenCalled(); + expect(mockMenu.remove).toHaveBeenCalled(); + }); + + }); + } +); \ No newline at end of file diff --git a/platform/representation/test/gestures/ContextMenuGestureSpec.js b/platform/representation/test/gestures/ContextMenuGestureSpec.js index 8b91a969d4..7a13bb98ff 100644 --- a/platform/representation/test/gestures/ContextMenuGestureSpec.js +++ b/platform/representation/test/gestures/ContextMenuGestureSpec.js @@ -26,8 +26,8 @@ * Module defining ContextMenuGestureSpec. Created by vwoeltje on 11/22/14. */ define( - ["../../src/gestures/ContextMenuGesture", "../../src/gestures/GestureConstants"], - function (ContextMenuGesture, GestureConstants) { + ["../../src/gestures/ContextMenuGesture"], + function (ContextMenuGesture) { "use strict"; var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ], @@ -100,66 +100,9 @@ define( mockElement.on.mostRecentCall.args[1] ); }); - - it("compiles and adds a menu to the DOM on a contextmenu event", function () { - // Make sure that callback really is for the contextmenu event - expect(mockElement.on.mostRecentCall.args[0]).toEqual("contextmenu"); - - fireGesture(mockEvent); - - expect(mockBody.append).toHaveBeenCalledWith(mockMenu); - }); - - it("prevents the default context menu behavior", function () { - fireGesture(mockEvent); - expect(mockEvent.preventDefault).toHaveBeenCalled(); - }); - - it("positions menus where clicked", function () { - mockEvent.pageX = 10; - mockEvent.pageY = 5; - fireGesture(mockEvent); - expect(mockScope.menuStyle.left).toEqual("10px"); - expect(mockScope.menuStyle.top).toEqual("5px"); - expect(mockScope.menuStyle.right).toBeUndefined(); - expect(mockScope.menuStyle.bottom).toBeUndefined(); - expect(mockScope.menuClass['go-up']).toBeFalsy(); - expect(mockScope.menuClass['go-left']).toBeFalsy(); - }); - - it("repositions menus near the screen edge", function () { - mockEvent.pageX = mockWindow.innerWidth - 10; - mockEvent.pageY = mockWindow.innerHeight - 5; - fireGesture(mockEvent); - expect(mockScope.menuStyle.right).toEqual("10px"); - expect(mockScope.menuStyle.bottom).toEqual("5px"); - expect(mockScope.menuStyle.left).toBeUndefined(); - expect(mockScope.menuStyle.top).toBeUndefined(); - expect(mockScope.menuClass['go-up']).toBeTruthy(); - expect(mockScope.menuClass['go-left']).toBeTruthy(); - }); - - it("removes a menu when body is clicked", function () { - // Show the menu - fireGesture(mockEvent); - - // Verify precondition - expect(mockBody.off).not.toHaveBeenCalled(); - - // Find and fire body's click listener - mockBody.on.calls.forEach(function (call) { - if (call.args[0] === 'click') { - call.args[1](); - } - }); - - // Menu should have been removed - expect(mockMenu.remove).toHaveBeenCalled(); - - // Listener should have been detached from body - expect(mockBody.off).toHaveBeenCalled(); - }); - + + ////// Is this one here or in action spec? (shale) + /* it("removes listeners from body if destroyed while menu is showing", function () { // Show the menu fireGesture(mockEvent); @@ -175,6 +118,7 @@ define( expect(mockBody.off).toHaveBeenCalled(); expect(mockMenu.remove).toHaveBeenCalled(); }); + */ }); } diff --git a/platform/representation/test/suite.json b/platform/representation/test/suite.json index 600b81baea..16ebb5c666 100644 --- a/platform/representation/test/suite.json +++ b/platform/representation/test/suite.json @@ -1,4 +1,5 @@ [ + "actions/ContextMenuAction", "gestures/ContextMenuGesture", "gestures/DragGesture", "gestures/DropGesture", From 2b67ae42bfb373c941f39c00adea8d667695d34b Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 14:00:54 -0700 Subject: [PATCH 16/20] [Browse] Gesture and action tests The menu gesture and the menu action tests are completed. #33. --- .../browse/test/MenuArrowControllerSpec.js | 225 +++--------------- .../test/actions/ContextMenuActionSpec.js | 42 ++-- .../test/gestures/ContextMenuGestureSpec.js | 40 +--- 3 files changed, 56 insertions(+), 251 deletions(-) diff --git a/platform/commonUI/browse/test/MenuArrowControllerSpec.js b/platform/commonUI/browse/test/MenuArrowControllerSpec.js index 7a78407d36..7b58b20a7c 100644 --- a/platform/commonUI/browse/test/MenuArrowControllerSpec.js +++ b/platform/commonUI/browse/test/MenuArrowControllerSpec.js @@ -25,217 +25,58 @@ * MenuArrowControllerSpec. Created by shale on 07/02/2015. */ define( - ["../src/BrowseController"], - function (BrowseController) { + ["../src/MenuArrowController"], + function (MenuArrowController) { "use strict"; + + //var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ], + // DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ]; - describe("The browse controller", function () { + + describe("The menu arrow controller", function () { var mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockRootObject, - mockUrlService, mockDomainObject, - mockNextObject, + mockEvent, + mockContextMenuAction, + mockActionContext, controller; - - function mockPromise(value) { - return { - then: function (callback) { - return mockPromise(callback(value)); - } - }; - } - + beforeEach(function () { mockScope = jasmine.createSpyObj( "$scope", [ "$on", "$watch" ] ); - mockRoute = { current: { params: {} } }; - mockLocation = jasmine.createSpyObj( - "$location", - [ "path" ] - ); - mockUrlService = jasmine.createSpyObj( - "urlService", - ["urlForLocation"] - ); - mockObjectService = jasmine.createSpyObj( - "objectService", - [ "getObjects" ] - ); - mockNavigationService = jasmine.createSpyObj( - "navigationService", - [ - "getNavigation", - "setNavigation", - "addListener", - "removeListener" - ] - ); - mockRootObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getCapability", "getModel", "useCapability" ] - ); mockDomainObject = jasmine.createSpyObj( "domainObject", - [ "getId", "getCapability", "getModel", "useCapability" ] + [ "getCapability" ] ); - mockNextObject = jasmine.createSpyObj( - "nextObject", - [ "getId", "getCapability", "getModel", "useCapability" ] + mockEvent = jasmine.createSpyObj( + "event", + [ "preventDefault" ] ); - - mockObjectService.getObjects.andReturn(mockPromise({ - ROOT: mockRootObject - })); - mockRootObject.useCapability.andReturn(mockPromise([ - mockDomainObject - ])); - mockDomainObject.useCapability.andReturn(mockPromise([ - mockNextObject - ])); - mockNextObject.useCapability.andReturn(undefined); - mockNextObject.getId.andReturn("next"); - mockDomainObject.getId.andReturn("mine"); - - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockUrlService + mockContextMenuAction = jasmine.createSpyObj( + "menu", + [ "perform", "destroy" ] ); - }); - - it("uses composition to set the navigated object, if there is none", function () { - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockUrlService - ); - expect(mockNavigationService.setNavigation) - .toHaveBeenCalledWith(mockDomainObject); - }); - - it("does not try to override navigation", function () { - mockNavigationService.getNavigation.andReturn(mockDomainObject); - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService, - mockUrlService - ); - expect(mockScope.navigatedObject).toBe(mockDomainObject); - }); - - it("updates scope when navigated object changes", function () { - // Should have registered a listener - call it - mockNavigationService.addListener.mostRecentCall.args[0]( - mockDomainObject - ); - expect(mockScope.navigatedObject).toEqual(mockDomainObject); - }); - - it("releases its navigation listener when its scope is destroyed", function () { - expect(mockScope.$on).toHaveBeenCalledWith( - "$destroy", - jasmine.any(Function) - ); - mockScope.$on.mostRecentCall.args[1](); - // Should remove the listener it added earlier - expect(mockNavigationService.removeListener).toHaveBeenCalledWith( - mockNavigationService.addListener.mostRecentCall.args[0] - ); - }); - - it("uses route parameters to choose initially-navigated object", function () { - mockRoute.current.params.ids = "mine/next"; - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService - ); - expect(mockScope.navigatedObject).toBe(mockNextObject); - expect(mockNavigationService.setNavigation) - .toHaveBeenCalledWith(mockNextObject); - }); - - it("handles invalid IDs by going as far as possible", function () { - // Idea here is that if we get a bad path of IDs, - // browse controller should traverse down it until - // it hits an invalid ID. - mockRoute.current.params.ids = "mine/junk"; - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService - ); - expect(mockScope.navigatedObject).toBe(mockDomainObject); - expect(mockNavigationService.setNavigation) - .toHaveBeenCalledWith(mockDomainObject); - }); - - it("handles compositionless objects by going as far as possible", function () { - // Idea here is that if we get a path which passes - // through an object without a composition, browse controller - // should stop at it since remaining IDs cannot be loaded. - mockRoute.current.params.ids = "mine/next/junk"; - controller = new BrowseController( - mockScope, - mockRoute, - mockLocation, - mockObjectService, - mockNavigationService - ); - expect(mockScope.navigatedObject).toBe(mockNextObject); - expect(mockNavigationService.setNavigation) - .toHaveBeenCalledWith(mockNextObject); - }); - - it("updates the displayed route to reflect current navigation", function () { - var mockContext = jasmine.createSpyObj('context', ['getPath']), - mockUnlisten = jasmine.createSpy('unlisten'), - mockMode = "browse"; - - mockContext.getPath.andReturn( - [mockRootObject, mockDomainObject, mockNextObject] - ); - mockNextObject.getCapability.andCallFake(function (c) { - return c === 'context' && mockContext; + mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent}; + + mockScope.domainObject = mockDomainObject; + mockDomainObject.getCapability.andReturn(function (c) { + //return c === 'action' ? mockContextMenuAction : undefined; + return mockContextMenuAction; }); - mockScope.$on.andReturn(mockUnlisten); - // Provide a navigation change - mockNavigationService.addListener.mostRecentCall.args[0]( - mockNextObject - ); - // Allows the path index to be checked - // prior to setting $route.current - mockLocation.path.andReturn("/browse/"); + controller = new MenuArrowController(mockScope); + }); + + it(" calls the context menu action when clicked", function () { + // Simulate a click on the menu arrow + controller.showMenu(mockEvent); - // Exercise the Angular workaround - mockScope.$on.mostRecentCall.args[1](); - expect(mockUnlisten).toHaveBeenCalled(); + //stop = $scope.domainObject.getCapability('action').perform(actionContext); - // location.path to be called with the urlService's - // urlFor function with the next domainObject and mode - expect(mockLocation.path).toHaveBeenCalledWith( - mockUrlService.urlForLocation(mockMode, mockNextObject) - ); + expect(mockDomainObject.getCapability).toHaveBeenCalled(); + //.toHaveBeenCalledWith('action'); }); }); diff --git a/platform/representation/test/actions/ContextMenuActionSpec.js b/platform/representation/test/actions/ContextMenuActionSpec.js index 2d65ff6414..5cfdab1e17 100644 --- a/platform/representation/test/actions/ContextMenuActionSpec.js +++ b/platform/representation/test/actions/ContextMenuActionSpec.js @@ -47,8 +47,8 @@ define( mockElement, mockDomainObject, mockEvent, - gesture, - fireGesture; + mockActionContext, + action; beforeEach(function () { mockCompile = jasmine.createSpy("$compile"); @@ -69,38 +69,32 @@ define( mockCompiledTemplate.andReturn(mockMenu); mockDocument.find.andReturn(mockBody); mockRootScope.$new.andReturn(mockScope); + + mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent}; - gesture = new ContextMenuGesture( + action = new ContextMenuAction( mockCompile, mockDocument, mockWindow, mockRootScope, - mockElement, - mockDomainObject + mockActionContext ); - - // Capture the contextmenu callback - fireGesture = mockElement.on.mostRecentCall.args[1]; }); - it("compiles and adds a menu to the DOM on a contextmenu event", function () { - // Make sure that callback really is for the contextmenu event - expect(mockElement.on.mostRecentCall.args[0]).toEqual("contextmenu"); - - fireGesture(mockEvent); - + it(" adds a menu to the DOM when perform is called", function () { + action.perform(); expect(mockBody.append).toHaveBeenCalledWith(mockMenu); }); it("prevents the default context menu behavior", function () { - fireGesture(mockEvent); + action.perform(); expect(mockEvent.preventDefault).toHaveBeenCalled(); }); it("positions menus where clicked", function () { mockEvent.pageX = 10; mockEvent.pageY = 5; - fireGesture(mockEvent); + action.perform(); expect(mockScope.menuStyle.left).toEqual("10px"); expect(mockScope.menuStyle.top).toEqual("5px"); expect(mockScope.menuStyle.right).toBeUndefined(); @@ -112,7 +106,7 @@ define( it("repositions menus near the screen edge", function () { mockEvent.pageX = mockWindow.innerWidth - 10; mockEvent.pageY = mockWindow.innerHeight - 5; - fireGesture(mockEvent); + action.perform(); expect(mockScope.menuStyle.right).toEqual("10px"); expect(mockScope.menuStyle.bottom).toEqual("5px"); expect(mockScope.menuStyle.left).toBeUndefined(); @@ -123,14 +117,14 @@ define( it("removes a menu when body is clicked", function () { // Show the menu - fireGesture(mockEvent); - + action.perform(); + // Verify precondition expect(mockBody.off).not.toHaveBeenCalled(); - // Find and fire body's click listener + // Find and fire body's mousedown listener mockBody.on.calls.forEach(function (call) { - if (call.args[0] === 'click') { + if (call.args[0] === 'mousedown') { call.args[1](); } }); @@ -144,14 +138,14 @@ define( it("removes listeners from body if destroyed while menu is showing", function () { // Show the menu - fireGesture(mockEvent); - + action.perform(); + // Verify preconditions expect(mockBody.off).not.toHaveBeenCalled(); expect(mockMenu.remove).not.toHaveBeenCalled(); // Destroy the menu - gesture.destroy(); + action.destroy(); // Verify menu was removed and listener detached expect(mockBody.off).toHaveBeenCalled(); diff --git a/platform/representation/test/gestures/ContextMenuGestureSpec.js b/platform/representation/test/gestures/ContextMenuGestureSpec.js index 7a13bb98ff..98076e6e82 100644 --- a/platform/representation/test/gestures/ContextMenuGestureSpec.js +++ b/platform/representation/test/gestures/ContextMenuGestureSpec.js @@ -31,53 +31,22 @@ define( "use strict"; var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ], - DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ], - MENU_DIMENSIONS = GestureConstants.MCT_MENU_DIMENSIONS; + DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ]; describe("The 'context menu' gesture", function () { - var mockCompile, - mockCompiledTemplate, - mockMenu, - mockDocument, - mockBody, - mockWindow, - mockRootScope, - mockScope, - mockElement, + var mockElement, mockDomainObject, mockEvent, gesture, fireGesture; beforeEach(function () { - mockCompile = jasmine.createSpy("$compile"); - mockCompiledTemplate = jasmine.createSpy("template"); - mockMenu = jasmine.createSpyObj("menu", JQLITE_FUNCTIONS); - mockDocument = jasmine.createSpyObj("$document", JQLITE_FUNCTIONS); - mockBody = jasmine.createSpyObj("body", JQLITE_FUNCTIONS); - mockWindow = { innerWidth: MENU_DIMENSIONS[0] * 4, innerHeight: MENU_DIMENSIONS[1] * 4 }; - mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]); - mockScope = {}; mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); mockEvent = jasmine.createSpyObj("event", ["preventDefault"]); - mockEvent.pageX = 0; - mockEvent.pageY = 0; - mockCompile.andReturn(mockCompiledTemplate); - mockCompiledTemplate.andReturn(mockMenu); - mockDocument.find.andReturn(mockBody); - mockRootScope.$new.andReturn(mockScope); - - gesture = new ContextMenuGesture( - mockCompile, - mockDocument, - mockWindow, - mockRootScope, - mockElement, - mockDomainObject - ); + gesture = new ContextMenuGesture(mockElement, mockDomainObject); // Capture the contextmenu callback fireGesture = mockElement.on.mostRecentCall.args[1]; @@ -97,7 +66,8 @@ define( expect(mockElement.off).toHaveBeenCalledWith( "contextmenu", - mockElement.on.mostRecentCall.args[1] + //mockElement.on.mostRecentCall.args[1] + mockDomainObject.calls ); }); From e3a96eff8df2397b01c180351bb85b60911e4b54 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Thu, 2 Jul 2015 15:34:11 -0700 Subject: [PATCH 17/20] [Browse] Fixed clicking on menu Previously any click on the context menu would close the context menu rather than doing the appropriate action. This is now fixed. The menu only closes when a click happens not on the menu. #33. --- platform/representation/src/actions/ContextMenuAction.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index ff31b9f088..ee85b2f900 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -92,7 +92,12 @@ define( // Add the menu to the body body.append(menu); - + + // Stop propagation so that clicks on the menu do not close the menu + menu.on('mousedown', function (event) { + event.stopPropagation(); + }); + // Dismiss the menu when body is clicked elsewhere // ('mousedown' because 'click' breaks left-click context menus) body.on('mousedown', dismiss); From b2a23ee968c79c5086a0ba086cf753245b5eb5f7 Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 7 Jul 2015 09:28:01 -0700 Subject: [PATCH 18/20] [Browse] Tests completed Completed the menu arrow controller test. All tests are now completed. #33. --- .../browse/test/MenuArrowControllerSpec.js | 35 +++++++++---------- .../test/gestures/ContextMenuGestureSpec.js | 20 ----------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/platform/commonUI/browse/test/MenuArrowControllerSpec.js b/platform/commonUI/browse/test/MenuArrowControllerSpec.js index 7b58b20a7c..b8aa345489 100644 --- a/platform/commonUI/browse/test/MenuArrowControllerSpec.js +++ b/platform/commonUI/browse/test/MenuArrowControllerSpec.js @@ -29,11 +29,7 @@ define( function (MenuArrowController) { "use strict"; - //var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ], - // DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ]; - - - describe("The menu arrow controller", function () { + describe("The menu arrow controller ", function () { var mockScope, mockDomainObject, mockEvent, @@ -44,7 +40,7 @@ define( beforeEach(function () { mockScope = jasmine.createSpyObj( "$scope", - [ "$on", "$watch" ] + [ "" ] ); mockDomainObject = jasmine.createSpyObj( "domainObject", @@ -55,30 +51,31 @@ define( [ "preventDefault" ] ); mockContextMenuAction = jasmine.createSpyObj( - "menu", - [ "perform", "destroy" ] + "action", + [ "perform", "getActions" ] + ); + mockActionContext = jasmine.createSpyObj( + "actionContext", + [ "" ] ); - mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent}; + mockActionContext.domainObject = mockDomainObject; + mockActionContext.event = mockEvent; mockScope.domainObject = mockDomainObject; - mockDomainObject.getCapability.andReturn(function (c) { - //return c === 'action' ? mockContextMenuAction : undefined; - return mockContextMenuAction; - }); + mockDomainObject.getCapability.andReturn(mockContextMenuAction); + mockContextMenuAction.perform.andReturn(jasmine.any(Function)); controller = new MenuArrowController(mockScope); }); - it(" calls the context menu action when clicked", function () { + it("calls the context menu action when clicked", function () { // Simulate a click on the menu arrow controller.showMenu(mockEvent); - //stop = $scope.domainObject.getCapability('action').perform(actionContext); - - expect(mockDomainObject.getCapability).toHaveBeenCalled(); - //.toHaveBeenCalledWith('action'); + // Expect the menu action to be performed + expect(mockDomainObject.getCapability).toHaveBeenCalledWith('action'); + expect(mockContextMenuAction.perform).toHaveBeenCalled(); }); - }); } ); diff --git a/platform/representation/test/gestures/ContextMenuGestureSpec.js b/platform/representation/test/gestures/ContextMenuGestureSpec.js index 98076e6e82..098e687217 100644 --- a/platform/representation/test/gestures/ContextMenuGestureSpec.js +++ b/platform/representation/test/gestures/ContextMenuGestureSpec.js @@ -70,26 +70,6 @@ define( mockDomainObject.calls ); }); - - ////// Is this one here or in action spec? (shale) - /* - it("removes listeners from body if destroyed while menu is showing", function () { - // Show the menu - fireGesture(mockEvent); - - // Verify preconditions - expect(mockBody.off).not.toHaveBeenCalled(); - expect(mockMenu.remove).not.toHaveBeenCalled(); - - // Destroy the menu - gesture.destroy(); - - // Verify menu was removed and listener detached - expect(mockBody.off).toHaveBeenCalled(); - expect(mockMenu.remove).toHaveBeenCalled(); - }); - */ - }); } ); \ No newline at end of file From 1455e5d8b57bce83a685c51e2af63a4feb14d659 Mon Sep 17 00:00:00 2001 From: shale Date: Tue, 14 Jul 2015 13:25:25 -0700 Subject: [PATCH 19/20] [Browse] Removed destroy functions Removed destroy functions from menu arrow controller and contetxt menu action as suggested. #33, #47. --- platform/commonUI/browse/src/MenuArrowController.js | 9 ++------- .../representation/src/actions/ContextMenuAction.js | 11 ----------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/platform/commonUI/browse/src/MenuArrowController.js b/platform/commonUI/browse/src/MenuArrowController.js index 309280f5fe..86cad25c0e 100644 --- a/platform/commonUI/browse/src/MenuArrowController.js +++ b/platform/commonUI/browse/src/MenuArrowController.js @@ -36,18 +36,13 @@ define( * @constructor */ function MenuArrowController($scope) { - var stop; - function showMenu(event) { var actionContext = {key: 'menu', domainObject: $scope.domainObject, event: event}; - stop = $scope.domainObject.getCapability('action').perform(actionContext); + $scope.domainObject.getCapability('action').perform(actionContext); } return { - showMenu: showMenu, - destroy: function () { - stop(); - } + showMenu: showMenu }; } diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index ee85b2f900..390531053e 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -107,17 +107,6 @@ define( } return { - /** - * Dismiss any visible menu. - * @method - * @memberof ContextMenuAction - */ - destroy: function () { - // Scope has been destroyed, so remove all listeners. - if (dismissExistingMenu) { - dismissExistingMenu(); - } - }, perform: perform }; } From aa091a9d26959cc49fe156ede297b8a7697f674d Mon Sep 17 00:00:00 2001 From: shale Date: Tue, 14 Jul 2015 13:52:54 -0700 Subject: [PATCH 20/20] [Browse] Update tests Removed reference to destroy() in the context menu action test. #33, #47. --- .../test/actions/ContextMenuActionSpec.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/platform/representation/test/actions/ContextMenuActionSpec.js b/platform/representation/test/actions/ContextMenuActionSpec.js index 5cfdab1e17..73b877ddc3 100644 --- a/platform/representation/test/actions/ContextMenuActionSpec.js +++ b/platform/representation/test/actions/ContextMenuActionSpec.js @@ -135,23 +135,6 @@ define( // Listener should have been detached from body expect(mockBody.off).toHaveBeenCalled(); }); - - it("removes listeners from body if destroyed while menu is showing", function () { - // Show the menu - action.perform(); - - // Verify preconditions - expect(mockBody.off).not.toHaveBeenCalled(); - expect(mockMenu.remove).not.toHaveBeenCalled(); - - // Destroy the menu - action.destroy(); - - // Verify menu was removed and listener detached - expect(mockBody.off).toHaveBeenCalled(); - expect(mockMenu.remove).toHaveBeenCalled(); - }); - }); } ); \ No newline at end of file