From 57eefd73164fbf0f008c5e2e162f8fa7e333c23a Mon Sep 17 00:00:00 2001 From: Sarah Hale Date: Tue, 30 Jun 2015 11:18:56 -0700 Subject: [PATCH 01/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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/36] [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 From e7e79f41a73a4527f2e1a00c8b669efa4a750e3a Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 21 Jul 2015 14:24:17 -0700 Subject: [PATCH 21/36] [Packaging] Create NPM Package Create NPM package for OpenMCTWeb. Includes scripts for hosting, running tests, and building documentation. --- .gitignore | 1 - jsdoc.json | 10 +++++++++ karma.conf.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 33 ++++++++++++++++++++++++++++++ test-main.js | 40 ++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 jsdoc.json create mode 100644 karma.conf.js create mode 100644 package.json create mode 100644 test-main.js diff --git a/.gitignore b/.gitignore index 4c2c6ce8a0..3188d5fa38 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ closed-lib # Node dependencies node_modules - diff --git a/jsdoc.json b/jsdoc.json new file mode 100644 index 0000000000..ed0fddcf31 --- /dev/null +++ b/jsdoc.json @@ -0,0 +1,10 @@ +{ + "source": { + "include": [ + "example/", + "platform/" + ], + "includePattern": "(example|platform)/.+\\.js$", + "excludePattern": ".+\\Spec\\.js$|lib/.+" + } +} \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000000..b47841019e --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,56 @@ +module.exports = function(config) { + config.set({ + + // Base path that will be used to resolve all file patterns. + basePath: '', + + // Frameworks to use + // Available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine', 'requirejs'], + + // List of files / patterns to load in the browser. + // By default, files are also included in a script tag. + files: [ + '**/moment*', + {pattern: 'example/**/*.js', included: false}, + {pattern: 'platform/**/*.js', included: false}, + {pattern: 'warp/**/*.js', included: false}, + 'test-main.js' + ], + + // List of files to exclude. + exclude: [ + 'platform/framework/src/Main.js' + ], + + // Preprocess matching files before serving them to the browser. + // https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: {}, + + // Test results reporter to use + // Possible values: 'dots', 'progress' + // Available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // Web server port. + port: 9876, + + // Wnable / disable colors in the output (reporters and logs). + colors: true, + + logLevel: config.LOG_INFO, + + // Rerun tests when any file changes. + autoWatch: true, + + // Specify browsers to run tests in. + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [ + 'Chrome' + ], + + // Continuous Integration mode. + // If true, Karma captures browsers, runs the tests and exits. + singleRun: false + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000000..1216935f21 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "open-mct-web", + "version": "0.7.2", + "description": "The OpenMCTWeb core platform", + "dependencies": { + "express": "^4.13.1", + "minimist": "^1.1.1" + }, + "devDependencies": { + "jasmine-core": "^2.3.0", + "jsdoc": "^3.3.2", + "jshint": "^2.7.0", + "karma": "^0.12.31", + "karma-chrome-launcher": "^0.1.8", + "karma-cli": "0.0.4", + "karma-jasmine": "^0.1.5", + "karma-phantomjs-launcher": "^0.1.4", + "karma-requirejs": "^0.2.2", + "requirejs": "^2.1.17" + }, + "scripts": { + "start": "node app.js", + "test": "karma start --single-run", + "jshint": "jshint platform example || exit 0", + "jsdoc": "jsdoc -c jsdoc.json -r -d docs" + }, + "repository": { + "type": "git", + "url": "https://github.com/nasa/openmctweb.git" + }, + "author": "", + "license": "Apache-2.0" +} diff --git a/test-main.js b/test-main.js new file mode 100644 index 0000000000..d687656e68 --- /dev/null +++ b/test-main.js @@ -0,0 +1,40 @@ +var allTestFiles = []; +var TEST_REGEXP = /(Spec)\.js$/; + +var pathToModule = function(path) { + return path.replace(/^\/base\//, '').replace(/\.js$/, ''); +}; + +Object.keys(window.__karma__.files).forEach(function(file) { + if (TEST_REGEXP.test(file)) { + // Normalize paths to RequireJS module names. + allTestFiles.push(pathToModule(file)); + } +}); + +// We will be handling es6-promise loading with a shim. +allTestFiles.unshift('es6-promise'); + +require.config({ + // Karma serves files from the basePath defined in karma.conf.js + baseUrl: '/base', + + paths: { + 'es6-promise': 'platform/framework/lib/es6-promise-2.0.0.min', + 'moment-duration-format': 'warp/clock/lib/moment-duration-format' + }, + shim: { + 'es6-promise': { + init: function () { + console.log('I was inited!'); + window.Promise = window.Promise || ES6Promise.Promise; + } + } + }, + + // dynamically load all test files + deps: allTestFiles, + + // we have to kickoff jasmine, as it is asynchronous + callback: window.__karma__.start +}); From cb56bbe5695cd7410ae7e176d7cf58ebea37b620 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 21 Jul 2015 14:30:00 -0700 Subject: [PATCH 22/36] [Documentation] Fix JSDoc syntax errors --- platform/core/src/objects/DomainObject.js | 2 +- platform/framework/src/resolve/BundleResolver.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/core/src/objects/DomainObject.js b/platform/core/src/objects/DomainObject.js index 7bc31666de..e3a10160a5 100644 --- a/platform/core/src/objects/DomainObject.js +++ b/platform/core/src/objects/DomainObject.js @@ -35,7 +35,7 @@ define( * * @param {string} id the object's unique identifier * @param {object} model the "JSONifiable" state of the object - * @param {Object.|function} capabilities all * capabilities to be exposed by this object * @constructor */ diff --git a/platform/framework/src/resolve/BundleResolver.js b/platform/framework/src/resolve/BundleResolver.js index d26ee60271..5c8216da94 100644 --- a/platform/framework/src/resolve/BundleResolver.js +++ b/platform/framework/src/resolve/BundleResolver.js @@ -45,7 +45,7 @@ define( * into one large object containing resolved extensions from * all bundles (in the same form.) * - * @param {Object.[]} resolvedBundles + * @param {Object.|Array} resolvedBundles * @returns {Object.} */ function mergeResolvedBundles(resolvedBundles) { From 808a79178ba10593deaad892e1ebd4e01d23f891 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 21 Jul 2015 14:34:40 -0700 Subject: [PATCH 23/36] [Continous] Build and publish documentation --- build-docs.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ circle.yml | 5 +++++ 2 files changed, 47 insertions(+) create mode 100755 build-docs.sh create mode 100644 circle.yml diff --git a/build-docs.sh b/build-docs.sh new file mode 100755 index 0000000000..510de0041d --- /dev/null +++ b/build-docs.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Script to build and deploy docs to github pages. + +# Any Content currently visible on the website will be replaced by +# this process. + +OUTPUT_DIRECTORY="docs" +REPOSITORY_URL="git@github.com:larkin/openmctweb.git" + +BUILD_SHA=`git rev-parse head` + +# A remote will be created for the git repository we are pushing to. +# Don't change the name. +REMOTE_NAME="documentation" +WEBSITE_BRANCH="gh-pages" + +# Configure github for CircleCI user. +git config --global user.email "buildbot@circleci.com" +git config --global user.name "BuildBot" + +# clean output directory +if [ -d $OUTPUT_DIRECTORY ]; then + rm -rf $OUTPUT_DIRECTORY || exit 1 +fi + +npm run-script jsdoc +cd $OUTPUT_DIRECTORY || exit 1 + +echo "git init" +git init +echo "git remote add $REMOTE_NAME $REPOSITORY_URL" +git remote add $REMOTE_NAME $REPOSITORY_URL +echo "git add ." +git add . +echo "git commit -m \"Generate docs from build $BUILD_SHA\"" +git commit -m "Generate docs from build $BUILD_SHA" + +echo "git push $REMOTE_NAME HEAD:$WEBSITE_BRANCH -f" +git push $REMOTE_NAME HEAD:$WEBSITE_BRANCH -f + +echo "Documentation pushed gh-pages branch." \ No newline at end of file diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000000..9981ef249a --- /dev/null +++ b/circle.yml @@ -0,0 +1,5 @@ +deployment: + production: + branch: continuous-deployment + commands: + - ./build-docs.sh From 19b0b1aa66b767e4579d2bd5fa43bd1f77023466 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 21 Jul 2015 17:27:17 -0700 Subject: [PATCH 24/36] [Continuous] Run via Procfile binds port --- Procfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000..659947f3b8 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: node app.js --port $PORT \ No newline at end of file From 01a52b8af886ae91ff4003bb2ea62306a08dd300 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 21 Jul 2015 17:29:25 -0700 Subject: [PATCH 25/36] [Continuous] Deploy to heroku --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index 9981ef249a..36c7c9b0b8 100644 --- a/circle.yml +++ b/circle.yml @@ -3,3 +3,4 @@ deployment: branch: continuous-deployment commands: - ./build-docs.sh + - git push git@heroku.com:openmctweb-demo.git $CIRCLE_SHA1:refs/heads/master From 919ef2f991edfb6f9a75e0d5a55ae22e0165ae82 Mon Sep 17 00:00:00 2001 From: larkin Date: Wed, 22 Jul 2015 10:58:28 -0700 Subject: [PATCH 26/36] [Persistence] Add localstorage persistence --- example/localstorage/bundle.json | 18 ++++++ .../src/LocalStoragePersistenceProvider.js | 62 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 example/localstorage/bundle.json create mode 100644 example/localstorage/src/LocalStoragePersistenceProvider.js diff --git a/example/localstorage/bundle.json b/example/localstorage/bundle.json new file mode 100644 index 0000000000..b164f9aaa9 --- /dev/null +++ b/example/localstorage/bundle.json @@ -0,0 +1,18 @@ +{ + "extensions": { + "components": [ + { + "provides": "persistenceService", + "type": "provider", + "implementation": "LocalStoragePersistenceProvider.js", + "depends": [ "$q", "PERSISTENCE_SPACE" ] + } + ], + "constants": [ + { + "key": "PERSISTENCE_SPACE", + "value": "mct" + } + ] + } +} \ No newline at end of file diff --git a/example/localstorage/src/LocalStoragePersistenceProvider.js b/example/localstorage/src/LocalStoragePersistenceProvider.js new file mode 100644 index 0000000000..b01e6a569b --- /dev/null +++ b/example/localstorage/src/LocalStoragePersistenceProvider.js @@ -0,0 +1,62 @@ +/** + * Stubbed implementation of a persistence provider, + * to permit objects to be created, saved, etc. + */ +define( + [], + function () { + 'use strict'; + + function BrowserPersistenceProvider($q, SPACE) { + var spaces = SPACE ? [SPACE] : [], + promises = { + as: function (value) { + return $q.when(value); + } + }; + + var setValue = function(key, value) { + localStorage[key] = JSON.stringify(value); + }; + + var getValue = function(key) { + if (localStorage[key]) { + return JSON.parse(localStorage[key]); + } + return {}; + }; + + var provider = { + listSpaces: function () { + return promises.as(spaces); + }, + listObjects: function (space) { + var space_obj = getValue(space); + return promises.as(Object.keys(space_obj)); + }, + createObject: function (space, key, value) { + var space_obj = getValue(space); + space_obj[key] = value; + setValue(space, space_obj); + return promises.as(true); + }, + readObject: function (space, key) { + var space_obj = getValue(space); + return promises.as(space_obj[key]); + }, + deleteObject: function (space, key, value) { + var space_obj = getValue(space); + delete space_obj[key]; + return promises.as(true); + } + }; + + provider.updateObject = provider.createObject; + + return provider; + + } + + return BrowserPersistenceProvider; + } +); From 0fde10a818f0716af3f5ef7956ad6bbafa2b3ca1 Mon Sep 17 00:00:00 2001 From: larkin Date: Wed, 22 Jul 2015 11:00:18 -0700 Subject: [PATCH 27/36] [Continuous] Procfile uses localstorage --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 659947f3b8..aa6094edfe 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: node app.js --port $PORT \ No newline at end of file +web: node app.js --port $PORT --include example/localstorage \ No newline at end of file From 12b8408bca9e9be926e4dedef2ca9d9a5a12e09b Mon Sep 17 00:00:00 2001 From: larkin Date: Wed, 22 Jul 2015 15:32:20 -0700 Subject: [PATCH 28/36] [Entanglement] Enable Entanglement --- bundles.json | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles.json b/bundles.json index f69e127eec..0b97f1abab 100644 --- a/bundles.json +++ b/bundles.json @@ -20,6 +20,7 @@ "platform/forms", "platform/persistence/queue", "platform/policy", + "platform/entanglement", "example/imagery", "example/persistence", From 3fe9170c7def84f1f39a7fdd0b062a2b2d516e95 Mon Sep 17 00:00:00 2001 From: larkin Date: Fri, 24 Jul 2015 15:34:26 -0700 Subject: [PATCH 29/36] [Gitignore] Ignore jsdoc output --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3188d5fa38..16b1dbfdac 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ closed-lib # Node dependencies node_modules + +# Build documentation +docs From ee34b74ca11ddc42d7ab1dc2026f0f000f5bdc06 Mon Sep 17 00:00:00 2001 From: larkin Date: Fri, 24 Jul 2015 16:21:15 -0700 Subject: [PATCH 30/36] [Style] Test config is JSLint approved --- karma.conf.js | 1 + test-main.js | 11 ++--------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index b47841019e..c8a25ba2eb 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,3 +1,4 @@ +/*global module*/ module.exports = function(config) { config.set({ diff --git a/test-main.js b/test-main.js index d687656e68..141d216fc8 100644 --- a/test-main.js +++ b/test-main.js @@ -1,3 +1,4 @@ +/*global require,window*/ var allTestFiles = []; var TEST_REGEXP = /(Spec)\.js$/; @@ -12,7 +13,7 @@ Object.keys(window.__karma__.files).forEach(function(file) { } }); -// We will be handling es6-promise loading with a shim. +// Force es6-promise to load. allTestFiles.unshift('es6-promise'); require.config({ @@ -23,14 +24,6 @@ require.config({ 'es6-promise': 'platform/framework/lib/es6-promise-2.0.0.min', 'moment-duration-format': 'warp/clock/lib/moment-duration-format' }, - shim: { - 'es6-promise': { - init: function () { - console.log('I was inited!'); - window.Promise = window.Promise || ES6Promise.Promise; - } - } - }, // dynamically load all test files deps: allTestFiles, From 44ee21d61315eddaea1f75fa01be84e3187d989a Mon Sep 17 00:00:00 2001 From: larkin Date: Fri, 24 Jul 2015 16:41:10 -0700 Subject: [PATCH 31/36] [Continuous] Push docs to correct repository --- build-docs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-docs.sh b/build-docs.sh index 510de0041d..bbb6d866af 100755 --- a/build-docs.sh +++ b/build-docs.sh @@ -2,11 +2,11 @@ # Script to build and deploy docs to github pages. -# Any Content currently visible on the website will be replaced by +# Any Content currently visible on the website will be replaced by # this process. OUTPUT_DIRECTORY="docs" -REPOSITORY_URL="git@github.com:larkin/openmctweb.git" +REPOSITORY_URL="git@github.com:nasa/openmctweb.git" BUILD_SHA=`git rev-parse head` From 09519cf6d47832447b2bce2dc212fe36554833a9 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 24 Jul 2015 17:07:49 -0700 Subject: [PATCH 32/36] [Continuous] Set commit author, fix grammar --- build-docs.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-docs.sh b/build-docs.sh index bbb6d866af..ae47035f41 100755 --- a/build-docs.sh +++ b/build-docs.sh @@ -16,8 +16,8 @@ REMOTE_NAME="documentation" WEBSITE_BRANCH="gh-pages" # Configure github for CircleCI user. -git config --global user.email "buildbot@circleci.com" -git config --global user.name "BuildBot" +git config user.email "buildbot@circleci.com" +git config user.name "BuildBot" # clean output directory if [ -d $OUTPUT_DIRECTORY ]; then @@ -39,4 +39,4 @@ git commit -m "Generate docs from build $BUILD_SHA" echo "git push $REMOTE_NAME HEAD:$WEBSITE_BRANCH -f" git push $REMOTE_NAME HEAD:$WEBSITE_BRANCH -f -echo "Documentation pushed gh-pages branch." \ No newline at end of file +echo "Documentation pushed to gh-pages branch." From 36ac5aa4de2e8f4e496d9a251f3dec16907487f5 Mon Sep 17 00:00:00 2001 From: larkin Date: Fri, 24 Jul 2015 16:47:31 -0700 Subject: [PATCH 33/36] [Style] JSLint compliance --- .../src/LocalStoragePersistenceProvider.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/example/localstorage/src/LocalStoragePersistenceProvider.js b/example/localstorage/src/LocalStoragePersistenceProvider.js index b01e6a569b..e8b1493b29 100644 --- a/example/localstorage/src/LocalStoragePersistenceProvider.js +++ b/example/localstorage/src/LocalStoragePersistenceProvider.js @@ -1,3 +1,4 @@ +/*global define,localStorage*/ /** * Stubbed implementation of a persistence provider, * to permit objects to be created, saved, etc. @@ -13,20 +14,21 @@ define( as: function (value) { return $q.when(value); } - }; + }, + provider; - var setValue = function(key, value) { + function setValue(key, value) { localStorage[key] = JSON.stringify(value); - }; + } - var getValue = function(key) { + function getValue(key) { if (localStorage[key]) { return JSON.parse(localStorage[key]); } return {}; - }; + } - var provider = { + provider = { listSpaces: function () { return promises.as(spaces); }, From 60cdc0eb6d73ed2af585d775cd74dd86cb9bc7c8 Mon Sep 17 00:00:00 2001 From: larkin Date: Fri, 24 Jul 2015 16:50:49 -0700 Subject: [PATCH 34/36] [Licensing] Add license header to applicable files --- build-docs.sh | 29 +++++++++++++++---- .../src/LocalStoragePersistenceProvider.js | 22 ++++++++++++++ karma.conf.js | 22 ++++++++++++++ test-main.js | 22 ++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-) diff --git a/build-docs.sh b/build-docs.sh index ae47035f41..a2494cb9bb 100755 --- a/build-docs.sh +++ b/build-docs.sh @@ -1,9 +1,28 @@ #!/bin/bash -# Script to build and deploy docs to github pages. +#***************************************************************************** +#* 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. +#***************************************************************************** -# Any Content currently visible on the website will be replaced by -# this process. +# Script to build and deploy docs to github pages. OUTPUT_DIRECTORY="docs" REPOSITORY_URL="git@github.com:nasa/openmctweb.git" @@ -11,7 +30,7 @@ REPOSITORY_URL="git@github.com:nasa/openmctweb.git" BUILD_SHA=`git rev-parse head` # A remote will be created for the git repository we are pushing to. -# Don't change the name. +# Don't worry, as this entire directory will get trashed inbetween builds. REMOTE_NAME="documentation" WEBSITE_BRANCH="gh-pages" @@ -19,7 +38,7 @@ WEBSITE_BRANCH="gh-pages" git config user.email "buildbot@circleci.com" git config user.name "BuildBot" -# clean output directory +# Clean output directory, JSDOC will recreate if [ -d $OUTPUT_DIRECTORY ]; then rm -rf $OUTPUT_DIRECTORY || exit 1 fi diff --git a/example/localstorage/src/LocalStoragePersistenceProvider.js b/example/localstorage/src/LocalStoragePersistenceProvider.js index e8b1493b29..8a367ca333 100644 --- a/example/localstorage/src/LocalStoragePersistenceProvider.js +++ b/example/localstorage/src/LocalStoragePersistenceProvider.js @@ -1,3 +1,25 @@ +/***************************************************************************** + * 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,localStorage*/ /** * Stubbed implementation of a persistence provider, diff --git a/karma.conf.js b/karma.conf.js index c8a25ba2eb..47aa3f059b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,3 +1,25 @@ +/***************************************************************************** + * 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 module*/ module.exports = function(config) { config.set({ diff --git a/test-main.js b/test-main.js index 141d216fc8..46740a93b2 100644 --- a/test-main.js +++ b/test-main.js @@ -1,3 +1,25 @@ +/***************************************************************************** + * 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 require,window*/ var allTestFiles = []; var TEST_REGEXP = /(Spec)\.js$/; From c6b0e4bf6f940c327fd4854a6b6f99112cf59ca1 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 24 Jul 2015 17:13:19 -0700 Subject: [PATCH 35/36] [Continuous] Set author after repo is initialized --- build-docs.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build-docs.sh b/build-docs.sh index a2494cb9bb..dd62c5ec41 100755 --- a/build-docs.sh +++ b/build-docs.sh @@ -34,10 +34,6 @@ BUILD_SHA=`git rev-parse head` REMOTE_NAME="documentation" WEBSITE_BRANCH="gh-pages" -# Configure github for CircleCI user. -git config user.email "buildbot@circleci.com" -git config user.name "BuildBot" - # Clean output directory, JSDOC will recreate if [ -d $OUTPUT_DIRECTORY ]; then rm -rf $OUTPUT_DIRECTORY || exit 1 @@ -48,6 +44,11 @@ cd $OUTPUT_DIRECTORY || exit 1 echo "git init" git init + +# Configure github for CircleCI user. +git config user.email "buildbot@circleci.com" +git config user.name "BuildBot" + echo "git remote add $REMOTE_NAME $REPOSITORY_URL" git remote add $REMOTE_NAME $REPOSITORY_URL echo "git add ." From e639d9ba8fc0e29f79ffeea657af0aee0badc080 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 24 Jul 2015 17:32:49 -0700 Subject: [PATCH 36/36] [Continuous] Only deploy from master branch --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 36c7c9b0b8..b8f367a604 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,6 @@ deployment: production: - branch: continuous-deployment + branch: master commands: - ./build-docs.sh - git push git@heroku.com:openmctweb-demo.git $CIRCLE_SHA1:refs/heads/master