mirror of
https://github.com/nasa/openmct.git
synced 2025-06-25 10:44:21 +00:00
Compare commits
1 Commits
api-tutori
...
proposed-v
Author | SHA1 | Date | |
---|---|---|---|
3b86e02ed3 |
309
API.md
309
API.md
@ -1,114 +1,285 @@
|
||||
# Open MCT API
|
||||
|
||||
The Open MCT framework public api can be utilized by building the application (`gulp install`) and then copying the file from `dist/main.js` to your directory
|
||||
of choice.
|
||||
The Open MCT framework public api can be utilized by building the application
|
||||
(`gulp install`) and then copying the file from `dist/main.js` to your
|
||||
directory of choice.
|
||||
|
||||
Open MCT supports AMD, CommonJS, and standard browser loading; it's easy to use
|
||||
in your project.
|
||||
Open MCT supports AMD, CommonJS, and loading via a script tag; it's easy to use
|
||||
in your project. The [`openmct`]{@link module:openmct} module is exported
|
||||
via AMD and CommonJS, and is also exposed as `openmct` in the global scope
|
||||
if loaded via a script tag.
|
||||
|
||||
## Overview
|
||||
|
||||
Open MCT's goal is to allow you to browse, create, edit, and visualize all of the domain knowledge you need on a daily basis.
|
||||
Open MCT's goal is to allow you to browse, create, edit, and visualize all of
|
||||
the domain knowledge you need on a daily basis.
|
||||
|
||||
To do this, the main building block provided by Open MCT is the domain object-- the temperature sensor on the starboard solar panel, an overlay plot comparing the results of all temperature sensor, the command dictionary for a spacecraft, the individual commands in that dictionary, your "my documents" folder: all of these things are domain objects.
|
||||
To do this, the main building block provided by Open MCT is the _domain object_.
|
||||
The temperature sensor on the starboard solar panel,
|
||||
an overlay plot comparing the results of all temperature sensor,
|
||||
the command dictionary for a spacecraft,
|
||||
the individual commands in that dictionary, your "my documents" folder:
|
||||
All of these things are domain objects.
|
||||
|
||||
Domain objects have Types-- so a specific instrument temperature sensor is a "Telemetry Point," and turning on a drill for a certain duration of time is an "Activity". Types allow you to form an ontology of knowledge and provide an abstraction for grouping, visualizing, and interpreting data.
|
||||
Domain objects have Types, so a specific instrument temperature sensor is a
|
||||
"Telemetry Point," and turning on a drill for a certain duration of time is
|
||||
an "Activity". Types allow you to form an ontology of knowledge and provide
|
||||
an abstraction for grouping, visualizing, and interpreting data.
|
||||
|
||||
And then we have Views. Views allow you to visualize a domain object. Views can apply to specific domain objects; they may also apply to certain types of domain objects, or they may apply to everything. Views are simply a method of visualizing domain objects.
|
||||
And then we have Views. Views allow you to visualize domain objects. Views can
|
||||
apply to specific domain objects; they may also apply to certain types of
|
||||
domain objects, or they may apply to everything. Views are simply a method
|
||||
of visualizing domain objects.
|
||||
|
||||
Regions allow you to specify what views are displayed for specific types of domain objects in response to different user actions-- for instance, you may want to display a different view while editing, or you may want to update the toolbar display when objects are selected. Regions allow you to map views to specific user actions.
|
||||
Regions allow you to specify what views are displayed for specific types of
|
||||
domain objects in response to different user actions. For instance, you may
|
||||
want to display a different view while editing, or you may want to update the
|
||||
toolbar display when objects are selected. Regions allow you to map views to
|
||||
specific user actions.
|
||||
|
||||
Domain objects can be mutated and persisted, developers can create custom actions and apply them to domain objects, and many more things can be done. For more information, read on.
|
||||
Domain objects can be mutated and persisted, developers can create custom
|
||||
actions and apply them to domain objects, and many more things can be done.
|
||||
For more information, read on!
|
||||
|
||||
## The API
|
||||
## Running Open MCT
|
||||
|
||||
### `MCT.Type(options)`
|
||||
Status: First Draft
|
||||
Once the [`openmct`](@link module:openmct) module has been loaded, you can
|
||||
simply invoke [`start`]{@link module:openmct.MCT#start} to run Open MCT:
|
||||
|
||||
Returns a `typeInstance`. `options` is an object supporting the following properties:
|
||||
|
||||
* `metadata`: `object` defining metadata used in displaying the object; has the following properties:
|
||||
* `label`: `string`, the human-readible name of the type. used in menus and inspector.
|
||||
* `glyph`: `string`, the name of the icon to display for this type, used in labels.
|
||||
* `description`: `string`, a human readible description of the object and what it is for.
|
||||
* `initialize`: `function` which initializes new instances of this type. it is called with an object, should add any default properties to that object.
|
||||
* `creatable`: `boolean`, if true, this object will be visible in the create menu.
|
||||
* `form`: `Array` an array of form fields, as defined... somewhere! Generates a property sheet that is visible while editing this object.
|
||||
```
|
||||
openmct.start();
|
||||
```
|
||||
|
||||
### `MCT.type(typeKey, typeInstance)`
|
||||
Status: First Draft
|
||||
Generally, however, you will want to configure Open MCT by adding plugins
|
||||
before starting it. It is important to install plugins and configure Open MCT
|
||||
_before_ calling [`start`]{@link module:openmct.MCT#start}; Open MCT is not
|
||||
designed to be reconfigured once started.
|
||||
|
||||
Register a `typeInstance` with a given Type `key` (a `string`). There can only be one `typeInstance` registered per type `key`. typeInstances must be registered before they can be utilized.
|
||||
## Configuring Open MCT
|
||||
|
||||
### `MCT.Objects`
|
||||
Status: First Draft
|
||||
The [`openmct`]{@link module:openmct} module (more specifically, the
|
||||
[`MCT`]{@link module:openmct.MCT} class, of which `openmct` is an instance)
|
||||
exposes a variety of methods to allow the application to be configured,
|
||||
extended, and customized before running.
|
||||
|
||||
Allows you to register object providers, which allows you to integrate domain objects from various different sources. Also implements methods for mutation and persistence of objects. See [Object API](src/api/objects/README.md) for more details.
|
||||
Short examples follow; see the linked documentation for further details.
|
||||
|
||||
### `MCT.Composition`
|
||||
Status: First Draft
|
||||
### Adding Domain Object Types
|
||||
|
||||
Objects can contain other objects, and the Composition API allows you to fetch the composition of any given domain object, or implement custom methods for defining composition as necessary.
|
||||
Custom types may be registered via
|
||||
[`openmct.types`]{@link module:openmct.MCT#types}:
|
||||
|
||||
### `MCT.view(region, definition)`
|
||||
Status: First Draft
|
||||
```
|
||||
openmct.types.addType('my-type', new openmct.Type({
|
||||
label: "My Type",
|
||||
description: "This is a type that I added!"
|
||||
});
|
||||
```
|
||||
|
||||
Register a view factory for a specific region. View factories receive an instance of a domain object and return a `View` for that object, or return undefined if they do not know how to generate a view for that object.
|
||||
### Adding Views
|
||||
|
||||
* `ViewDefinition`: an object with the following properties:
|
||||
* `canView(domainObject)`: should return truthy if the view is valid for a given domain object, falsy if it is not capable of generating a view for that object.
|
||||
* `view(domainObject)`: should instantate and return a `View` for the given object.
|
||||
* `metadata()`: a function that returns metadata about this view. Optional.
|
||||
* `View`: an object containing a number of lifecycle methods:
|
||||
* `view.show(container)`: instantiate a view (a set of dom elements) and attach it to the container.
|
||||
* `view.destroy(container)`: remove any listeners and expect your dom elements to be destroyed.
|
||||
Custom views may be registered based on the region in the application
|
||||
where they should appear:
|
||||
|
||||
For a basic introduction to views & types, check out these tutorials:
|
||||
* [`openmct.mainViews`]{@link module:openmct.MCT#mainViews} is a registry
|
||||
of views of domain objects which should appear in the main viewing area.
|
||||
* [`openmct.inspectors`]{@link module:openmct.MCT#inspectors} is a registry
|
||||
of views of domain objects and/or active selections, which should appear in
|
||||
the Inspector.
|
||||
* [`openmct.toolbars`]{@link module:openmct.MCT#toolbars} is a registry
|
||||
of views of domain objects and/or active selections, which should appear in
|
||||
the toolbar area while editing.
|
||||
* [`openmct.indicators`]{@link module:openmct.MCT#inspectors} is a registry
|
||||
of views which should appear in the status area of the application.
|
||||
|
||||
* [custom-view](custom-view.html) -- Implementing a custom view with vanilla javascript.
|
||||
* [custom-view-react](custom-view-react.html) -- Implementing a custom view with React.
|
||||
Example:
|
||||
|
||||
### `MCT.conductor`
|
||||
Status: First Draft
|
||||
```
|
||||
openmct.mainViews.addProvider({
|
||||
canView: function (domainObject) {
|
||||
return domainObject.type === 'my-type';
|
||||
},
|
||||
view: function (domainObject) {
|
||||
return new MyView(domainObject);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The time conductor is an API that facilitates time synchronization across multiple components. Components that would like to be "time aware" may attach listeners to the time conductor API to allow them to remain synchronized with other components. For more information ont he time conductor API, please look at the API draft here: https://github.com/nasa/openmct/blob/66220b89ca568075f107505ba414de9457dc0427/platform/features/conductor-redux/src/README.md
|
||||
### Adding a Root-level Object
|
||||
|
||||
### `MCT.selection`
|
||||
Status: First Draft
|
||||
In many cases, you'd like a certain object (or a certain hierarchy of
|
||||
objects) to be accessible from the top level of the application (the
|
||||
tree on the left-hand side of Open MCT.) It is typical to expose a telemetry
|
||||
dictionary as a hierarchy of telemetry-providing domain objects in this
|
||||
fashion.
|
||||
|
||||
Tracks the application's selection state (which elements of a view has a user selected?)
|
||||
To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method
|
||||
of the [object API]{@link module:openmct.ObjectAPI}:
|
||||
|
||||
One or more JavaScript objects may be selected at any given time. User code is responsible for any necessary type-checking.
|
||||
```
|
||||
openmct.objects.addRoot({
|
||||
identifier: { key: "my-key", namespace: "my-namespace" }
|
||||
name: "My Root-level Object",
|
||||
type: "my-type"
|
||||
});
|
||||
```
|
||||
|
||||
The following methods are exposed from this object:
|
||||
You can also remove this root-level object via its identifier:
|
||||
|
||||
* `select(value)`: Add `value` to the current selection.
|
||||
* `deselect(value)`: Remove `value` from the current selection.
|
||||
* `selected()`: Get array of all selected objects.
|
||||
* `clear()`: Deselect all selected objects.
|
||||
```
|
||||
openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" });
|
||||
```
|
||||
|
||||
MCT.selection is an EventEmitter; a `change` event is emitted whenever the selection changes.
|
||||
### Adding Composition Providers
|
||||
|
||||
### `MCT.systems`
|
||||
Status: Not Implemented, Needs to be ported from old system.
|
||||
The "composition" of a domain object is the list of objects it contains,
|
||||
as shown (for example) in the tree for browsing. Open MCT provides a
|
||||
default solution for composition, but there may be cases where you want
|
||||
to provide the composition of a certain object (or type of object) dynamically.
|
||||
For instance, you may want to populate a hierarchy under a custom root-level
|
||||
object based on the contents of a telemetry dictionary.
|
||||
To do this, you can add a new CompositionProvider:
|
||||
|
||||
A registry for different time system definitions. Based upon the previous time format system which utilized the "formats" extension category.
|
||||
```
|
||||
openmct.composition.addProvider({
|
||||
appliesTo: function (domainObject) {
|
||||
return domainObject.type === 'my-type';
|
||||
},
|
||||
load: function (domainObject) {
|
||||
return Promise.resolve(myDomainObjects);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### `MCT.run([container])`
|
||||
Status: Stable Draft
|
||||
### Adding Telemetry Providers
|
||||
|
||||
Run the MCT application, loading the application into the `container`, a DOM element. If a container is not specified, the application is injected into the body of the page.
|
||||
When connecting to a new telemetry source, you will want to register a new
|
||||
[telemetry provider]{@link module:openmct.TelemetryAPI~TelemetryProvider}
|
||||
with the [telemetry API]{@link module:openmct.TelemetryAPI#addProvider}:
|
||||
|
||||
### `MCT.install(plugin)`
|
||||
Status: Stable Draft
|
||||
```
|
||||
openmct.telemetry.addProvider({
|
||||
canProvideTelemetry: function (domainObject) {
|
||||
return domainObject.type === 'my-type';
|
||||
},
|
||||
properties: function (domainObject) {
|
||||
return [
|
||||
{ key: 'value', name: "Temperature", units: "degC" },
|
||||
{ key: 'time', name: "UTC" }
|
||||
];
|
||||
},
|
||||
request: function (domainObject, options) {
|
||||
var telemetryId = domainObject.myTelemetryId;
|
||||
return myAdapter.request(telemetryId, options.start, options.end);
|
||||
},
|
||||
subscribe: function (domainObject, callback) {
|
||||
var telemetryId = domainObject.myTelemetryId;
|
||||
myAdapter.subscribe(telemetryId, callback);
|
||||
return myAdapter.unsubscribe.bind(myAdapter, telemetryId, callback);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Install a plugin in MCT. Must be called before calling `run`. Plugins are functions which are invoked with the `MCT` instance as their first argument, and are expected to use the MCT public API to add functionality.
|
||||
The implementations for `request` and `subscribe` can vary depending on the
|
||||
nature of the endpoint which will provide telemetry. In the example above,
|
||||
it is assumed that `myAdapter` contains the specific implementations
|
||||
(HTTP requests, WebSocket connections, etc.) associated with some telemetry
|
||||
source.
|
||||
|
||||
For an example of writing a plugin, check out [plugin-example.html](plugin-example.html)
|
||||
## Using Open MCT
|
||||
|
||||
### `MCT.setAssetPath(path)`
|
||||
When implementing new features, it is useful and sometimes necessary to
|
||||
utilize functionality exposed by Open MCT.
|
||||
|
||||
Sets the path (absolute or relative) at which the Open MCT static files are being hosted. The default value is '.'.
|
||||
### Retrieving Composition
|
||||
|
||||
Note that this API is transitional and will be removed in a future version.
|
||||
To limit which objects are loaded at any given time, the composition of
|
||||
a domain object must be requested asynchronously:
|
||||
|
||||
```
|
||||
openmct.composition(myObject).load().then(function (childObjects) {
|
||||
childObjects.forEach(doSomething);
|
||||
});
|
||||
```
|
||||
|
||||
### Support Common Gestures
|
||||
|
||||
Custom views may also want to support common gestures using the
|
||||
[gesture API]{@link module:openmct.GestureAPI}. For instance, to make
|
||||
a view (or part of a view) selectable:
|
||||
|
||||
```
|
||||
openmct.gestures.selectable(myHtmlElement, myDomainObject);
|
||||
```
|
||||
|
||||
### Working with Domain Objects
|
||||
|
||||
The [object API]{@link module:openmct.ObjectAPI} provides useful methods
|
||||
for working with domain objects.
|
||||
|
||||
To make changes to a domain object, use the
|
||||
[`mutate`]{@link module:openmct.ObjectAPI#mutate} method:
|
||||
|
||||
```
|
||||
openmct.objects.mutate(myDomainObject, "name", "New name!");
|
||||
```
|
||||
|
||||
Making modifications in this fashion allows other usages of the domain
|
||||
object to remain up to date using the
|
||||
[`observe`]{@link module:openmct.ObjectAPI#observe} method:
|
||||
|
||||
```
|
||||
openmct.objects.observe(myDomainObject, "name", function (newName) {
|
||||
myLabel.textContent = newName;
|
||||
});
|
||||
```
|
||||
|
||||
### Using Telemetry
|
||||
|
||||
Very often in Open MCT, you wish to work with telemetry data (for instance,
|
||||
to display it in a custom visualization.)
|
||||
|
||||
|
||||
### Synchronizing with the Time Conductor
|
||||
|
||||
Views which wish to remain synchronized with the state of Open MCT's
|
||||
time conductor should utilize
|
||||
[`openmct.conductor`]{@link module:openmct.TimeConductor}:
|
||||
|
||||
```
|
||||
openmct.conductor.on('bounds', function (newBounds) {
|
||||
requestTelemetry(newBounds.start, newBounds.end).then(displayTelemetry);
|
||||
});
|
||||
```
|
||||
|
||||
## Plugins
|
||||
|
||||
While you can register new features with Open MCT directly, it is generally
|
||||
more useful to package these as a plugin. A plugin is a function that takes
|
||||
[`openmct`]{@link module:openmct} as an argument, and performs configuration
|
||||
upon `openmct` when invoked.
|
||||
|
||||
### Installing Plugins
|
||||
|
||||
To install plugins, use the [`install`]{@link module:openmct.MCT#install}
|
||||
method:
|
||||
|
||||
```
|
||||
openmct.install(myPlugin);
|
||||
```
|
||||
|
||||
The plugin will be invoked to configure Open MCT before it is started.
|
||||
|
||||
### Writing Plugins
|
||||
|
||||
Plugins configure Open MCT, and should utilize the
|
||||
[`openmct`]{@link module:openmct} module to do so, as summarized above in
|
||||
"Configuring Open MCT" and "Using Open MCT" above.
|
||||
|
||||
### Distributing Plugins
|
||||
|
||||
Hosting or downloading plugins is outside of the scope of this documentation.
|
||||
We recommend distributing plugins as UMD modules which export a single
|
||||
function.
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
@ -45,6 +45,7 @@ define(function () {
|
||||
if (!this.bundles[path]) {
|
||||
throw new Error('Tried to disable inactive bundle ' + path);
|
||||
}
|
||||
delete this.bundles[path];
|
||||
};
|
||||
|
||||
BundleRegistry.prototype.contains = function (path) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
@ -51,6 +51,7 @@ define(['./BundleRegistry'], function (BundleRegistry) {
|
||||
beforeEach(function () {
|
||||
testBundleDef = { someKey: "some value" };
|
||||
bundleRegistry.register(testPath, testBundleDef);
|
||||
bundleRegistry.enable(testPath);
|
||||
});
|
||||
|
||||
it("lists registered bundles", function () {
|
||||
|
262
src/MCT.js
262
src/MCT.js
@ -1,11 +1,34 @@
|
||||
/*****************************************************************************
|
||||
* 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',
|
||||
'legacyRegistry',
|
||||
'uuid',
|
||||
'./api/api',
|
||||
'text!./adapter/templates/edit-object-replacement.html',
|
||||
'./Selection',
|
||||
'./api/objects/object-utils'
|
||||
'./selection/Selection',
|
||||
'./api/objects/object-utils',
|
||||
'./ui/ViewRegistry'
|
||||
], function (
|
||||
EventEmitter,
|
||||
legacyRegistry,
|
||||
@ -13,14 +36,31 @@ define([
|
||||
api,
|
||||
editObjectTemplate,
|
||||
Selection,
|
||||
objectUtils
|
||||
objectUtils,
|
||||
ViewRegistry
|
||||
) {
|
||||
/**
|
||||
* Open MCT is an extensible web application for building mission
|
||||
* control user interfaces. This module is itself an instance of
|
||||
* [MCT]{@link module:openmct.MCT}, which provides an interface for
|
||||
* configuring and executing the application.
|
||||
*
|
||||
* @exports openmct
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Open MCT application. This may be configured by installing plugins
|
||||
* or registering extensions before the application is started.
|
||||
* @class MCT
|
||||
* @memberof module:openmct
|
||||
* @augments {EventEmitter}
|
||||
*/
|
||||
function MCT() {
|
||||
EventEmitter.call(this);
|
||||
this.legacyBundle = { extensions: {
|
||||
services: [
|
||||
{
|
||||
key: "mct",
|
||||
key: "openmct",
|
||||
implementation: function () {
|
||||
return this;
|
||||
}.bind(this)
|
||||
@ -28,7 +68,131 @@ define([
|
||||
]
|
||||
} };
|
||||
|
||||
/**
|
||||
* Tracks current selection state of the application.
|
||||
* @private
|
||||
*/
|
||||
this.selection = new Selection();
|
||||
|
||||
/**
|
||||
* MCT's time conductor, which may be used to synchronize view contents
|
||||
* for telemetry- or time-based views.
|
||||
* @type {module:openmct.TimeConductor}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name conductor
|
||||
*/
|
||||
this.conductor = new api.TimeConductor();
|
||||
|
||||
/**
|
||||
* An interface for interacting with the composition of domain objects.
|
||||
* The composition of a domain object is the list of other domain
|
||||
* objects it "contains" (for instance, that should be displayed
|
||||
* beneath it in the tree.)
|
||||
*
|
||||
* `composition` may be called as a function, in which case it acts
|
||||
* as [`composition.get`]{@link module:openmct.CompositionAPI#get}.
|
||||
*
|
||||
* @type {module:openmct.CompositionAPI}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name composition
|
||||
*/
|
||||
this.composition = new api.CompositionAPI();
|
||||
|
||||
/**
|
||||
* Registry for views of domain objects which should appear in the
|
||||
* main viewing area.
|
||||
*
|
||||
* @type {module:openmct.ViewRegistry}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name mainViews
|
||||
*/
|
||||
this.mainViews = new ViewRegistry();
|
||||
|
||||
/**
|
||||
* Registry for views which should appear in the Inspector area.
|
||||
* These views will be chosen based on selection state, so
|
||||
* providers should be prepared to test arbitrary objects for
|
||||
* viewability.
|
||||
*
|
||||
* @type {module:openmct.ViewRegistry}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name inspectors
|
||||
*/
|
||||
this.inspectors = new ViewRegistry();
|
||||
|
||||
/**
|
||||
* Registry for views which should appear in Edit Properties
|
||||
* dialogs, and similar user interface elements used for
|
||||
* modifying domain objects external to its regular views.
|
||||
*
|
||||
* @type {module:openmct.ViewRegistry}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name propertyEditors
|
||||
*/
|
||||
this.propertyEditors = new ViewRegistry();
|
||||
|
||||
/**
|
||||
* Registry for views which should appear in the status indicator area.
|
||||
* @type {module:openmct.ViewRegistry}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name indicators
|
||||
*/
|
||||
this.indicators = new ViewRegistry();
|
||||
|
||||
/**
|
||||
* Registry for views which should appear in the toolbar area while
|
||||
* editing.
|
||||
*
|
||||
* These views will be chosen based on selection state, so
|
||||
* providers should be prepared to test arbitrary objects for
|
||||
* viewability.
|
||||
*
|
||||
* @type {module:openmct.ViewRegistry}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name toolbars
|
||||
*/
|
||||
this.toolbars = new ViewRegistry();
|
||||
|
||||
/**
|
||||
* Registry for domain object types which may exist within this
|
||||
* instance of Open MCT.
|
||||
*
|
||||
* @type {module:openmct.TypeRegistry}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name types
|
||||
*/
|
||||
this.types = new api.TypeRegistry();
|
||||
|
||||
/**
|
||||
* Utilities for attaching common behaviors to views.
|
||||
*
|
||||
* @type {module:openmct.GestureAPI}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name gestures
|
||||
*/
|
||||
this.gestures = new api.GestureAPI();
|
||||
|
||||
/**
|
||||
* An interface for interacting with domain objects and the domain
|
||||
* object hierarchy.
|
||||
*
|
||||
* @type {module:openmct.ObjectAPI}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name objects
|
||||
*/
|
||||
this.objects = new api.ObjectAPI();
|
||||
|
||||
/**
|
||||
* An interface for retrieving and interpreting telemetry data associated
|
||||
* with a domain object.
|
||||
*
|
||||
* @type {module:openmct.TelemetryAPI}
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name telemetry
|
||||
*/
|
||||
this.telemetry = new api.TelemetryAPI();
|
||||
|
||||
this.TimeConductor = this.conductor; // compatibility for prototype
|
||||
this.on('navigation', this.selection.clear.bind(this.selection));
|
||||
}
|
||||
|
||||
@ -47,6 +211,8 @@ define([
|
||||
|
||||
/**
|
||||
* Set path to where assets are hosted. This should be the path to main.js.
|
||||
* @memberof module:openmct.MCT#
|
||||
* @method setAssetPath
|
||||
*/
|
||||
MCT.prototype.setAssetPath = function (path) {
|
||||
this.legacyExtension('constants', {
|
||||
@ -56,68 +222,24 @@ define([
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new type of view.
|
||||
*
|
||||
* @param region the region identifier (see mct.regions)
|
||||
* @param {ViewDefinition} definition the definition for this view
|
||||
* Start running Open MCT. This should be called only after any plugins
|
||||
* have been installed.
|
||||
* @fires module:openmct.MCT~start
|
||||
* @memberof module:openmct.MCT#
|
||||
* @method start
|
||||
* @param {HTMLElement} [domElement] the DOM element in which to run
|
||||
* MCT; if undefined, MCT will be run in the body of the document
|
||||
*/
|
||||
MCT.prototype.view = function (region, definition) {
|
||||
var viewKey = region + uuid();
|
||||
var adaptedViewKey = "adapted-view-" + region;
|
||||
|
||||
this.legacyExtension(
|
||||
region === this.regions.main ? 'views' : 'representations',
|
||||
{
|
||||
name: "A view",
|
||||
key: adaptedViewKey,
|
||||
editable: true,
|
||||
template: '<mct-view region="\'' +
|
||||
region +
|
||||
'\'" ' +
|
||||
'key="\'' +
|
||||
viewKey +
|
||||
'\'" ' +
|
||||
'mct-object="domainObject">' +
|
||||
'</mct-view>'
|
||||
MCT.prototype.start = function (domElement) {
|
||||
if (!domElement) {
|
||||
domElement = document.body;
|
||||
}
|
||||
);
|
||||
|
||||
this.legacyExtension('policies', {
|
||||
category: "view",
|
||||
implementation: function Policy() {
|
||||
this.allow = function (view, domainObject) {
|
||||
if (view.key === adaptedViewKey) {
|
||||
var model = domainObject.getModel();
|
||||
var newDO = objectUtils.toNewFormat(model);
|
||||
return definition.canView(newDO);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
});
|
||||
var appDiv = document.createElement('div');
|
||||
appDiv.setAttribute('ng-view', '');
|
||||
appDiv.className = 'user-environ';
|
||||
domElement.appendChild(appDiv);
|
||||
|
||||
this.legacyExtension('newViews', {
|
||||
factory: definition,
|
||||
region: region,
|
||||
key: viewKey
|
||||
});
|
||||
};
|
||||
|
||||
MCT.prototype.type = function (key, type) {
|
||||
var legacyDef = type.toLegacyDefinition();
|
||||
legacyDef.key = key;
|
||||
type.key = key;
|
||||
|
||||
this.legacyExtension('types', legacyDef);
|
||||
this.legacyExtension('representations', {
|
||||
key: "edit-object",
|
||||
priority: "preferred",
|
||||
template: editObjectTemplate,
|
||||
type: key
|
||||
});
|
||||
};
|
||||
|
||||
MCT.prototype.start = function () {
|
||||
this.legacyExtension('runs', {
|
||||
depends: ['navigationService'],
|
||||
implementation: function (navigationService) {
|
||||
@ -128,24 +250,26 @@ define([
|
||||
|
||||
legacyRegistry.register('adapter', this.legacyBundle);
|
||||
legacyRegistry.enable('adapter');
|
||||
/**
|
||||
* Fired by [MCT]{@link module:openmct.MCT} when the application
|
||||
* is started.
|
||||
* @event start
|
||||
* @memberof module:openmct.MCT~
|
||||
*/
|
||||
this.emit('start');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Install a plugin in MCT.
|
||||
*
|
||||
* @param `Function` plugin -- a plugin install function which will be
|
||||
* @param {Function} plugin a plugin install function which will be
|
||||
* invoked with the mct instance.
|
||||
* @memberof module:openmct.MCT#
|
||||
*/
|
||||
MCT.prototype.install = function (plugin) {
|
||||
plugin(this);
|
||||
};
|
||||
|
||||
MCT.prototype.regions = {
|
||||
main: "MAIN",
|
||||
properties: "PROPERTIES",
|
||||
toolbar: "TOOLBAR"
|
||||
};
|
||||
|
||||
return MCT;
|
||||
});
|
||||
|
@ -1,32 +0,0 @@
|
||||
define(['EventEmitter'], function (EventEmitter) {
|
||||
function Selection() {
|
||||
EventEmitter.call(this);
|
||||
this.selectedValues = [];
|
||||
}
|
||||
|
||||
Selection.prototype = Object.create(EventEmitter.prototype);
|
||||
|
||||
Selection.prototype.select = function (value) {
|
||||
this.selectedValues.push(value);
|
||||
this.emit('change', this.selectedValues);
|
||||
return this.deselect.bind(this, value);
|
||||
};
|
||||
|
||||
Selection.prototype.deselect = function (value) {
|
||||
this.selectedValues = this.selectedValues.filter(function (v) {
|
||||
return v !== value;
|
||||
});
|
||||
this.emit('change', this.selectedValues);
|
||||
};
|
||||
|
||||
Selection.prototype.selected = function () {
|
||||
return this.selectedValues;
|
||||
};
|
||||
|
||||
Selection.prototype.clear = function () {
|
||||
this.selectedValues = [];
|
||||
this.emit('change', this.selectedValues);
|
||||
};
|
||||
|
||||
return Selection;
|
||||
});
|
@ -1,19 +1,35 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'../../api/objects/object-utils'
|
||||
], function (objectUtils) {
|
||||
function ActionDialogDecorator(mct, newViews, actionService) {
|
||||
this.actionService = actionService;
|
||||
function ActionDialogDecorator(mct, actionService) {
|
||||
this.mct = mct;
|
||||
this.definitions = newViews.filter(function (newView) {
|
||||
return newView.region === mct.regions.properties;
|
||||
}).map(function (newView) {
|
||||
return newView.factory;
|
||||
});
|
||||
this.actionService = actionService;
|
||||
}
|
||||
|
||||
ActionDialogDecorator.prototype.getActions = function (context) {
|
||||
var mct = this.mct;
|
||||
var definitions = this.definitions;
|
||||
|
||||
return this.actionService.getActions(context).map(function (action) {
|
||||
if (action.dialogService) {
|
||||
@ -21,16 +37,13 @@ define([
|
||||
context.domainObject.getModel(),
|
||||
objectUtils.parseKeyString(context.domainObject.getId())
|
||||
);
|
||||
var providers = mct.propertyEditors.get(domainObject);
|
||||
|
||||
definitions = definitions.filter(function (definition) {
|
||||
return definition.canView(domainObject);
|
||||
});
|
||||
|
||||
if (definitions.length > 0) {
|
||||
if (providers.length > 0) {
|
||||
action.dialogService = Object.create(action.dialogService);
|
||||
action.dialogService.getUserInput = function (form, value) {
|
||||
return new mct.Dialog(
|
||||
definitions[0].view(context.domainObject),
|
||||
providers[0].view(context.domainObject),
|
||||
form.title
|
||||
).show();
|
||||
};
|
||||
|
@ -1,17 +1,41 @@
|
||||
/*****************************************************************************
|
||||
* 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',
|
||||
'./actions/ActionDialogDecorator',
|
||||
'./directives/MCTView',
|
||||
'./services/Instantiate',
|
||||
'./capabilities/APICapabilityDecorator',
|
||||
'./policies/AdapterCompositionPolicy'
|
||||
'./policies/AdapterCompositionPolicy',
|
||||
'./runs/AlternateCompositionInitializer'
|
||||
], function (
|
||||
legacyRegistry,
|
||||
ActionDialogDecorator,
|
||||
MCTView,
|
||||
Instantiate,
|
||||
APICapabilityDecorator,
|
||||
AdapterCompositionPolicy
|
||||
AdapterCompositionPolicy,
|
||||
AlternateCompositionInitializer
|
||||
) {
|
||||
legacyRegistry.register('src/adapter', {
|
||||
"extensions": {
|
||||
@ -21,7 +45,7 @@ define([
|
||||
implementation: MCTView,
|
||||
depends: [
|
||||
"newViews[]",
|
||||
"mct"
|
||||
"openmct"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -50,14 +74,52 @@ define([
|
||||
type: "decorator",
|
||||
provides: "actionService",
|
||||
implementation: ActionDialogDecorator,
|
||||
depends: [ "mct", "newViews[]" ]
|
||||
depends: ["openmct"]
|
||||
}
|
||||
],
|
||||
policies: [
|
||||
{
|
||||
category: "composition",
|
||||
implementation: AdapterCompositionPolicy,
|
||||
depends: [ "mct" ]
|
||||
depends: ["openmct"]
|
||||
}
|
||||
],
|
||||
runs: [
|
||||
{
|
||||
implementation: AlternateCompositionInitializer,
|
||||
depends: ["openmct"]
|
||||
}
|
||||
],
|
||||
licenses: [
|
||||
{
|
||||
"name": "almond",
|
||||
"version": "0.3.3",
|
||||
"description": "Lightweight RequireJS replacement for builds",
|
||||
"author": "jQuery Foundation",
|
||||
"website": "https://github.com/requirejs/almond",
|
||||
"copyright": "Copyright jQuery Foundation and other contributors, https://jquery.org/",
|
||||
"license": "license-mit",
|
||||
"link": "https://github.com/requirejs/almond/blob/master/LICENSE"
|
||||
},
|
||||
{
|
||||
"name": "lodash",
|
||||
"version": "3.10.1",
|
||||
"description": "Utility functions",
|
||||
"author": "Dojo Foundation",
|
||||
"website": "https://lodash.com",
|
||||
"copyright": "Copyright 2012-2015 The Dojo Foundation",
|
||||
"license": "license-mit",
|
||||
"link": "https://raw.githubusercontent.com/lodash/lodash/3.10.1/LICENSE"
|
||||
},
|
||||
{
|
||||
"name": "EventEmitter3",
|
||||
"version": "1.2.0",
|
||||
"description": "Event-driven programming support",
|
||||
"author": "Arnout Kazemier",
|
||||
"website": "https://github.com/primus/eventemitter3",
|
||||
"copyright": "Copyright (c) 2014 Arnout Kazemier",
|
||||
"license": "license-mit",
|
||||
"link": "https://github.com/primus/eventemitter3/blob/1.2.0/LICENSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'./synchronizeMutationCapability',
|
||||
'./AlternateCompositionCapability'
|
||||
@ -25,7 +47,7 @@ define([
|
||||
}
|
||||
if (AlternateCompositionCapability.appliesTo(model)) {
|
||||
capabilities.composition = function (domainObject) {
|
||||
return new AlternateCompositionCapability(this.$injector, domainObject)
|
||||
return new AlternateCompositionCapability(this.$injector, domainObject);
|
||||
}.bind(this);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -24,17 +24,15 @@
|
||||
* Module defining AlternateCompositionCapability. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
define([
|
||||
'../../api/objects/object-utils',
|
||||
'../../api/composition/CompositionAPI'
|
||||
], function (objectUtils, CompositionAPI) {
|
||||
|
||||
'../../api/objects/object-utils'
|
||||
], function (objectUtils) {
|
||||
function AlternateCompositionCapability($injector, domainObject) {
|
||||
this.domainObject = domainObject;
|
||||
|
||||
this.getDependencies = function () {
|
||||
this.instantiate = $injector.get("instantiate");
|
||||
this.contextualize = $injector.get("contextualize");
|
||||
this.getDependencies = undefined;
|
||||
this.openmct = $injector.get("openmct");
|
||||
}.bind(this);
|
||||
}
|
||||
|
||||
@ -50,7 +48,7 @@ define([
|
||||
function addChildToComposition(model) {
|
||||
var existingIndex = model.composition.indexOf(child.getId());
|
||||
if (existingIndex === -1) {
|
||||
model.composition.push(child.getId())
|
||||
model.composition.push(child.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +83,12 @@ define([
|
||||
this.domainObject.getModel(),
|
||||
this.domainObject.getId()
|
||||
);
|
||||
var collection = CompositionAPI(newFormatDO);
|
||||
|
||||
if (this.getDependencies) {
|
||||
this.getDependencies();
|
||||
}
|
||||
|
||||
var collection = this.openmct.composition.get(newFormatDO);
|
||||
return collection.load()
|
||||
.then(function (children) {
|
||||
collection.destroy();
|
||||
@ -94,7 +97,9 @@ define([
|
||||
};
|
||||
|
||||
AlternateCompositionCapability.appliesTo = function (model) {
|
||||
return !!CompositionAPI(objectUtils.toNewFormat(model, model.id));
|
||||
// Will get replaced by a runs exception to properly
|
||||
// bind to running openmct instance
|
||||
return false;
|
||||
};
|
||||
|
||||
return AlternateCompositionCapability;
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
|
||||
], function (
|
||||
@ -20,8 +42,8 @@ define([
|
||||
});
|
||||
};
|
||||
return capability;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return synchronizeMutationCapability;
|
||||
});
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'angular',
|
||||
'./Region',
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([], function () {
|
||||
function Region(element) {
|
||||
this.activeView = undefined;
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([], function () {
|
||||
function AdapterCompositionPolicy(mct) {
|
||||
this.mct = mct;
|
||||
|
36
src/adapter/runs/AlternateCompositionInitializer.js
Normal file
36
src/adapter/runs/AlternateCompositionInitializer.js
Normal file
@ -0,0 +1,36 @@
|
||||
/*****************************************************************************
|
||||
* 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 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.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'../capabilities/AlternateCompositionCapability'
|
||||
], function (AlternateCompositionCapability) {
|
||||
// Present to work around the need for openmct to be used
|
||||
// from AlternateCompositionCapability.appliesTo, even though it
|
||||
// cannot be injected.
|
||||
function AlternateCompositionInitializer(openmct) {
|
||||
AlternateCompositionCapability.appliesTo = function (model) {
|
||||
return !model.composition && !!openmct.composition.get(model);
|
||||
};
|
||||
}
|
||||
|
||||
return AlternateCompositionInitializer;
|
||||
});
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
@ -32,7 +32,8 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* The TimeConductor extends the EventEmitter class. A number of events are
|
||||
* fired when properties of the time conductor change, which are
|
||||
* documented below.
|
||||
* @constructor
|
||||
* @interface
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function TimeConductor() {
|
||||
EventEmitter.call(this);
|
||||
@ -58,6 +59,8 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* bounds, for example by views validating user inputs.
|
||||
* @param bounds The start and end time of the conductor.
|
||||
* @returns {string | true} A validation error, or true if valid
|
||||
* @memberof module:openmct.TimeConductor#
|
||||
* @method validateBounds
|
||||
*/
|
||||
TimeConductor.prototype.validateBounds = function (bounds) {
|
||||
if ((bounds.start === undefined) ||
|
||||
@ -83,16 +86,19 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* time conductor ticks, regularly updating the bounds from a timing
|
||||
* source appropriate to the selected time system and mode of the time
|
||||
* conductor.
|
||||
* @fires TimeConductor#follow
|
||||
* @fires module:openmct.TimeConductor~follow
|
||||
* @param {boolean} followMode
|
||||
* @returns {boolean}
|
||||
* @memberof module:openmct.TimeConductor#
|
||||
* @method follow
|
||||
*/
|
||||
TimeConductor.prototype.follow = function (followMode) {
|
||||
if (arguments.length > 0) {
|
||||
this.followMode = followMode;
|
||||
/**
|
||||
* @event TimeConductor#follow The TimeConductor has toggled
|
||||
* into or out of follow mode.
|
||||
* The TimeConductor has toggled into or out of follow mode.
|
||||
* @event follow
|
||||
* @memberof module:openmct.TimeConductor~
|
||||
* @property {boolean} followMode true if follow mode is
|
||||
* enabled, otherwise false.
|
||||
*/
|
||||
@ -105,23 +111,28 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* @typedef {Object} TimeConductorBounds
|
||||
* @property {number} start The start time displayed by the time conductor in ms since epoch. Epoch determined by current time system
|
||||
* @property {number} end The end time displayed by the time conductor in ms since epoch.
|
||||
* @memberof module:openmct.TimeConductor~
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get or set the start and end time of the time conductor. Basic validation
|
||||
* of bounds is performed.
|
||||
*
|
||||
* @param {TimeConductorBounds} newBounds
|
||||
* @param {module:openmct.TimeConductorBounds~TimeConductorBounds} newBounds
|
||||
* @throws {Error} Validation error
|
||||
* @fires TimeConductor#bounds
|
||||
* @returns {TimeConductorBounds}
|
||||
* @fires module:openmct.TimeConductor~bounds
|
||||
* @returns {module:openmct.TimeConductorBounds~TimeConductorBounds}
|
||||
* @memberof module:openmct.TimeConductor#
|
||||
* @method bounds
|
||||
*/
|
||||
TimeConductor.prototype.bounds = function (newBounds) {
|
||||
if (arguments.length > 0) {
|
||||
throwOnError(this.validateBounds(newBounds));
|
||||
this.boundsVal = newBounds;
|
||||
/**
|
||||
* @event TimeConductor#bounds The start time, end time, or
|
||||
* both have been updated
|
||||
* The start time, end time, or both have been updated.
|
||||
* @event bounds
|
||||
* @memberof module:openmct.TimeConductor~
|
||||
* @property {TimeConductorBounds} bounds
|
||||
*/
|
||||
this.emit('bounds', this.boundsVal);
|
||||
@ -134,17 +145,21 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* units, epoch, and other aspects of time representation. When changing
|
||||
* the time system in use, new valid bounds must also be provided.
|
||||
* @param {TimeSystem} newTimeSystem
|
||||
* @param {TimeConductorBounds} bounds
|
||||
* @fires TimeConductor#timeSystem
|
||||
* @param {module:openmct.TimeConductor~TimeConductorBounds} bounds
|
||||
* @fires module:openmct.TimeConductor~timeSystem
|
||||
* @returns {TimeSystem} The currently applied time system
|
||||
* @memberof module:openmct.TimeConductor#
|
||||
* @method timeSystem
|
||||
*/
|
||||
TimeConductor.prototype.timeSystem = function (newTimeSystem, bounds) {
|
||||
if (arguments.length >= 2) {
|
||||
this.system = newTimeSystem;
|
||||
/**
|
||||
* @event TimeConductor#timeSystem The time system used by the time
|
||||
* The time system used by the time
|
||||
* conductor has changed. A change in Time System will always be
|
||||
* followed by a bounds event specifying new query bounds
|
||||
* followed by a bounds event specifying new query bounds.
|
||||
*
|
||||
* @event module:openmct.TimeConductor~timeSystem
|
||||
* @property {TimeSystem} The value of the currently applied
|
||||
* Time System
|
||||
* */
|
||||
@ -163,15 +178,19 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* Get or set the Time of Interest. The Time of Interest is the temporal
|
||||
* focus of the current view. It can be manipulated by the user from the
|
||||
* time conductor or from other views.
|
||||
* @fires TimeConductor#timeOfInterest
|
||||
* @fires module:openmct.TimeConductor~timeOfInterest
|
||||
* @param newTOI
|
||||
* @returns {number} the current time of interest
|
||||
* @memberof module:openmct.TimeConductor#
|
||||
* @method timeOfInterest
|
||||
*/
|
||||
TimeConductor.prototype.timeOfInterest = function (newTOI) {
|
||||
if (arguments.length > 0) {
|
||||
this.toi = newTOI;
|
||||
/**
|
||||
* @event TimeConductor#timeOfInterest The Time of Interest has moved.
|
||||
* The Time of Interest has moved.
|
||||
* @event timeOfInterest
|
||||
* @memberof module:openmct.TimeConductor~
|
||||
* @property {number} Current time of interest
|
||||
*/
|
||||
this.emit('timeOfInterest', this.toi);
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
|
@ -1,6 +1,29 @@
|
||||
/*****************************************************************************
|
||||
* 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(function () {
|
||||
/**
|
||||
* @typedef TypeDefinition
|
||||
* @memberof module:openmct.Type~
|
||||
* @property {Metadata} metadata displayable metadata about this type
|
||||
* @property {function (object)} [initialize] a function which initializes
|
||||
* the model for new domain objects of this type
|
||||
@ -9,9 +32,12 @@ define(function () {
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Type describes a kind of domain object that may appear or be
|
||||
* created within Open MCT.
|
||||
*
|
||||
* @param {TypeDefinition} definition
|
||||
* @constructor
|
||||
* @param {module:opemct.Type~TypeDefinition} definition
|
||||
* @class Type
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function Type(definition) {
|
||||
this.definition = definition;
|
||||
@ -21,34 +47,13 @@ define(function () {
|
||||
* Check if a domain object is an instance of this type.
|
||||
* @param domainObject
|
||||
* @returns {boolean} true if the domain object is of this type
|
||||
* @memberof module:openmct.Type#
|
||||
* @method check
|
||||
*/
|
||||
Type.prototype.check = function (domainObject) {
|
||||
// Depends on assignment from MCT.
|
||||
return domainObject.type === this.key;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a definition for this type that can be registered using the
|
||||
* legacy bundle format.
|
||||
* @private
|
||||
*/
|
||||
Type.prototype.toLegacyDefinition = function () {
|
||||
var def = {};
|
||||
def.name = this.definition.metadata.label;
|
||||
def.glyph = this.definition.metadata.glyph;
|
||||
def.description = this.definition.metadata.description;
|
||||
def.properties = this.definition.form;
|
||||
|
||||
if (this.definition.initialize) {
|
||||
def.model = {};
|
||||
this.definition.initialize(def.model);
|
||||
}
|
||||
|
||||
if (this.definition.creatable) {
|
||||
def.features = ['creation'];
|
||||
}
|
||||
return def;
|
||||
};
|
||||
|
||||
return Type;
|
||||
});
|
||||
|
@ -1,38 +0,0 @@
|
||||
define([], function () {
|
||||
|
||||
/**
|
||||
* A View is used to provide displayable content, and to react to
|
||||
* associated life cycle events.
|
||||
*
|
||||
* @interface
|
||||
*/
|
||||
function View() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the supplied DOM element with the contents of this view.
|
||||
*
|
||||
* View implementations should use this method to attach any
|
||||
* listeners or acquire other resources that are necessary to keep
|
||||
* the contents of this view up-to-date.
|
||||
*
|
||||
* @param {HTMLElement} container the DOM element to populate
|
||||
*/
|
||||
View.prototype.show = function (container) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Release any resources associated with this view.
|
||||
*
|
||||
* View implementations should use this method to detach any
|
||||
* listeners or release other resources that are no longer necessary
|
||||
* once a view is no longer used.
|
||||
*/
|
||||
View.prototype.destroy = function () {
|
||||
|
||||
};
|
||||
|
||||
return View;
|
||||
});
|
@ -1,44 +0,0 @@
|
||||
define(function () {
|
||||
|
||||
/**
|
||||
* Defines a kind of view.
|
||||
* @interface
|
||||
*/
|
||||
function ViewDefinition() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata about this view, as may be used in the user interface
|
||||
* to present options for this view.
|
||||
* @param {*} object the object to be shown in this view
|
||||
* @returns {mct.ViewMetadata} metadata about this view
|
||||
*/
|
||||
ViewDefinition.prototype.metadata = function (object) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate a new view of this object. Callers of this method are
|
||||
* responsible for calling `canView` before instantiating views in this
|
||||
* manner.
|
||||
*
|
||||
* @param {*} object the object to be shown in this view
|
||||
* @returns {mct.View} a view of this object
|
||||
*/
|
||||
ViewDefinition.prototype.view = function (object) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this view is capable of showing this object. Users of
|
||||
* views should use this method before calling `show`.
|
||||
*
|
||||
* Subclasses should override this method to control the applicability
|
||||
* of this view to other objects.
|
||||
*
|
||||
* @param {*} object the object to be shown in this view
|
||||
* @returns {boolean} true if this view is applicable to this object
|
||||
*/
|
||||
ViewDefinition.prototype.canView = function (object) {
|
||||
};
|
||||
|
||||
return ViewDefinition;
|
||||
});
|
@ -1,24 +1,52 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'./Type',
|
||||
'./TimeConductor',
|
||||
'./View',
|
||||
'./objects/ObjectAPI',
|
||||
'./composition/CompositionAPI',
|
||||
'./ui/Dialog'
|
||||
'./types/TypeRegistry',
|
||||
'./ui/Dialog',
|
||||
'./ui/GestureAPI',
|
||||
'./telemetry/TelemetryAPI'
|
||||
], function (
|
||||
Type,
|
||||
TimeConductor,
|
||||
View,
|
||||
ObjectAPI,
|
||||
CompositionAPI,
|
||||
Dialog
|
||||
TypeRegistry,
|
||||
Dialog,
|
||||
GestureAPI,
|
||||
TelemetryAPI
|
||||
) {
|
||||
return {
|
||||
Type: Type,
|
||||
TimeConductor: new TimeConductor(),
|
||||
View: View,
|
||||
Objects: ObjectAPI,
|
||||
Composition: CompositionAPI,
|
||||
Dialog: Dialog
|
||||
TimeConductor: TimeConductor,
|
||||
ObjectAPI: ObjectAPI,
|
||||
CompositionAPI: CompositionAPI,
|
||||
Dialog: Dialog,
|
||||
TypeRegistry: TypeRegistry,
|
||||
GestureAPI: GestureAPI,
|
||||
TelemetryAPI: TelemetryAPI
|
||||
};
|
||||
});
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'lodash',
|
||||
'EventEmitter',
|
||||
@ -9,31 +31,106 @@ define([
|
||||
DefaultCompositionProvider,
|
||||
CompositionCollection
|
||||
) {
|
||||
/**
|
||||
* An interface for interacting with the composition of domain objects.
|
||||
* The composition of a domain object is the list of other domain objects
|
||||
* it "contains" (for instance, that should be displayed beneath it
|
||||
* in the tree.)
|
||||
*
|
||||
* @interface CompositionAPI
|
||||
* @returns {module:openmct.CompositionCollection}
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function CompositionAPI() {
|
||||
this.registry = [];
|
||||
this.policies = [];
|
||||
this.addProvider(new DefaultCompositionProvider());
|
||||
}
|
||||
|
||||
var PROVIDER_REGISTRY = [];
|
||||
|
||||
function getProvider (object) {
|
||||
return _.find(PROVIDER_REGISTRY, function (p) {
|
||||
return p.appliesTo(object);
|
||||
});
|
||||
/**
|
||||
* Add a composition provider.
|
||||
*
|
||||
* Plugins can add new composition providers to change the loading
|
||||
* behavior for certain domain objects.
|
||||
*
|
||||
* @method addProvider
|
||||
* @param {module:openmct.CompositionProvider} provider the provider to add
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
*/
|
||||
CompositionAPI.prototype.addProvider = function (provider) {
|
||||
this.registry.unshift(provider);
|
||||
};
|
||||
|
||||
function composition(object) {
|
||||
var provider = getProvider(object);
|
||||
/**
|
||||
* Retrieve the composition (if any) of this domain object.
|
||||
*
|
||||
* @method get
|
||||
* @returns {module:openmct.CompositionCollection}
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
*/
|
||||
CompositionAPI.prototype.get = function (domainObject) {
|
||||
var provider = _.find(this.registry, function (p) {
|
||||
return p.appliesTo(domainObject);
|
||||
});
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new CompositionCollection(object, provider);
|
||||
return new CompositionCollection(domainObject, provider);
|
||||
};
|
||||
|
||||
composition.addProvider = function (provider) {
|
||||
PROVIDER_REGISTRY.unshift(provider);
|
||||
/**
|
||||
* A composition policy is a function which either allows or disallows
|
||||
* placing one object in another's composition.
|
||||
*
|
||||
* Open MCT's policy model requires consensus, so any one policy may
|
||||
* reject composition by returning false. As such, policies should
|
||||
* generally be written to return true in the default case.
|
||||
*
|
||||
* @callback CompositionPolicy
|
||||
* @memberof module:openmct.CompositionAPI~
|
||||
* @param {module:openmct.DomainObject} containingObject the object which
|
||||
* would act as a container
|
||||
* @param {module:openmct.DomainObject} containedObject the object which
|
||||
* would be contained
|
||||
* @returns {boolean} false if this composition should be disallowed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add a composition policy. Composition policies may disallow domain
|
||||
* objects from containing other domain objects.
|
||||
*
|
||||
* @method addPolicy
|
||||
* @param {module:openmct.CompositionAPI~CompositionPolicy} policy
|
||||
* the policy to add
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
*/
|
||||
CompositionAPI.prototype.addPolicy = function (policy) {
|
||||
this.policies.push(policy);
|
||||
};
|
||||
|
||||
composition.addProvider(new DefaultCompositionProvider());
|
||||
|
||||
return composition;
|
||||
/**
|
||||
* Check whether or not a domain object is allowed to contain another
|
||||
* domain object.
|
||||
*
|
||||
* @private
|
||||
* @method checkPolicy
|
||||
* @param {module:openmct.DomainObject} containingObject the object which
|
||||
* would act as a container
|
||||
* @param {module:openmct.DomainObject} containedObject the object which
|
||||
* would be contained
|
||||
* @returns {boolean} false if this composition should be disallowed
|
||||
|
||||
* @param {module:openmct.CompositionAPI~CompositionPolicy} policy
|
||||
* the policy to add
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
*/
|
||||
CompositionAPI.prototype.checkPolicy = function (container, containee) {
|
||||
return this.policies.every(function (policy) {
|
||||
return policy(container, containee);
|
||||
});
|
||||
};
|
||||
|
||||
return CompositionAPI;
|
||||
});
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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',
|
||||
'lodash',
|
||||
@ -8,10 +30,27 @@ define([
|
||||
objectUtils
|
||||
) {
|
||||
|
||||
function CompositionCollection(domainObject, provider) {
|
||||
|
||||
/**
|
||||
* A CompositionCollection represents the list of domain objects contained
|
||||
* by another domain object. It provides methods for loading this
|
||||
* list asynchronously, and for modifying this list.
|
||||
*
|
||||
* @interface CompositionCollection
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* whose composition will be contained
|
||||
* @param {module:openmct.CompositionProvider} provider the provider
|
||||
* to use to retrieve other domain objects
|
||||
* @param {module:openmct.CompositionAPI} api the composition API, for
|
||||
* policy checks
|
||||
* @memberof module:openmct
|
||||
* @augments EventEmitter
|
||||
*/
|
||||
function CompositionCollection(domainObject, provider, api) {
|
||||
EventEmitter.call(this);
|
||||
this.domainObject = domainObject;
|
||||
this.provider = provider;
|
||||
this.api = api;
|
||||
if (this.provider.on) {
|
||||
this.provider.on(
|
||||
this.domainObject,
|
||||
@ -26,7 +65,7 @@ define([
|
||||
this
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CompositionCollection.prototype = Object.create(EventEmitter.prototype);
|
||||
|
||||
@ -38,18 +77,66 @@ define([
|
||||
this.remove(child, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the index of a domain object within this composition. If the
|
||||
* domain object is not contained here, -1 will be returned.
|
||||
*
|
||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||
* must have resolved before using this method.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object for which
|
||||
* an index should be retrieved
|
||||
* @returns {number} the index of that domain object
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name indexOf
|
||||
*/
|
||||
CompositionCollection.prototype.indexOf = function (child) {
|
||||
return _.findIndex(this._children, function (other) {
|
||||
return _.findIndex(this.loadedChildren, function (other) {
|
||||
return objectUtils.equals(child, other);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the index of a domain object within this composition.
|
||||
*
|
||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||
* must have resolved before using this method.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object for which
|
||||
* containment should be checked
|
||||
* @returns {boolean} true if the domain object is contained here
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name contains
|
||||
*/
|
||||
CompositionCollection.prototype.contains = function (child) {
|
||||
return this.indexOf(child) !== -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a domain object can be added to this composition.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object to add
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name canContain
|
||||
*/
|
||||
CompositionCollection.prototype.canContain = function (domainObject) {
|
||||
return this.api.checkPolicy(this.domainObject, domainObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a domain object to this composition.
|
||||
*
|
||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||
* must have resolved before using this method.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object to add
|
||||
* @param {boolean} skipMutate true if the underlying provider should
|
||||
* not be updated
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name add
|
||||
*/
|
||||
CompositionCollection.prototype.add = function (child, skipMutate) {
|
||||
if (!this._children) {
|
||||
if (!this.loadedChildren) {
|
||||
throw new Error("Must load composition before you can add!");
|
||||
}
|
||||
if (!this.canContain(child)) {
|
||||
@ -61,7 +148,7 @@ define([
|
||||
}
|
||||
throw new Error("Unable to add child: already in composition");
|
||||
}
|
||||
this._children.push(child);
|
||||
this.loadedChildren.push(child);
|
||||
this.emit('add', child);
|
||||
if (!skipMutate) {
|
||||
// add after we have added.
|
||||
@ -69,18 +156,38 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the domain objects in this composition.
|
||||
*
|
||||
* @returns {Promise.<Array.<module:openmct.DomainObject>>} a promise for
|
||||
* the domain objects in this composition
|
||||
* @memberof {module:openmct.CompositionCollection#}
|
||||
* @name load
|
||||
*/
|
||||
CompositionCollection.prototype.load = function () {
|
||||
return this.provider.load(this.domainObject)
|
||||
.then(function (children) {
|
||||
this._children = [];
|
||||
this.loadedChildren = [];
|
||||
children.map(function (c) {
|
||||
this.add(c, true);
|
||||
}, this);
|
||||
this.emit('load');
|
||||
return this._children.slice();
|
||||
return this.loadedChildren.slice();
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a domain object from this composition.
|
||||
*
|
||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||
* must have resolved before using this method.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object to remove
|
||||
* @param {boolean} skipMutate true if the underlying provider should
|
||||
* not be updated
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name remove
|
||||
*/
|
||||
CompositionCollection.prototype.remove = function (child, skipMutate) {
|
||||
if (!this.contains(child)) {
|
||||
if (skipMutate) {
|
||||
@ -89,7 +196,7 @@ define([
|
||||
throw new Error("Unable to remove child: not found in composition");
|
||||
}
|
||||
var index = this.indexOf(child);
|
||||
var removed = this._children.splice(index, 1)[0];
|
||||
var removed = this.loadedChildren.splice(index, 1)[0];
|
||||
this.emit('remove', index, child);
|
||||
if (!skipMutate) {
|
||||
// trigger removal after we have internally removed it.
|
||||
@ -97,10 +204,12 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
CompositionCollection.prototype.canContain = function (domainObject) {
|
||||
return this.provider.canContain(this.domainObject, domainObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop using this composition collection. This will release any resources
|
||||
* associated with this collection.
|
||||
* @name destroy
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
*/
|
||||
CompositionCollection.prototype.destroy = function () {
|
||||
if (this.provider.off) {
|
||||
this.provider.off(
|
||||
@ -118,5 +227,5 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
return CompositionCollection
|
||||
return CompositionCollection;
|
||||
});
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'lodash',
|
||||
'EventEmitter',
|
||||
@ -9,6 +31,14 @@ define([
|
||||
ObjectAPI,
|
||||
objectUtils
|
||||
) {
|
||||
/**
|
||||
* A CompositionProvider provides the underlying implementation of
|
||||
* composition-related behavior for certain types of domain object.
|
||||
*
|
||||
* @interface CompositionProvider
|
||||
* @memberof module:openmct
|
||||
* @augments EventEmitter
|
||||
*/
|
||||
|
||||
function makeEventName(domainObject, event) {
|
||||
return event + ':' + objectUtils.makeKeyString(domainObject.key);
|
||||
@ -21,10 +51,30 @@ define([
|
||||
DefaultCompositionProvider.prototype =
|
||||
Object.create(EventEmitter.prototype);
|
||||
|
||||
/**
|
||||
* Check if this provider should be used to load composition for a
|
||||
* particular domain object.
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* to check
|
||||
* @returns {boolean} true if this provider can provide
|
||||
* composition for a given domain object
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @method appliesTo
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.appliesTo = function (domainObject) {
|
||||
return !!domainObject.composition;
|
||||
};
|
||||
|
||||
/**
|
||||
* Load any domain objects contained in the composition of this domain
|
||||
* object.
|
||||
* @param {module:openmct.DomainObjcet} domainObject the domain object
|
||||
* for which to load composition
|
||||
* @returns {Promise.<Array.<module:openmct.DomainObject>>} a promise for
|
||||
* the domain objects in this composition
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @method load
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.load = function (domainObject) {
|
||||
return Promise.all(domainObject.composition.map(ObjectAPI.get));
|
||||
};
|
||||
@ -59,10 +109,18 @@ define([
|
||||
);
|
||||
};
|
||||
|
||||
DefaultCompositionProvider.prototype.canContain = function (domainObject, child) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a domain object from another domain object's composition.
|
||||
*
|
||||
* This method is optional; if not present, adding to a domain object's
|
||||
* composition using this provider will be disallowed.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* which should have its composition modified
|
||||
* @param {module:openmct.DomainObject} child the domain object to remove
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @method remove
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.remove = function (domainObject, child) {
|
||||
// TODO: this needs to be synchronized via mutation
|
||||
var index = domainObject.composition.indexOf(child);
|
||||
@ -70,6 +128,18 @@ define([
|
||||
this.emit(makeEventName(domainObject, 'remove'), child);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a domain object to another domain object's composition.
|
||||
*
|
||||
* This method is optional; if not present, adding to a domain object's
|
||||
* composition using this provider will be disallowed.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* which should have its composition modified
|
||||
* @param {module:openmct.DomainObject} child the domain object to add
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @method add
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.add = function (domainObject, child) {
|
||||
// TODO: this needs to be synchronized via mutation
|
||||
domainObject.composition.push(child.key);
|
||||
|
@ -1,37 +0,0 @@
|
||||
# Composition API - Overview
|
||||
|
||||
The composition API is straightforward:
|
||||
|
||||
MCT.composition(object) -- returns a `CompositionCollection` if the object has
|
||||
composition, returns undefined if it doesn't.
|
||||
|
||||
## CompositionCollection
|
||||
|
||||
Has three events:
|
||||
* `load`: when the collection has completed loading.
|
||||
* `add`: when a new object has been added to the collection.
|
||||
* `remove` when an object has been removed from the collection.
|
||||
|
||||
Has three methods:
|
||||
|
||||
`Collection.load()` -- returns a promise that is fulfilled when the composition
|
||||
has loaded.
|
||||
`Collection.add(object)` -- add a domain object to the composition.
|
||||
`Collection.remove(object)` -- remove the object from the composition.
|
||||
|
||||
## Composition providers
|
||||
composition providers are anything that meets the following interface:
|
||||
|
||||
* `provider.appliesTo(domainObject)` -> return true if this provider can provide
|
||||
composition for a given domain object.
|
||||
* `provider.add(domainObject, childObject)` -> adds object
|
||||
* `provider.remove(domainObject, childObject)` -> immediately removes objects
|
||||
* `provider.load(domainObject)` -> returns promise for array of children
|
||||
|
||||
TODO: need to figure out how to make the provider event listeners invisible to the provider.
|
||||
|
||||
There is a default composition provider which handles loading composition for
|
||||
any object with a `composition` property. If you want specialized composition
|
||||
loading behavior, implement your own composition provider and register it with
|
||||
|
||||
`MCT.composition.addProvider(myProvider)`
|
@ -1,10 +1,30 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'./object-utils',
|
||||
'./ObjectAPI',
|
||||
'./objectEventEmitter'
|
||||
], function (
|
||||
utils,
|
||||
ObjectAPI,
|
||||
objectEventEmitter
|
||||
) {
|
||||
function ObjectServiceProvider(objectService, instantiate, topic) {
|
||||
@ -21,6 +41,7 @@ define([
|
||||
*/
|
||||
ObjectServiceProvider.prototype.bridgeEventBuses = function () {
|
||||
var removeGeneralTopicListener;
|
||||
var handleLegacyMutation;
|
||||
|
||||
var handleMutation = function (newStyleObject) {
|
||||
var keyString = utils.makeKeyString(newStyleObject.key);
|
||||
@ -36,7 +57,7 @@ define([
|
||||
removeGeneralTopicListener = this.generalTopic.listen(handleLegacyMutation);
|
||||
}.bind(this);
|
||||
|
||||
var handleLegacyMutation = function (legacyObject){
|
||||
handleLegacyMutation = function (legacyObject) {
|
||||
var newStyleObject = utils.toNewFormat(legacyObject.getModel(), legacyObject.getId());
|
||||
|
||||
//Don't trigger self
|
||||
@ -50,9 +71,7 @@ define([
|
||||
};
|
||||
|
||||
ObjectServiceProvider.prototype.save = function (object) {
|
||||
var key = object.key,
|
||||
keyString = utils.makeKeyString(key),
|
||||
newObject = this.instantiate(utils.toOldFormat(object), keyString);
|
||||
var key = object.key;
|
||||
|
||||
return object.getCapability('persistence')
|
||||
.persist()
|
||||
@ -76,14 +95,14 @@ define([
|
||||
|
||||
// Injects new object API as a decorator so that it hijacks all requests.
|
||||
// Object providers implemented on new API should just work, old API should just work, many things may break.
|
||||
function LegacyObjectAPIInterceptor(ROOTS, instantiate, topic, objectService) {
|
||||
function LegacyObjectAPIInterceptor(openmct, ROOTS, instantiate, topic, objectService) {
|
||||
this.getObjects = function (keys) {
|
||||
var results = {},
|
||||
promises = keys.map(function (keyString) {
|
||||
var key = utils.parseKeyString(keyString);
|
||||
return ObjectAPI.get(key)
|
||||
return openmct.objects.get(key)
|
||||
.then(function (object) {
|
||||
object = utils.toOldFormat(object)
|
||||
object = utils.toOldFormat(object);
|
||||
results[keyString] = instantiate(object, keyString);
|
||||
});
|
||||
});
|
||||
@ -94,12 +113,12 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
ObjectAPI._supersecretSetFallbackProvider(
|
||||
openmct.objects.supersecretSetFallbackProvider(
|
||||
new ObjectServiceProvider(objectService, instantiate, topic)
|
||||
);
|
||||
|
||||
ROOTS.forEach(function (r) {
|
||||
ObjectAPI.addRoot(utils.parseKeyString(r.id));
|
||||
openmct.objects.addRoot(utils.parseKeyString(r.id));
|
||||
});
|
||||
|
||||
return this;
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'lodash',
|
||||
'./objectEventEmitter'
|
||||
@ -5,7 +27,6 @@ define([
|
||||
_,
|
||||
objectEventEmitter
|
||||
) {
|
||||
|
||||
var ANY_OBJECT_EVENT = "mutation";
|
||||
|
||||
/**
|
||||
@ -13,7 +34,7 @@ define([
|
||||
* setters for
|
||||
* @param eventEmitter
|
||||
* @param object
|
||||
* @constructor
|
||||
* @interface MutableObject
|
||||
*/
|
||||
function MutableObject(object) {
|
||||
this.object = object;
|
||||
@ -27,15 +48,30 @@ define([
|
||||
MutableObject.prototype.stopListening = function () {
|
||||
this.unlisteners.forEach(function (unlisten) {
|
||||
unlisten();
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Observe changes to this domain object.
|
||||
* @param {string} path the property to observe
|
||||
* @param {Function} callback a callback to invoke when new values for
|
||||
* this property are observed
|
||||
* @method on
|
||||
* @memberof module:openmct.MutableObject#
|
||||
*/
|
||||
MutableObject.prototype.on = function (path, callback) {
|
||||
var fullPath = qualifiedEventName(this.object, path);
|
||||
objectEventEmitter.on(fullPath, callback);
|
||||
this.unlisteners.push(objectEventEmitter.off.bind(objectEventEmitter, fullPath, callback));
|
||||
};
|
||||
|
||||
/**
|
||||
* Modify this domain object.
|
||||
* @param {string} path the property to modify
|
||||
* @param {*} value the new value for this property
|
||||
* @method set
|
||||
* @memberof module:openmct.MutableObject#
|
||||
*/
|
||||
MutableObject.prototype.set = function (path, value) {
|
||||
|
||||
_.set(this.object, path, value);
|
||||
|
@ -1,110 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
define(['./MutableObject'], function (MutableObject) {
|
||||
describe('Mutable Domain Objects', function () {
|
||||
var domainObject,
|
||||
mutableObject,
|
||||
eventEmitter,
|
||||
arrayProperty,
|
||||
objectProperty,
|
||||
identifier;
|
||||
|
||||
beforeEach(function () {
|
||||
identifier = 'objectId';
|
||||
arrayProperty = [
|
||||
'First array element',
|
||||
'Second array element',
|
||||
'Third array element'
|
||||
];
|
||||
objectProperty = {
|
||||
prop1: 'val1',
|
||||
prop2: 'val2',
|
||||
prop3: {
|
||||
propA: 'valA',
|
||||
propB: 'valB',
|
||||
propC: []
|
||||
}
|
||||
};
|
||||
domainObject = {
|
||||
key: {
|
||||
identifier: identifier
|
||||
},
|
||||
stringProperty: 'stringValue',
|
||||
objectProperty: objectProperty,
|
||||
arrayProperty: arrayProperty
|
||||
};
|
||||
eventEmitter = jasmine.createSpyObj('eventEmitter', [
|
||||
'emit'
|
||||
]);
|
||||
mutableObject = new MutableObject(eventEmitter, domainObject);
|
||||
});
|
||||
|
||||
it('Supports getting and setting of object properties', function () {
|
||||
expect(domainObject.stringProperty).toEqual('stringValue');
|
||||
mutableObject.set('stringProperty', 'updated');
|
||||
expect(domainObject.stringProperty).toEqual('updated');
|
||||
|
||||
var newArrayProperty = [];
|
||||
expect(domainObject.arrayProperty).toEqual(arrayProperty);
|
||||
mutableObject.set('arrayProperty', newArrayProperty);
|
||||
expect(domainObject.arrayProperty).toEqual(newArrayProperty);
|
||||
|
||||
var newObjectProperty = [];
|
||||
expect(domainObject.objectProperty).toEqual(objectProperty);
|
||||
mutableObject.set('objectProperty', newObjectProperty);
|
||||
expect(domainObject.objectProperty).toEqual(newObjectProperty);
|
||||
});
|
||||
|
||||
it('Supports getting and setting of nested properties', function () {
|
||||
expect(domainObject.objectProperty).toEqual(objectProperty);
|
||||
expect(domainObject.objectProperty.prop1).toEqual(objectProperty.prop1);
|
||||
expect(domainObject.objectProperty.prop3.propA).toEqual(objectProperty.prop3.propA);
|
||||
|
||||
mutableObject.set('objectProperty.prop1', 'new-prop-1');
|
||||
expect(domainObject.objectProperty.prop1).toEqual('new-prop-1');
|
||||
|
||||
mutableObject.set('objectProperty.prop3.propA', 'new-prop-A');
|
||||
expect(domainObject.objectProperty.prop3.propA).toEqual('new-prop-A');
|
||||
|
||||
mutableObject.set('arrayProperty.1', 'New Second Array Element');
|
||||
expect(arrayProperty[1]).toEqual('New Second Array Element');
|
||||
});
|
||||
|
||||
it('Fires events when properties change', function () {
|
||||
var newString = 'updated'
|
||||
mutableObject.set('stringProperty', newString);
|
||||
expect(eventEmitter.emit).toHaveBeenCalledWith([identifier, 'stringProperty'].join(':'), newString);
|
||||
|
||||
var newArray = [];
|
||||
mutableObject.set('arrayProperty', newArray);
|
||||
expect(eventEmitter.emit).toHaveBeenCalledWith([identifier, 'arrayProperty'].join(':'), newArray);
|
||||
|
||||
});
|
||||
|
||||
it('Fires wildcard event when any property changes', function () {
|
||||
var newString = 'updated'
|
||||
mutableObject.set('objectProperty.prop3.propA', newString);
|
||||
expect(eventEmitter.emit).toHaveBeenCalledWith([identifier, '*'].join(':'), domainObject);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'lodash',
|
||||
'./object-utils',
|
||||
@ -8,51 +30,104 @@ define([
|
||||
MutableObject
|
||||
) {
|
||||
|
||||
|
||||
/**
|
||||
Object API. Intercepts the existing object API while also exposing
|
||||
A new Object API.
|
||||
* Utilities for loading, saving, and manipulating domain objects.
|
||||
* @interface ObjectAPI
|
||||
* @memberof module:openmct
|
||||
* @implements {module:openmct.ObjectProvider}
|
||||
*/
|
||||
|
||||
var Objects = {},
|
||||
ROOT_REGISTRY = [],
|
||||
PROVIDER_REGISTRY = {},
|
||||
FALLBACK_PROVIDER;
|
||||
|
||||
Objects._supersecretSetFallbackProvider = function (p) {
|
||||
FALLBACK_PROVIDER = p;
|
||||
};
|
||||
|
||||
// Root provider is hardcoded in; can't be skipped.
|
||||
var RootProvider = {
|
||||
function ObjectAPI() {
|
||||
this.providers = {};
|
||||
this.rootRegistry = [];
|
||||
this.rootProvider = {
|
||||
'get': function () {
|
||||
return Promise.resolve({
|
||||
name: 'The root object',
|
||||
type: 'root',
|
||||
composition: ROOT_REGISTRY
|
||||
composition: this.rootRegistry
|
||||
});
|
||||
}.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
|
||||
this.fallbackProvider = p;
|
||||
};
|
||||
|
||||
// Retrieve the provider for a given key.
|
||||
function getProvider(key) {
|
||||
ObjectAPI.prototype.getProvider = function (key) {
|
||||
if (key.identifier === 'ROOT') {
|
||||
return RootProvider;
|
||||
return this.rootProvider;
|
||||
}
|
||||
return PROVIDER_REGISTRY[key.namespace] || FALLBACK_PROVIDER;
|
||||
}
|
||||
|
||||
Objects.addProvider = function (namespace, provider) {
|
||||
PROVIDER_REGISTRY[namespace] = provider;
|
||||
return this.providers[key.namespace] || this.fallbackProvider;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Register a new object provider for a particular namespace.
|
||||
*
|
||||
* @param {string} namespace the namespace for which to provide objects
|
||||
* @param {module:openmct.ObjectProvider} provider the provider which
|
||||
* will handle loading domain objects from this namespace
|
||||
* @memberof {module:openmct.ObjectAPI#}
|
||||
* @name addProvider
|
||||
*/
|
||||
ObjectAPI.prototype.addProvider = function (namespace, provider) {
|
||||
this.providers[namespace] = provider;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides the ability to read, write, and delete domain objects.
|
||||
*
|
||||
* When registering a new object provider, all methods on this interface
|
||||
* are optional.
|
||||
*
|
||||
* @interface ObjectProvider
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
|
||||
/**
|
||||
* Save this domain object in its current state.
|
||||
*
|
||||
* @method save
|
||||
* @memberof module:openmct.ObjectProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object to
|
||||
* save
|
||||
* @returns {Promise} a promise which will resolve when the domain object
|
||||
* has been saved, or be rejected if it cannot be saved
|
||||
*/
|
||||
|
||||
/**
|
||||
* Delete this domain object.
|
||||
*
|
||||
* @method delete
|
||||
* @memberof module:openmct.ObjectProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object to
|
||||
* delete
|
||||
* @returns {Promise} a promise which will resolve when the domain object
|
||||
* has been deleted, or be rejected if it cannot be deleted
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a domain object.
|
||||
*
|
||||
* @method get
|
||||
* @memberof module:openmct.ObjectProvider#
|
||||
* @param {string} key the key for the domain object to load
|
||||
* @returns {Promise} a promise which will resolve when the domain object
|
||||
* has been saved, or be rejected if it cannot be saved
|
||||
*/
|
||||
|
||||
[
|
||||
'save',
|
||||
'delete',
|
||||
'get'
|
||||
].forEach(function (method) {
|
||||
Objects[method] = function () {
|
||||
ObjectAPI.prototype[method] = function () {
|
||||
var key = arguments[0],
|
||||
provider = getProvider(key);
|
||||
provider = this.getProvider(key);
|
||||
|
||||
if (!provider) {
|
||||
throw new Error('No Provider Matched');
|
||||
@ -66,12 +141,26 @@ define([
|
||||
};
|
||||
});
|
||||
|
||||
Objects.addRoot = function (key) {
|
||||
ROOT_REGISTRY.unshift(key);
|
||||
/**
|
||||
* Add a root-level object.
|
||||
* @param {module:openmct.DomainObject} domainObject the root-level object
|
||||
* to add.
|
||||
* @method addRoot
|
||||
* @memberof module:openmct.ObjectAPI#
|
||||
*/
|
||||
ObjectAPI.prototype.addRoot = function (key) {
|
||||
this.rootRegistry.unshift(key);
|
||||
};
|
||||
|
||||
Objects.removeRoot = function (key) {
|
||||
ROOT_REGISTRY = ROOT_REGISTRY.filter(function (k) {
|
||||
/**
|
||||
* Remove a root-level object.
|
||||
* @param {module:openmct.ObjectAPI~Identifier} id the identifier of the
|
||||
* root-level object to remove.
|
||||
* @method removeRoot
|
||||
* @memberof module:openmct.ObjectAPI#
|
||||
*/
|
||||
ObjectAPI.prototype.removeRoot = function (key) {
|
||||
this.rootRegistry = this.rootRegistry.filter(function (k) {
|
||||
return (
|
||||
k.identifier !== key.identifier ||
|
||||
k.namespace !== key.namespace
|
||||
@ -79,9 +168,67 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
Objects.getMutable = function (object) {
|
||||
return new MutableObject(object);
|
||||
/**
|
||||
* Modify a domain object.
|
||||
* @param {module:openmct.DomainObject} object the object to mutate
|
||||
* @param {string} path the property to modify
|
||||
* @param {*} value the new value for this property
|
||||
* @method mutate
|
||||
* @memberof module:openmct.ObjectAPI#
|
||||
*/
|
||||
ObjectAPI.prototype.mutate = function (domainObject, path, value) {
|
||||
return new MutableObject(domainObject).set(path, value);
|
||||
};
|
||||
|
||||
return Objects;
|
||||
/**
|
||||
* Observe changes to a domain object.
|
||||
* @param {module:openmct.DomainObject} object the object to observe
|
||||
* @param {string} path the property to observe
|
||||
* @param {Function} callback a callback to invoke when new values for
|
||||
* this property are observed
|
||||
* @method observe
|
||||
* @memberof module:openmct.ObjectAPI#
|
||||
*/
|
||||
ObjectAPI.prototype.observe = function (domainObject, path, callback) {
|
||||
var mutableObject = new MutableObject(domainObject);
|
||||
mutableObject.on(path, callback);
|
||||
return mutableObject.stopListening.bind(mutableObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* Uniquely identifies a domain object.
|
||||
*
|
||||
* @typedef Identifier
|
||||
* @memberof module:openmct.ObjectAPI~
|
||||
* @property {string} namespace the namespace to/from which this domain
|
||||
* object should be loaded/stored.
|
||||
* @property {string} key a unique identifier for the domain object
|
||||
* within that namespace
|
||||
*/
|
||||
|
||||
/**
|
||||
* A domain object is an entity of relevance to a user's workflow, that
|
||||
* should appear as a distinct and meaningful object within the user
|
||||
* interface. Examples of domain objects are folders, telemetry sensors,
|
||||
* and so forth.
|
||||
*
|
||||
* A few common properties are defined for domain objects. Beyond these,
|
||||
* individual types of domain objects may add more as they see fit.
|
||||
*
|
||||
* @property {module:openmct.ObjectAPI~Identifier} identifier a key/namespace pair which
|
||||
* uniquely identifies this domain object
|
||||
* @property {string} type the type of domain object
|
||||
* @property {string} name the human-readable name for this domain object
|
||||
* @property {string} [creator] the user name of the creator of this domain
|
||||
* object
|
||||
* @property {number} [modified] the time, in milliseconds since the UNIX
|
||||
* epoch, at which this domain object was last modified
|
||||
* @property {module:openmct.ObjectAPI~Identifier[]} [composition] if
|
||||
* present, this will be used by the default composition provider
|
||||
* to load domain objects
|
||||
* @typedef DomainObject
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
|
||||
return ObjectAPI;
|
||||
});
|
||||
|
@ -1,54 +0,0 @@
|
||||
# Object API - Overview
|
||||
|
||||
The object API provides methods for fetching domain objects.
|
||||
|
||||
# Keys
|
||||
Keys are a composite identifier that is used to create and persist objects. Ex:
|
||||
```javascript
|
||||
{
|
||||
namespace: 'elastic',
|
||||
identifier: 'myIdentifier'
|
||||
}
|
||||
```
|
||||
|
||||
In old MCT days, we called this an "id", and we encoded it in a single string.
|
||||
The above key would encode into the identifier, `elastic:myIdentifier`.
|
||||
|
||||
When interacting with the API you will be dealing with key objects.
|
||||
|
||||
## Roots
|
||||
|
||||
"Roots" are objects that Open MCT will load at run time and form the basic entry point for users. You can register new root objects by calling the
|
||||
|
||||
# Configuring the Object API
|
||||
|
||||
The following methods should be used before calling run. They allow you to
|
||||
configure the persistence space of MCT.
|
||||
|
||||
* `MCT.objects.addRoot(key)` -- add a "ROOT" to Open MCT by specifying it's key.
|
||||
* `MCT.objects.removeRoot(key)` -- Remove a "ROOT" from Open MCT by key.
|
||||
* `MCT.objects.addProvider(namespace, provider)` -- register an object provider for a specific namespace. See below for documentation on the provider interface.
|
||||
|
||||
# defining providers
|
||||
|
||||
# Using the object API
|
||||
|
||||
The object API provides methods for getting, saving, and deleting objects. Plugin developers may not frequently need to interact with this API, as they should receive instances of the objects as needed.
|
||||
|
||||
* MCT.objects.get(key) -> returns promise for an object
|
||||
* MCT.objects.save(object) -> returns promise that is resolved when object has been saved
|
||||
* MCT.objects.delete(object) -> returns promise that is resolved when object has been deleted
|
||||
|
||||
## Configuration Example: Adding a groot
|
||||
|
||||
See the tutorial in [object-provider.html](object-provider.html).
|
||||
|
||||
### Making a custom provider:
|
||||
|
||||
All methods on the provider interface are optional.
|
||||
|
||||
* `provider.get(key)` -> returns promise for a domain object.
|
||||
* `provider.save(domainObject)` -> returns promise that is fulfilled when object has been saved.
|
||||
* `provider.delete(domainObject)` -> returns promise that is fulfilled when object has been deleted.
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
@ -39,6 +39,7 @@ define([
|
||||
priority: "mandatory",
|
||||
implementation: LegacyObjectAPIInterceptor,
|
||||
depends: [
|
||||
"openmct",
|
||||
"roots[]",
|
||||
"instantiate",
|
||||
"topic"
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
|
||||
], function (
|
||||
@ -12,22 +34,21 @@ define([
|
||||
}
|
||||
var namespace = '',
|
||||
identifier = key;
|
||||
for (var i = 0, escaped = false, len=key.length; i < key.length; i++) {
|
||||
for (var i = 0, escaped = false; i < key.length; i++) {
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
namespace += key[i];
|
||||
} else {
|
||||
if (key[i] === "\\") {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
if (key[i] === ":") {
|
||||
} else if (key[i] === ":") {
|
||||
// namespace = key.slice(0, i);
|
||||
identifier = key.slice(i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
namespace += key[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (key === namespace) {
|
||||
namespace = '';
|
||||
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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 (
|
||||
|
319
src/api/telemetry/TelemetryAPI.js
Normal file
319
src/api/telemetry/TelemetryAPI.js
Normal file
@ -0,0 +1,319 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'lodash',
|
||||
'EventEmitter'
|
||||
], function (
|
||||
_,
|
||||
EventEmitter
|
||||
) {
|
||||
/**
|
||||
* A LimitEvaluator may be used to detect when telemetry values
|
||||
* have exceeded nominal conditions.
|
||||
*
|
||||
* @interface LimitEvaluator
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check for any limit violations associated with a telemetry datum.
|
||||
* @method evaluate
|
||||
* @param {*} datum the telemetry datum to evaluate
|
||||
* @param {TelemetryProperty} the property to check for limit violations
|
||||
* @memberof module:openmct.TelemetryAPI~LimitEvaluator
|
||||
* @returns {module:openmct.TelemetryAPI~LimitViolation} metadata about
|
||||
* the limit violation, or undefined if a value is within limits
|
||||
*/
|
||||
|
||||
/**
|
||||
* A violation of limits defined for a telemetry property.
|
||||
* @typedef LimitViolation
|
||||
* @memberof {module:openmct.TelemetryAPI~}
|
||||
* @property {string} cssclass the class (or space-separated classes) to
|
||||
* apply to display elements for values which violate this limit
|
||||
* @property {string} name the human-readable name for the limit violation
|
||||
*/
|
||||
|
||||
/**
|
||||
* A TelemetryFormatter converts telemetry values for purposes of
|
||||
* display as text.
|
||||
*
|
||||
* @interface TelemetryFormatter
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve the 'key' from the datum and format it accordingly to
|
||||
* telemetry metadata in domain object.
|
||||
*
|
||||
* @method format
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryFormatter#
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// format map is a placeholder until we figure out format service.
|
||||
var FORMAT_MAP = {
|
||||
generic: function (range) {
|
||||
return function (datum) {
|
||||
return datum[range.key];
|
||||
};
|
||||
},
|
||||
enum: function (range) {
|
||||
var enumMap = _.indexBy(range.enumerations, 'value');
|
||||
return function (datum) {
|
||||
try {
|
||||
return enumMap[datum[range.valueKey]].text;
|
||||
} catch (e) {
|
||||
return datum[range.valueKey];
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
FORMAT_MAP.number =
|
||||
FORMAT_MAP.float =
|
||||
FORMAT_MAP.integer =
|
||||
FORMAT_MAP.ascii =
|
||||
FORMAT_MAP.generic;
|
||||
|
||||
/**
|
||||
* Describes a property which would be found in a datum of telemetry
|
||||
* associated with a particular domain object.
|
||||
*
|
||||
* @typedef TelemetryProperty
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
* @property {string} key the name of the property in the datum which
|
||||
* contains this telemetry value
|
||||
* @property {string} name the human-readable name for this property
|
||||
* @property {string} [units] the units associated with this property
|
||||
* @property {boolean} [temporal] true if this property is a timestamp, or
|
||||
* may be otherwise used to order telemetry in a time-like
|
||||
* fashion; default is false
|
||||
* @property {boolean} [numeric] true if the values for this property
|
||||
* can be interpreted plainly as numbers; default is true
|
||||
* @property {boolean} [enumerated] true if this property may have only
|
||||
* certain specific values; default is false
|
||||
* @property {string} [values] for enumerated states, an ordered list
|
||||
* of possible values
|
||||
*/
|
||||
|
||||
/**
|
||||
* Describes and bounds requests for telemetry data.
|
||||
*
|
||||
* @typedef TelemetryRequest
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
* @property {string} sort the key of the property to sort by. This may
|
||||
* be prefixed with a "+" or a "-" sign to sort in ascending
|
||||
* or descending order respectively. If no prefix is present,
|
||||
* ascending order will be used.
|
||||
* @property {*} start the lower bound for values of the sorting property
|
||||
* @property {*} end the upper bound for values of the sorting property
|
||||
* @property {string[]} strategies symbolic identifiers for strategies
|
||||
* (such as `minmax`) which may be recognized by providers;
|
||||
* these will be tried in order until an appropriate provider
|
||||
* is found
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides telemetry data. To connect to new data sources, new
|
||||
* TelemetryProvider implementations should be
|
||||
* [registered]{@link module:openmct.TelemetryAPI#addProvider}.
|
||||
*
|
||||
* @interface TelemetryProvider
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An interface for retrieving telemetry data associated with a domain
|
||||
* object.
|
||||
*
|
||||
* @interface TelemetryAPI
|
||||
* @augments module:openmct.TelemetryAPI~TelemetryProvider
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function TelemetryAPI() {
|
||||
this.providersByStrategy = {};
|
||||
this.defaultProviders = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this provider can supply telemetry data associated with
|
||||
* this domain object.
|
||||
*
|
||||
* @method canProvideTelemetry
|
||||
* @param {module:openmct.DomainObject} domainObject the object for
|
||||
* which telemetry would be provided
|
||||
* @returns {boolean} true if telemetry can be provided
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
*/
|
||||
TelemetryAPI.prototype.canProvideTelemetry = function (domainObject) {
|
||||
return this.defaultProviders.some(function (provider) {
|
||||
return provider.canProvideTelemetry(domainObject);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a telemetry provider with the telemetry service. This
|
||||
* allows you to connect alternative telemetry sources.
|
||||
* @method addProvider
|
||||
* @memberof module:openmct.TelemetryAPI#
|
||||
* @param {module:openmct.TelemetryAPI~TelemetryProvider} provider the new
|
||||
* telemetry provider
|
||||
* @param {string} [strategy] the request strategy supported by
|
||||
* this provider. If omitted, this will be used as a
|
||||
* default provider (when no strategy is requested or no
|
||||
* matching strategy is found.)
|
||||
*/
|
||||
TelemetryAPI.prototype.addProvider = function (provider, strategy) {
|
||||
if (!strategy) {
|
||||
this.defaultProviders.push(provider);
|
||||
} else {
|
||||
this.providersByStrategy[strategy] =
|
||||
this.providersByStrategy[strategy] || [];
|
||||
this.providersByStrategy[strategy].push(provider);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
TelemetryAPI.prototype.findProvider = function (domainObject, strategy) {
|
||||
function supportsDomainObject(provider) {
|
||||
return provider.canProvideTelemetry(domainObject);
|
||||
}
|
||||
|
||||
if (strategy) {
|
||||
var eligibleProviders =
|
||||
(this.providersByStrategy[strategy] || [])
|
||||
.filter(supportsDomainObject);
|
||||
if (eligibleProviders.length > 0) {
|
||||
return eligibleProviders[0];
|
||||
}
|
||||
}
|
||||
|
||||
return this.defaultProviders.filter(supportsDomainObject)[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Request historical telemetry for a domain object.
|
||||
* The `options` argument allows you to specify filters
|
||||
* (start, end, etc.), sort order, and strategies for retrieving
|
||||
* telemetry (aggregation, latest available, etc.).
|
||||
*
|
||||
* @method request
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* which has associated telemetry
|
||||
* @param {module:openmct.TelemetryAPI~TelemetryRequest} options
|
||||
* options for this historical request
|
||||
* @returns {Promise.<object[]>} a promise for an array of
|
||||
* telemetry data
|
||||
*/
|
||||
TelemetryAPI.prototype.request = function (domainObject, options) {
|
||||
var provider = this.findProvider(domainObject, options.strategy);
|
||||
return provider ?
|
||||
provider.request(domainObject, options) :
|
||||
Promise.reject([]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribe to realtime telemetry for a specific domain object.
|
||||
* The callback will be called whenever data is received from a
|
||||
* realtime provider.
|
||||
*
|
||||
* @method subscribe
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* which has associated telemetry
|
||||
* @param {Function} callback the callback to invoke with new data, as
|
||||
* it becomes available
|
||||
* @param {module:openmct.TelemetryAPI~TelemetryRequest} options
|
||||
* options for this request
|
||||
* @returns {Function} a function which may be called to terminate
|
||||
* the subscription
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a list of all telemetry properties defined for this
|
||||
* domain object.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain
|
||||
* object for which to request telemetry
|
||||
* @returns {module:openmct.TelemetryAPI~TelemetryProperty[]}
|
||||
* telemetry metadata
|
||||
* @method properties
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
*/
|
||||
|
||||
/**
|
||||
* Telemetry formatters help you format telemetry values for
|
||||
* display. Under the covers, they use telemetry metadata to
|
||||
* interpret your telemetry data, and then they use the format API
|
||||
* to format that data for display.
|
||||
*
|
||||
* This method is optional.
|
||||
* If a provider does not implement this method, it is presumed
|
||||
* that all telemetry associated with this domain object can
|
||||
* be formatted correctly by string coercion.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain
|
||||
* object for which to format telemetry
|
||||
* @returns {module:openmct.TelemetryAPI~TelemetryFormatter}
|
||||
* @method formatter
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a limit evaluator for this domain object.
|
||||
* Limit Evaluators help you evaluate limit and alarm status of individual telemetry datums for display purposes without having to interact directly with the Limit API.
|
||||
*
|
||||
* This method is optional.
|
||||
* If a provider does not implement this method, it is presumed
|
||||
* that no limits are defined for this domain object's telemetry.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain
|
||||
* object for which to evaluate limits
|
||||
* @returns {module:openmct.TelemetryAPI~LimitEvaluator}
|
||||
* @method limitEvaluator
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
*/
|
||||
_.forEach({
|
||||
subscribe: undefined,
|
||||
properties: [],
|
||||
formatter: undefined,
|
||||
limitEvaluator: undefined
|
||||
}, function (defaultValue, method) {
|
||||
TelemetryAPI.prototype[method] = function (domainObject) {
|
||||
var provider = this.findProvider(domainObject);
|
||||
return provider ?
|
||||
provider[method].apply(provider, arguments) :
|
||||
defaultValue;
|
||||
};
|
||||
});
|
||||
|
||||
return TelemetryAPI;
|
||||
});
|
45
src/api/telemetry/bundle.js
Normal file
45
src/api/telemetry/bundle.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'./TelemetryAPI',
|
||||
'legacyRegistry'
|
||||
], function (
|
||||
TelemetryAPI,
|
||||
legacyRegistry
|
||||
) {
|
||||
legacyRegistry.register('api/telemetry-api', {
|
||||
name: 'Telemetry API',
|
||||
description: 'The public Telemetry API',
|
||||
extensions: {
|
||||
runs: [
|
||||
{
|
||||
key: "TelemetryAPI",
|
||||
implementation: TelemetryAPI,
|
||||
depends: [
|
||||
'formatService'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
51
src/api/types/TypeRegistry.js
Normal file
51
src/api/types/TypeRegistry.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*****************************************************************************
|
||||
* 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([], function () {
|
||||
|
||||
/**
|
||||
* A TypeRegistry maintains the definitions for different types
|
||||
* that domain objects may have.
|
||||
* @interface TypeRegistry
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function TypeRegistry() {
|
||||
this.types = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new type of view.
|
||||
*
|
||||
* @param {string} typeKey a string identifier for this type
|
||||
* @param {module:openmct.Type} type the type to add
|
||||
* @method addProvider
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
*/
|
||||
TypeRegistry.prototype.addType = function (typeKey, type) {
|
||||
this.types[typeKey] = type;
|
||||
};
|
||||
|
||||
|
||||
return TypeRegistry;
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,34 @@
|
||||
/*****************************************************************************
|
||||
* 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(['text!./dialog.html', 'zepto'], function (dialogTemplate, $) {
|
||||
|
||||
/**
|
||||
* A dialog may be displayed to show blocking content to users.
|
||||
* @param {module:openmct.View} view the view to show in the dialog
|
||||
* @param {string} [title] the title for this dialog
|
||||
* @constructor
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function Dialog(view, title) {
|
||||
this.view = view;
|
||||
this.title = title;
|
||||
@ -6,6 +36,13 @@ define(['text!./dialog.html', 'zepto'], function (dialogTemplate, $) {
|
||||
this.enabledState = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display this dialog.
|
||||
* @returns {Promise} a promise that will be resolved if the user
|
||||
* chooses "OK", an rejected if the user chooses "cancel"
|
||||
* @method show
|
||||
* @memberof module:openmct.Dialog#
|
||||
*/
|
||||
Dialog.prototype.show = function () {
|
||||
if (this.showing) {
|
||||
throw new Error("Dialog already showing.");
|
||||
@ -49,6 +86,13 @@ define(['text!./dialog.html', 'zepto'], function (dialogTemplate, $) {
|
||||
this.showing = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set the "enabled" state of the OK button for this dialog.
|
||||
* @param {boolean} [state] true to enable, false to disable
|
||||
* @returns {boolean} true if enabled, false if disabled
|
||||
* @method enabled
|
||||
* @memberof module:openmct.Dialog#
|
||||
*/
|
||||
Dialog.prototype.enabled = function (state) {
|
||||
if (state !== undefined) {
|
||||
this.enabledState = state;
|
||||
|
68
src/api/ui/GestureAPI.js
Normal file
68
src/api/ui/GestureAPI.js
Normal file
@ -0,0 +1,68 @@
|
||||
/*****************************************************************************
|
||||
* 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([], function () {
|
||||
/**
|
||||
* Allows support for common user actions to be attached to views.
|
||||
* @interface GestureAPI
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function GestureAPI(selectGesture, contextMenuGesture) {
|
||||
this.selectGesture = selectGesture;
|
||||
this.contextMenuGesture = contextMenuGesture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Designate an HTML element as selectable, and associated with a
|
||||
* particular object.
|
||||
*
|
||||
* @param {HTMLElement} htmlElement the element to make selectable
|
||||
* @param {*} item the object which should become selected when this
|
||||
* element is clicked.
|
||||
* @returns {Function} a function to remove selectability from this
|
||||
* HTML element.
|
||||
* @method selectable
|
||||
* @memberof module:openmct.GestureAPI#
|
||||
*/
|
||||
GestureAPI.prototype.selectable = function (htmlElement, item) {
|
||||
return this.selectGesture.apply(htmlElement, item);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Designate an HTML element as having a context menu associated with
|
||||
* the provided item.
|
||||
*
|
||||
* @private
|
||||
* @param {HTMLElement} htmlElement the element to make selectable
|
||||
* @param {*} item the object for which a context menu should appear
|
||||
* @returns {Function} a function to remove this geture from this
|
||||
* HTML element.
|
||||
* @method selectable
|
||||
* @memberof module:openmct.GestureAPI#
|
||||
*/
|
||||
GestureAPI.prototype.contextMenu = function (htmlElement, item) {
|
||||
return this.contextMenuGesture.apply(htmlElement, item);
|
||||
};
|
||||
|
||||
return GestureAPI;
|
||||
});
|
@ -1,3 +1,25 @@
|
||||
/*****************************************************************************
|
||||
* 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',
|
||||
|
||||
@ -63,7 +85,7 @@ define([
|
||||
'../platform/representation/bundle',
|
||||
'../platform/search/bundle',
|
||||
'../platform/status/bundle',
|
||||
'../platform/telemetry/bundle',
|
||||
'../platform/telemetry/bundle'
|
||||
], function (legacyRegistry) {
|
||||
|
||||
var DEFAULTS = [
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* 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 Web is licensed under the Apache License, Version 2.0 (the
|
||||
* 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.
|
||||
@ -14,7 +14,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* 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.
|
||||
|
78
src/selection/ContextManager.js
Normal file
78
src/selection/ContextManager.js
Normal file
@ -0,0 +1,78 @@
|
||||
/*****************************************************************************
|
||||
* 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)
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
|
||||
|
||||
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;
|
||||
});
|
58
src/selection/HoverGesture.js
Normal file
58
src/selection/HoverGesture.js
Normal 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;
|
||||
});
|
60
src/selection/SelectGesture.js
Normal file
60
src/selection/SelectGesture.js
Normal 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;
|
||||
});
|
69
src/selection/Selection.js
Normal file
69
src/selection/Selection.js
Normal file
@ -0,0 +1,69 @@
|
||||
/*****************************************************************************
|
||||
* 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) {
|
||||
|
||||
/**
|
||||
* Manages selection state for Open MCT
|
||||
* @private
|
||||
*/
|
||||
function Selection() {
|
||||
EventEmitter.call(this);
|
||||
this.selected = [];
|
||||
}
|
||||
|
||||
Selection.prototype = Object.create(EventEmitter.prototype);
|
||||
|
||||
Selection.prototype.add = function (context) {
|
||||
this.clear(); // Only allow single select as initial simplification
|
||||
this.selected.push(context);
|
||||
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;
|
||||
});
|
@ -1,3 +1,33 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Open MCT https://nasa.github.io/openmct/
|
||||
* Version @@version
|
||||
* Built @@timestamp
|
||||
* Revision @@revision
|
||||
* Branch @@branch
|
||||
*/
|
||||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([], factory);
|
||||
|
152
src/ui/ViewRegistry.js
Normal file
152
src/ui/ViewRegistry.js
Normal file
@ -0,0 +1,152 @@
|
||||
/*****************************************************************************
|
||||
* 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([], function () {
|
||||
/**
|
||||
* A ViewRegistry maintains the definitions for different kinds of views
|
||||
* that may occur in different places in the user interface.
|
||||
* @interface ViewRegistry
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function ViewRegistry() {
|
||||
this.providers = [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private for platform-internal use
|
||||
* @param {*} item the object to be viewed
|
||||
* @returns {module:openmct.ViewProvider[]} any providers
|
||||
* which can provide views of this object
|
||||
*/
|
||||
ViewRegistry.prototype.get = function (item) {
|
||||
return this.providers.filter(function (provider) {
|
||||
return provider.canView(item);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new type of view.
|
||||
*
|
||||
* @param {module:openmct.ViewProvider} provider the provider for this view
|
||||
* @method addProvider
|
||||
* @memberof module:openmct.ViewRegistry#
|
||||
*/
|
||||
ViewRegistry.prototype.addProvider = function (provider) {
|
||||
this.providers.push(provider);
|
||||
};
|
||||
|
||||
/**
|
||||
* A View is used to provide displayable content, and to react to
|
||||
* associated life cycle events.
|
||||
*
|
||||
* @name View
|
||||
* @interface
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
|
||||
/**
|
||||
* Populate the supplied DOM element with the contents of this view.
|
||||
*
|
||||
* View implementations should use this method to attach any
|
||||
* listeners or acquire other resources that are necessary to keep
|
||||
* the contents of this view up-to-date.
|
||||
*
|
||||
* @param {HTMLElement} container the DOM element to populate
|
||||
* @method show
|
||||
* @memberof module:openmct.View#
|
||||
*/
|
||||
|
||||
/**
|
||||
* Release any resources associated with this view.
|
||||
*
|
||||
* View implementations should use this method to detach any
|
||||
* listeners or release other resources that are no longer necessary
|
||||
* once a view is no longer used.
|
||||
*
|
||||
* @method destroy
|
||||
* @memberof module:openmct.View#
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exposes types of views in Open MCT.
|
||||
*
|
||||
* @interface ViewProvider
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if this provider can supply views for a domain object.
|
||||
*
|
||||
* When called by Open MCT, this may include additional arguments
|
||||
* which are on the path to the object to be viewed; for instance,
|
||||
* when viewing "A Folder" within "My Items", this method will be
|
||||
* invoked with "A Folder" (as a domain object) as the first argument,
|
||||
* and "My Items" as the second argument.
|
||||
*
|
||||
* @method canView
|
||||
* @memberof module:openmct.ViewProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* to be viewed
|
||||
* @returns {boolean} true if this domain object can be viewed using
|
||||
* this provider
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provide a view of this object.
|
||||
*
|
||||
* When called by Open MCT, this may include additional arguments
|
||||
* which are on the path to the object to be viewed; for instance,
|
||||
* when viewing "A Folder" within "My Items", this method will be
|
||||
* invoked with "A Folder" (as a domain object) as the first argument,
|
||||
* and "My Items" as the second argument.
|
||||
*
|
||||
* @method view
|
||||
* @memberof module:openmct.ViewProvider#
|
||||
* @param {*} object the object to be viewed
|
||||
* @returns {module:openmct.View} a view of this domain object
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get metadata associated with this view provider. This may be used
|
||||
* to populate the user interface with options associated with this
|
||||
* view provider.
|
||||
*
|
||||
* @method metadata
|
||||
* @memberof module:openmct.ViewProvider#
|
||||
* @returns {module:openmct.ViewProvider~ViewMetadata} view metadata
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef ViewMetadata
|
||||
* @memberof module:openmct.ViewProvider~
|
||||
* @property {string} name the human-readable name of this view
|
||||
* @property {string} key a machine-readable name for this view
|
||||
* @property {string} [description] a longer-form description (typically
|
||||
* a single sentence or short paragraph) of this kind of view
|
||||
* @property {string} cssclass the CSS class to apply to labels for this
|
||||
* view (to add icons, for instance)
|
||||
*/
|
||||
|
||||
return ViewRegistry;
|
||||
|
||||
});
|
Reference in New Issue
Block a user