Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Shivam Dave 2015-07-27 11:32:41 -07:00
commit a9418fd2c7
26 changed files with 823 additions and 203 deletions

2
.gitignore vendored
View File

@ -20,3 +20,5 @@ closed-lib
# Node dependencies # Node dependencies
node_modules node_modules
# Build documentation
docs

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: node app.js --port $PORT --include example/localstorage

62
build-docs.sh Executable file
View File

@ -0,0 +1,62 @@
#!/bin/bash
#*****************************************************************************
#* 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.
#*****************************************************************************
# Script to build and deploy docs to github pages.
OUTPUT_DIRECTORY="docs"
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 worry, as this entire directory will get trashed inbetween builds.
REMOTE_NAME="documentation"
WEBSITE_BRANCH="gh-pages"
# Clean output directory, JSDOC will recreate
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
# 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 ."
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 to gh-pages branch."

View File

@ -20,6 +20,7 @@
"platform/forms", "platform/forms",
"platform/persistence/queue", "platform/persistence/queue",
"platform/policy", "platform/policy",
"platform/entanglement",
"example/imagery", "example/imagery",
"example/persistence", "example/persistence",

6
circle.yml Normal file
View File

@ -0,0 +1,6 @@
deployment:
production:
branch: master
commands:
- ./build-docs.sh
- git push git@heroku.com:openmctweb-demo.git $CIRCLE_SHA1:refs/heads/master

View File

@ -0,0 +1,18 @@
{
"extensions": {
"components": [
{
"provides": "persistenceService",
"type": "provider",
"implementation": "LocalStoragePersistenceProvider.js",
"depends": [ "$q", "PERSISTENCE_SPACE" ]
}
],
"constants": [
{
"key": "PERSISTENCE_SPACE",
"value": "mct"
}
]
}
}

View File

@ -0,0 +1,86 @@
/*****************************************************************************
* 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,
* 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);
}
},
provider;
function setValue(key, value) {
localStorage[key] = JSON.stringify(value);
}
function getValue(key) {
if (localStorage[key]) {
return JSON.parse(localStorage[key]);
}
return {};
}
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;
}
);

10
jsdoc.json Normal file
View File

@ -0,0 +1,10 @@
{
"source": {
"include": [
"example/",
"platform/"
],
"includePattern": "(example|platform)/.+\\.js$",
"excludePattern": ".+\\Spec\\.js$|lib/.+"
}
}

79
karma.conf.js Normal file
View File

@ -0,0 +1,79 @@
/*****************************************************************************
* 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({
// 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
});
};

33
package.json Normal file
View File

@ -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"
}

View File

@ -32,6 +32,11 @@
"key": "LocatorController", "key": "LocatorController",
"implementation": "creation/LocatorController", "implementation": "creation/LocatorController",
"depends": [ "$scope" ] "depends": [ "$scope" ]
},
{
"key": "MenuArrowController",
"implementation": "MenuArrowController",
"depends": [ "$scope" ]
} }
], ],
"controls": [ "controls": [
@ -71,6 +76,12 @@
"key": "object-header", "key": "object-header",
"templateUrl": "templates/browse/object-header.html", "templateUrl": "templates/browse/object-header.html",
"uses": [ "type" ] "uses": [ "type" ]
},
{
"key": "menu-arrow",
"templateUrl": "templates/menu-arrow.html",
"uses": [ "action" ],
"gestures": [ "menu" ]
} }
], ],
"services": [ "services": [

View File

@ -20,11 +20,11 @@
at runtime from the About dialog for additional information. at runtime from the About dialog for additional information.
--> -->
<div class='object-header'> <div class='object-header'>
<span class="label s-label"> <span class="label s-label">
<span class='type-icon icon ui-symbol'>{{type.getGlyph()}}</span> <span class='type-icon icon ui-symbol'>{{type.getGlyph()}}</span>
<span ng-if="parameters.mode" class='action'>{{parameters.mode}}</span> <span ng-if="parameters.mode" class='action'>{{parameters.mode}}</span>
<span class='type-name'>{{type.getName()}}</span> <span class='type-name'>{{type.getName()}}</span>
<span class='title-label'>{{model.name}}</span> <span class='title-label'>{{model.name}}</span>
<a id='actions-menu' class='ui-symbol context-available' onclick="alert('Not yet functional. This will display a dropdown menu of options for this object.');">v</a> <mct-representation key="'menu-arrow'" mct-object='domainObject'></mct-representation>
</span> </span>
</div> </div>

View File

@ -0,0 +1,26 @@
<!--
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.
-->
<span ng-controller="MenuArrowController as menuArrow">
<a class='ui-symbol context-available'
ng-click='menuArrow.showMenu($event)'>v</a>
</span>

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* 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 MenuArrowController. 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($scope) {
function showMenu(event) {
var actionContext = {key: 'menu', domainObject: $scope.domainObject, event: event};
$scope.domainObject.getCapability('action').perform(actionContext);
}
return {
showMenu: showMenu
};
}
return MenuArrowController;
}
);

View File

@ -0,0 +1,81 @@
/*****************************************************************************
* 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/MenuArrowController"],
function (MenuArrowController) {
"use strict";
describe("The menu arrow controller ", function () {
var mockScope,
mockDomainObject,
mockEvent,
mockContextMenuAction,
mockActionContext,
controller;
beforeEach(function () {
mockScope = jasmine.createSpyObj(
"$scope",
[ "" ]
);
mockDomainObject = jasmine.createSpyObj(
"domainObject",
[ "getCapability" ]
);
mockEvent = jasmine.createSpyObj(
"event",
[ "preventDefault" ]
);
mockContextMenuAction = jasmine.createSpyObj(
"action",
[ "perform", "getActions" ]
);
mockActionContext = jasmine.createSpyObj(
"actionContext",
[ "" ]
);
mockActionContext.domainObject = mockDomainObject;
mockActionContext.event = mockEvent;
mockScope.domainObject = mockDomainObject;
mockDomainObject.getCapability.andReturn(mockContextMenuAction);
mockContextMenuAction.perform.andReturn(jasmine.any(Function));
controller = new MenuArrowController(mockScope);
});
it("calls the context menu action when clicked", function () {
// Simulate a click on the menu arrow
controller.showMenu(mockEvent);
// Expect the menu action to be performed
expect(mockDomainObject.getCapability).toHaveBeenCalledWith('action');
expect(mockContextMenuAction.perform).toHaveBeenCalled();
});
});
}
);

View File

@ -1,6 +1,7 @@
[ [
"BrowseController", "BrowseController",
"BrowseObjectController", "BrowseObjectController",
"MenuArrowController",
"creation/CreateAction", "creation/CreateAction",
"creation/CreateActionProvider", "creation/CreateActionProvider",
"creation/CreateMenuController", "creation/CreateMenuController",

View File

@ -50,7 +50,7 @@ define(
* expand-to-show-navigated-object behavior.) * expand-to-show-navigated-object behavior.)
* @constructor * @constructor
*/ */
function TreeNodeController($scope, $timeout) { function TreeNodeController($scope, $timeout, $rootScope) {
var selectedObject = ($scope.ngModel || {}).selectedObject, var selectedObject = ($scope.ngModel || {}).selectedObject,
isSelected = false, isSelected = false,
hasBeenExpanded = false; hasBeenExpanded = false;
@ -138,7 +138,7 @@ define(
selectedObject = object; selectedObject = object;
checkSelection(); checkSelection();
} }
// Listen for changes which will effect display parameters // Listen for changes which will effect display parameters
$scope.$watch("ngModel.selectedObject", setSelection); $scope.$watch("ngModel.selectedObject", setSelection);
$scope.$watch("domainObject", checkSelection); $scope.$watch("domainObject", checkSelection);

View File

@ -35,7 +35,7 @@ define(
* *
* @param {string} id the object's unique identifier * @param {string} id the object's unique identifier
* @param {object} model the "JSONifiable" state of the object * @param {object} model the "JSONifiable" state of the object
* @param {Object.<string, Capability|function} capabilities all * @param {Object.<string, Capability>|function} capabilities all
* capabilities to be exposed by this object * capabilities to be exposed by this object
* @constructor * @constructor
*/ */

View File

@ -45,7 +45,7 @@ define(
* into one large object containing resolved extensions from * into one large object containing resolved extensions from
* all bundles (in the same form.) * all bundles (in the same form.)
* *
* @param {Object.<string, object[]>[]} resolvedBundles * @param {Object.<string, object[]>|Array} resolvedBundles
* @returns {Object.<string, object[]>} * @returns {Object.<string, object[]>}
*/ */
function mergeResolvedBundles(resolvedBundles) { function mergeResolvedBundles(resolvedBundles) {

View File

@ -26,7 +26,7 @@
{ {
"key": "menu", "key": "menu",
"implementation": "gestures/ContextMenuGesture.js", "implementation": "gestures/ContextMenuGesture.js",
"depends": [ "$compile", "$document", "$window", "$rootScope" ] "depends": []
} }
], ],
"components": [ "components": [
@ -49,6 +49,13 @@
"implementation": "services/DndService.js", "implementation": "services/DndService.js",
"depends": [ "$log" ] "depends": [ "$log" ]
} }
],
"actions": [
{
"key": "menu",
"implementation": "actions/ContextMenuAction.js",
"depends": [ "$compile", "$document", "$window", "$rootScope" ]
}
] ]
} }
} }

View File

@ -0,0 +1,116 @@
/*****************************************************************************
* 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 = "<mct-representation key=\"'context-menu'\" " +
"mct-object=\"domainObject\" " +
"ng-class=\"menuClass\"" +
"ng-style=\"menuStyle\">" +
"</mct-representation>",
dismissExistingMenu;
/**
* 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 actionContexr the context in which the action
* should be performed
*/
function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) {
function 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;
}
// 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);
// 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);
// Don't launch browser's context menu
actionContext.event.preventDefault();
}
return {
perform: perform
};
}
return ContextMenuAction;
}
);

View File

@ -22,102 +22,41 @@
/*global define,Promise*/ /*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( define(
["./GestureConstants"], function () {
function (GestureConstants) {
"use strict"; "use strict";
var MENU_TEMPLATE = "<mct-representation key=\"'context-menu'\" " +
"mct-object=\"domainObject\" " +
"ng-class=\"menuClass\"" +
"ng-style=\"menuStyle\">" +
"</mct-representation>",
dismissExistingMenu;
/** /**
* Add listeners to a representation such that it launches a * Add listeners to a representation such that it calls the
* custom context menu for the domain object it contains. * context menu action for the domain object it contains.
* *
* @constructor * @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 * @param element the jqLite-wrapped element which should exhibit
* the context mennu * the context mennu
* @param {DomainObject} domainObject the object on which actions * @param {DomainObject} domainObject the object on which actions
* in the context menu will be performed * in the context menu will be performed
*/ */
function ContextMenuGesture($compile, $document, $window, $rootScope, element, domainObject) { function ContextMenuGesture(element, domainObject) {
function showMenu(event) { var actionContext,
var winDim = [$window.innerWidth, $window.innerHeight], stop;
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;
// 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
};
// 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
event.preventDefault();
}
// When context menu event occurs, show object actions instead // When context menu event occurs, show object actions instead
element.on('contextmenu', showMenu); element.on('contextmenu', function (event) {
actionContext = {key: 'menu', domainObject: domainObject, event: event};
stop = domainObject.getCapability('action').perform(actionContext);
});
return { return {
/** /**
* Detach any event handlers associated with this gesture, * Detach any event handlers associated with this gesture.
* and dismiss any visible menu.
* @method * @method
* @memberof ContextMenuGesture * @memberof ContextMenuGesture
*/ */
destroy: function () { destroy: function () {
// Scope has been destroyed, so remove all listeners. element.off('contextmenu', stop);
if (dismissExistingMenu) {
dismissExistingMenu();
}
element.off('contextmenu', showMenu);
} }
}; };
} }

View File

@ -0,0 +1,140 @@
/*****************************************************************************
* 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,
mockActionContext,
action;
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);
mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent};
action = new ContextMenuAction(
mockCompile,
mockDocument,
mockWindow,
mockRootScope,
mockActionContext
);
});
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 () {
action.perform();
expect(mockEvent.preventDefault).toHaveBeenCalled();
});
it("positions menus where clicked", function () {
mockEvent.pageX = 10;
mockEvent.pageY = 5;
action.perform();
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;
action.perform();
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
action.perform();
// Verify precondition
expect(mockBody.off).not.toHaveBeenCalled();
// Find and fire body's mousedown listener
mockBody.on.calls.forEach(function (call) {
if (call.args[0] === 'mousedown') {
call.args[1]();
}
});
// Menu should have been removed
expect(mockMenu.remove).toHaveBeenCalled();
// Listener should have been detached from body
expect(mockBody.off).toHaveBeenCalled();
});
});
}
);

View File

@ -26,58 +26,27 @@
* Module defining ContextMenuGestureSpec. Created by vwoeltje on 11/22/14. * Module defining ContextMenuGestureSpec. Created by vwoeltje on 11/22/14.
*/ */
define( define(
["../../src/gestures/ContextMenuGesture", "../../src/gestures/GestureConstants"], ["../../src/gestures/ContextMenuGesture"],
function (ContextMenuGesture, GestureConstants) { function (ContextMenuGesture) {
"use strict"; "use strict";
var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ], var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ],
DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ], DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ];
MENU_DIMENSIONS = GestureConstants.MCT_MENU_DIMENSIONS;
describe("The 'context menu' gesture", function () { describe("The 'context menu' gesture", function () {
var mockCompile, var mockElement,
mockCompiledTemplate,
mockMenu,
mockDocument,
mockBody,
mockWindow,
mockRootScope,
mockScope,
mockElement,
mockDomainObject, mockDomainObject,
mockEvent, mockEvent,
gesture, gesture,
fireGesture; fireGesture;
beforeEach(function () { 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); mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
mockEvent = jasmine.createSpyObj("event", ["preventDefault"]); mockEvent = jasmine.createSpyObj("event", ["preventDefault"]);
mockEvent.pageX = 0;
mockEvent.pageY = 0;
mockCompile.andReturn(mockCompiledTemplate); gesture = new ContextMenuGesture(mockElement, mockDomainObject);
mockCompiledTemplate.andReturn(mockMenu);
mockDocument.find.andReturn(mockBody);
mockRootScope.$new.andReturn(mockScope);
gesture = new ContextMenuGesture(
mockCompile,
mockDocument,
mockWindow,
mockRootScope,
mockElement,
mockDomainObject
);
// Capture the contextmenu callback // Capture the contextmenu callback
fireGesture = mockElement.on.mostRecentCall.args[1]; fireGesture = mockElement.on.mostRecentCall.args[1];
@ -97,85 +66,10 @@ define(
expect(mockElement.off).toHaveBeenCalledWith( expect(mockElement.off).toHaveBeenCalledWith(
"contextmenu", "contextmenu",
mockElement.on.mostRecentCall.args[1] //mockElement.on.mostRecentCall.args[1]
mockDomainObject.calls
); );
}); });
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();
});
}); });
} }
); );

View File

@ -1,4 +1,5 @@
[ [
"actions/ContextMenuAction",
"gestures/ContextMenuGesture", "gestures/ContextMenuGesture",
"gestures/DragGesture", "gestures/DragGesture",
"gestures/DropGesture", "gestures/DropGesture",

55
test-main.js Normal file
View File

@ -0,0 +1,55 @@
/*****************************************************************************
* 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$/;
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));
}
});
// Force es6-promise to load.
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'
},
// dynamically load all test files
deps: allTestFiles,
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
});