Compare commits

...

39 Commits

Author SHA1 Message Date
407550e6f4 [Selection] Inject actionRegistry 2016-09-23 15:48:43 -07:00
8b44b44e38 [Selection] Generalize Registry 2016-09-23 15:46:45 -07:00
8dfa8df28a [Selection] Allow providers to return array
...to allow one-to-many providers for actions, as is useful
for Create et al (and, in this specific case, to support
adapters.)
2016-09-23 15:45:46 -07:00
9e19296b14 [Selection] Add ActionRegistry 2016-09-23 15:35:40 -07:00
106632c21c [Selection] Remove unused import 2016-09-23 15:32:40 -07:00
235032a571 [Selection] Wire in new contextmenu 2016-09-23 15:27:39 -07:00
db41f6e64f [Selection] Obey priority order 2016-09-23 15:19:16 -07:00
e83e0da521 [Selection] Export openmct from main.js 2016-09-23 15:16:32 -07:00
c411f8fbe3 [Selection] Go through openmct API 2016-09-23 15:07:03 -07:00
4ce952846c [Selection] Expose context menu adapter 2016-09-22 11:51:00 -07:00
fdab4a614f [Selection] Expose contextual gesture 2016-09-22 11:48:44 -07:00
152f55652f [Selection] Add adapter for context menu 2016-09-22 11:46:37 -07:00
c46c42e576 [Selection] Sketch in AngularView
...for use in the adapter layer.
2016-09-21 15:39:56 -07:00
75bf956c3d [Selection] Use context typedef 2016-09-21 14:54:22 -07:00
0a44c48338 [Selection] Sketch in context menu gesture 2016-09-21 13:27:59 -07:00
e4c3412e8a [Selection] Sketch in context menu view 2016-09-21 13:16:24 -07:00
4e1cfac4b9 [Selection] Expose inspector registry 2016-09-21 12:30:36 -07:00
0a64e9f515 [Selection] Add ViewRegistry 2016-09-21 12:29:43 -07:00
7341ed9d03 [Selection] Handle selection changes
...from the InspectorRegion
2016-09-21 12:26:57 -07:00
e2631bdcfd [Selection] Listen/unlisten to selection
...from the inspector region
2016-09-21 11:27:24 -07:00
773a7c0c24 [Selection] Begin adding Inspector region 2016-09-21 11:25:21 -07:00
fdcba66558 [Selection] Add legacy bundle
...to act as an adapter to legacy registration API
2016-09-14 11:54:19 -07:00
3b1ed7821f [Selection] Add openmct module
...to expose selection APIs
2016-09-14 11:50:36 -07:00
1be517f3ea [Selection] Don't reuse old paths for new items 2016-09-14 11:46:06 -07:00
5e3dcadfa4 Merge remote-tracking branch 'origin/master' into subobject-selection-1126
Conflicts:
	bower.json
	main.js
	test-main.js
2016-09-14 11:06:05 -07:00
fd97f4db41 [Selection] Begin implementing Hover gesture 2016-08-25 13:15:37 -07:00
3228a83802 [Selection] Begin adding hover gesture 2016-08-22 16:32:48 -07:00
1dba551fc6 [Selection] Force single select
...as a simplifying assumption for the initial prototype.
2016-08-22 16:07:01 -07:00
20f3b57ddd [Selection] Release listeners 2016-08-22 14:20:34 -07:00
58787c4436 [Selection] Remove obsolete include 2016-08-22 14:13:46 -07:00
2a45893602 [Selection] Begin adding context management 2016-08-22 13:22:17 -07:00
a94ab44431 [Selection] Toggle selected class 2016-08-22 12:24:40 -07:00
cc9efdff31 [Selection] At Path.toArray 2016-08-22 12:17:29 -07:00
6e664003e3 [Sub-object] Sketch in SelectGesture 2016-08-18 13:11:09 -07:00
70d804fc49 [Sub-object] Emit change events 2016-08-18 11:54:05 -07:00
06c184821e [Sub-object] Add Path.append 2016-08-18 11:51:09 -07:00
b76be3d2e5 [Sub-object] Basic Path/Selection implementation 2016-08-18 11:45:13 -07:00
8934ba96f7 [Sub-object] Add empty Selection class 2016-08-18 10:33:34 -07:00
3fb4ce7819 [Sub-object] Add EventEmitter dependency
Selection state will be represented in #1126 by an EventEmitter.
2016-08-17 16:32:44 -07:00
18 changed files with 564 additions and 11 deletions

View File

@ -19,6 +19,7 @@
"comma-separated-values": "^3.6.4",
"FileSaver.js": "^0.0.2",
"zepto": "^1.1.6",
"eventemitter3": "^1.2.0",
"html2canvas": "^0.4.1",
"jspdf": "^1.2.61"
}

View File

@ -28,12 +28,12 @@
<script src="bower_components/requirejs/require.js">
</script>
<script>
require(['main'], function (mct) {
require(['main'], function (openmct) {
require([
'./example/imagery/bundle',
'./example/eventGenerator/bundle',
'./example/generator/bundle'
], mct.run.bind(mct));
], openmct.start.bind(openmct));
});
</script>
<link rel="stylesheet" href="platform/commonUI/general/res/css/startup-base.css">

21
main.js
View File

@ -27,6 +27,7 @@ requirejs.config({
"angular": "bower_components/angular/angular.min",
"angular-route": "bower_components/angular-route/angular-route.min",
"csv": "bower_components/comma-separated-values/csv.min",
"EventEmitter": "bower_components/eventemitter3/index",
"es6-promise": "bower_components/es6-promise/es6-promise.min",
"html2canvas": "bower_components/html2canvas/build/html2canvas.min",
"jsPDF": "bower_components/jspdf/dist/jspdf.min",
@ -45,6 +46,9 @@ requirejs.config({
"angular-route": {
"deps": ["angular"]
},
"EventEmitter": {
"exports": "EventEmitter"
},
"html2canvas": {
"exports": "html2canvas"
},
@ -64,6 +68,7 @@ requirejs.config({
});
define([
'./src/openmct',
'./platform/framework/src/Main',
'legacyRegistry',
@ -101,12 +106,12 @@ define([
'./platform/entanglement/bundle',
'./platform/search/bundle',
'./platform/status/bundle',
'./platform/commonUI/regions/bundle'
], function (Main, legacyRegistry) {
return {
legacyRegistry: legacyRegistry,
run: function () {
return new Main().run(legacyRegistry);
}
};
'./platform/commonUI/regions/bundle',
'./src/adapter/legacyBundle'
], function (openmct, Main, legacyRegistry) {
openmct.legacyRegistry = legacyRegistry;
openmct.on('start', function () {
return new Main().run(legacyRegistry);
});
return openmct;
});

View File

@ -72,7 +72,7 @@ define(
// Assemble all gestures into a map, for easy look up
gestures.forEach(function (gesture) {
gestureMap[gesture.key] = gesture;
gestureMap[gesture.key] = gestureMap[gesture.key] || gesture;
});
this.gestureMap = gestureMap;

21
src/Registry.js Normal file
View File

@ -0,0 +1,21 @@
define([], function () {
function Registry() {
this.providers = [];
}
Registry.prototype.get = function (context) {
return this.providers.filter(function (provider) {
return provider.appliesTo(context);
}).map(function (provider) {
return provider.get(context);
}).reduce(function (a, b) {
return Array.isArray(b) ? a.concat(b) : a.concat([b]);
}, []);
};
Registry.prototype.register = function (provider) {
this.providers.push(provider);
};
return Registry;
});

View File

@ -0,0 +1,9 @@
define(
function () {
function AdaptedContextMenuGesture(openmct, $els, domainObject) {
this.destroy = openmct.gestures.contextual($els[0], domainObject);
}
return AdaptedContextMenuGesture;
}
);

View File

@ -0,0 +1,48 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
define([
'legacyRegistry',
'./gestures/AdaptedContextMenuGesture',
'../openmct'
], function (legacyRegistry, AdaptedContextMenuGesture, openmct) {
legacyRegistry.register('adapter', {
extensions: {
services: [
{
key: "openmct",
implementation: function () {
return openmct;
}
}
],
gestures: [
{
key: "menu",
implementation: AdaptedContextMenuGesture,
priority: "preferred",
depends: ["openmct"]
}
]
}
});
});

View File

@ -0,0 +1,28 @@
define(['angular'], function (angular) {
function AngularView(template) {
this.template = template;
}
AngularView.prototype.show = function (container) {
if (this.activeScope) {
this.destroy();
}
var $injector = angular.injector(['ng']);
var $compile = $injector.get('$compile');
var $rootScope = $injector.get('$rootScope');
var $scope = $rootScope.$new();
var elements = $compile(this.template)($scope);
angular.element(container).append(elements);
};
AngularView.prototype.destroy = function () {
if (this.activeScope) {
this.activeScope.$destroy();
this.activeScope = undefined;
}
};
return AngularView;
});

65
src/openmct.js Normal file
View File

@ -0,0 +1,65 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
define([
'EventEmitter',
'./Registry',
'./selection/Selection',
'./selection/ContextManager',
'./selection/SelectGesture',
'./ui/menu/ContextMenuGesture',
'./ui/ViewRegistry'
], function (
EventEmitter,
Registry,
Selection,
ContextManager,
SelectGesture,
ContextMenuGesture,
ViewRegistry
) {
var openmct = Object.create(EventEmitter.prototype);
var actionRegistry = new Registry();
var selection = new Selection();
var manager = new ContextManager();
var select = new SelectGesture(manager, selection);
var contextMenu = new ContextMenuGesture(
selection,
{},
actionRegistry,
manager
);
EventEmitter.call(openmct);
openmct.selection = selection;
openmct.inspectors = new ViewRegistry();
openmct.gestures = {
selectable: select.apply.bind(select),
contextual: contextMenu.apply.bind(contextMenu)
};
openmct.start = openmct.emit.bind(openmct, 'start');
return openmct;
});

View File

@ -0,0 +1,77 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
define(['zepto'], function ($) {
/**
* @typedef Context
* @property {*} item
* @property {HTMLElement} element
* @property {Context} parent the containing context (may be undefined)
*/
function ContextManager() {
this.counter = 0;
this.contexts = {};
}
ContextManager.prototype.nextId = function () {
this.counter += 1;
return "context-" + this.counter;
};
ContextManager.prototype.context = function (item, htmlElement) {
var $element = $(htmlElement);
var id = $element.attr('data-context') || this.nextId();
$element.attr('data-context', id);
if (this.contexts[id] && this.contexts[id].item !== item) {
this.release(htmlElement);
}
if (!this.contexts[id]) {
var $parent = $element.closest('[data-context]');
var parentId = $parent.attr('data-context');
var parentContext = parentId ? this.contexts[parentId] : undefined;
this.contexts[id] = {
item: item,
element: htmlElement,
parent: parentContext
};
}
return this.contexts[id];
};
ContextManager.prototype.release = function (htmlElement) {
var $element = $(htmlElement);
var id = $element.attr('data-context');
if (id) {
delete this.contexts[id];
$element.removeAttr('data-context');
}
};
return ContextManager;
});

View File

@ -0,0 +1,58 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
define(['zepto'], function ($) {
function HoverGesture(hoverManager) {
this.hoverManager = hoverManager;
}
HoverGesture.prototype.apply = function (htmlElement) {
var $element = $(htmlElement);
var hoverManager = this.hoverManager;
function update() {
$(hoverManager.all()).removeClass('hovering');
$(hoverManager.top()).addClass('hovering');
}
function enter() {
hoverManager.add(htmlElement);
update();
}
function leave() {
hoverManager.remove(htmlElement);
update();
}
$element.on('mouseenter', enter);
$element.on('mouseleave', leave);
return function () {
leave();
$element.off('mouseenter', enter);
$element.off('mouseleave', leave);
}.bind(this);
};
return HoverGesture;
});

View File

@ -0,0 +1,60 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
define(['zepto'], function ($) {
function SelectGesture(selection, contextManager) {
this.selection = selection;
this.contextManager = contextManager;
}
SelectGesture.prototype.apply = function (htmlElement, item) {
var $element = $(htmlElement);
var contextManager = this.contextManager;
var selection = this.selection;
var path = contextManager.path(item, htmlElement);
function select() {
selection.add(path);
}
function change() {
var selected = selection.primary();
$element.toggleClass(
'selected',
selected && path.matches(selected)
);
}
$element.addClass('selectable');
$element.on('click', select);
selection.on('change', change);
change(); // Initialize
return function () {
contextManager.release(htmlElement);
$element.off('click', select);
selection.off('change', change);
};
};
return SelectGesture;
});

View File

@ -0,0 +1,64 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
define(['EventEmitter'], function (EventEmitter) {
function Selection() {
EventEmitter.call(this);
this.selected = [];
}
Selection.prototype = Object.create(EventEmitter.prototype);
Selection.prototype.add = function (path) {
this.clear(); // Only allow single select as initial simplification
this.selected.push(path);
this.emit('change');
};
Selection.prototype.remove = function (path) {
this.selected = this.selected.filter(function (otherPath) {
return !path.matches(otherPath);
});
this.emit('change');
};
Selection.prototype.contains = function (path) {
return this.selected.some(function (otherPath) {
return path.matches(otherPath);
});
};
Selection.prototype.clear = function () {
this.selected = [];
this.emit('change');
};
Selection.prototype.primary = function () {
return this.selected[this.selected.length - 1];
};
Selection.prototype.all = function () {
return this.selected;
};
return Selection;
});

43
src/ui/InspectorRegion.js Normal file
View File

@ -0,0 +1,43 @@
define(['zepto'], function ($) {
function InspectorRegion(element, selection, inspectors) {
this.element = element;
this.selection = selection;
this.inspectors = inspectors;
this.active = false;
this.onSelectionChange = this.onSelectionChange.bind(this);
}
InspectorRegion.prototype.onSelectionChange = function (item) {
var $element = $(this.element);
var providers = this.inspectors.get(item);
$element.empty();
if (factories.length > 0) {
providers[0].view(item).show(this.element);
}
};
InspectorRegion.prototype.activate = function () {
if (this.active) {
this.deactivate();
}
this.selection.on('change', this.onSelectionChange);
this.active = true;
};
InspectorRegion.prototype.deactivate = function () {
if (!this.active) {
return;
}
this.selection.off('change', this.onSelectionChange);
this.active = false;
};
return InspectorRegion;
});

18
src/ui/ViewRegistry.js Normal file
View File

@ -0,0 +1,18 @@
define([], function () {
function ViewRegistry() {
this.providers = [];
}
ViewRegistry.prototype.get = function (item) {
return this.providers.filter(function (provider) {
return provider.canView(item);
});
};
ViewRegistry.prototype.addProvider = function (provider) {
this.providers.push(provider);
};
return ViewRegistry;
});

View File

@ -0,0 +1,42 @@
define(['zepto', './ContextMenuView'], function ($, ContextMenuView) {
function ContextMenuGesture(
selection,
overlayManager,
actionRegistry,
contextManager
) {
this.selection = selection;
this.overlayManager = overlayManager;
this.actionRegistry = actionRegistry;
this.contextManager = contextManager;
}
ContextMenuGesture.prototype.apply = function (htmlElement, item) {
var overlayManager = this.overlayManager;
var selection = this.selection;
var actionRegistry = this.actionRegistry;
var contextManager = this.contextManager;
var $element = $(htmlElement);
var context = contextManager.context(item, htmlElement);
function showMenu(event) {
selection.add(context);
var x = event.clientX;
var y = event.clientY;
var actions = actionRegistry.get(context);
var view = new ContextMenuView(actions);
overlayManager.show(view, x, y);
event.preventDefault();
}
$element.on('contextmenu', showMenu);
return $element.off.bind($element, 'contextmenu', showMenu);
};
return ContextMenuGesture;
});

View File

@ -0,0 +1,10 @@
define(['zepto'], function ($) {
function ContextMenuView(actions) {
this.actions = actions;
}
ContextMenuView.prototype.show = function (element) {
};
return ContextMenuView;
});

View File

@ -53,6 +53,7 @@ requirejs.config({
"angular": "bower_components/angular/angular.min",
"angular-route": "bower_components/angular-route/angular-route.min",
"csv": "bower_components/comma-separated-values/csv.min",
"EventEmitter": "bower_components/eventemitter3/index",
"es6-promise": "bower_components/es6-promise/es6-promise.min",
"html2canvas": "bower_components/html2canvas/build/html2canvas.min",
"jsPDF": "bower_components/jspdf/dist/jspdf.min",
@ -72,6 +73,9 @@ requirejs.config({
"angular-route": {
"deps": [ "angular" ]
},
"EventEmitter": {
"exports": "EventEmitter"
},
"moment-duration-format": {
"deps": [ "moment" ]
},