mirror of
https://github.com/nasa/openmct.git
synced 2025-04-12 05:40:17 +00:00
Merge branch 'master' into mct1221
This commit is contained in:
commit
c9ac85089a
18
API.md
18
API.md
@ -71,9 +71,10 @@ Custom types may be registered via
|
||||
[`openmct.types`]{@link module:openmct.MCT#types}:
|
||||
|
||||
```
|
||||
openmct.types.addType('my-type', new openmct.Type({
|
||||
openmct.types.addType('my-type', {
|
||||
label: "My Type",
|
||||
description: "This is a type that I added!"
|
||||
description: "This is a type that I added!",
|
||||
creatable: true
|
||||
});
|
||||
```
|
||||
|
||||
@ -118,18 +119,11 @@ To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method
|
||||
of the [object API]{@link module:openmct.ObjectAPI}:
|
||||
|
||||
```
|
||||
openmct.objects.addRoot({
|
||||
identifier: { key: "my-key", namespace: "my-namespace" }
|
||||
name: "My Root-level Object",
|
||||
type: "my-type"
|
||||
});
|
||||
openmct.objects.addRoot({ key: "my-key", namespace: "my-namespace" });
|
||||
```
|
||||
|
||||
You can also remove this root-level object via its identifier:
|
||||
|
||||
```
|
||||
openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" });
|
||||
```
|
||||
Root objects are loaded just like any other objects, i.e. via an object
|
||||
provider.
|
||||
|
||||
### Adding Composition Providers
|
||||
|
||||
|
@ -23,20 +23,18 @@
|
||||
|
||||
define([
|
||||
"./src/RemsTelemetryServerAdapter",
|
||||
"./src/RemsTelemetryInitializer",
|
||||
"./src/RemsTelemetryModelProvider",
|
||||
"./src/RemsTelemetryProvider",
|
||||
'legacyRegistry',
|
||||
"module"
|
||||
], function (
|
||||
RemsTelemetryServerAdapter,
|
||||
RemsTelemetryInitializer,
|
||||
RemsTelemetryModelProvider,
|
||||
RemsTelemetryProvider,
|
||||
legacyRegistry
|
||||
) {
|
||||
"use strict";
|
||||
legacyRegistry.register("example/msl-adapter", {
|
||||
legacyRegistry.register("example/msl", {
|
||||
"name" : "Mars Science Laboratory Data Adapter",
|
||||
"extensions" : {
|
||||
"types": [
|
||||
@ -81,7 +79,7 @@ define([
|
||||
"model": {
|
||||
"type": "msl.curiosity",
|
||||
"name": "Mars Science Laboratory",
|
||||
"composition": []
|
||||
"composition": ["msl_tlm:rems"]
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -92,12 +90,6 @@ define([
|
||||
"depends": ["$q", "$http", "$log", "REMS_WS_URL"]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": RemsTelemetryInitializer,
|
||||
"depends": ["rems.adapter", "objectService"]
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"provides": "modelService",
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
function (){
|
||||
"use strict";
|
||||
|
||||
var TAXONOMY_ID = "msl:curiosity",
|
||||
PREFIX = "msl_tlm:";
|
||||
|
||||
/**
|
||||
* Function that is executed on application startup and populates
|
||||
* the navigation tree with objects representing the MSL REMS
|
||||
* telemetry points. The tree is populated based on the data
|
||||
* dictionary on the provider.
|
||||
*
|
||||
* @param {RemsTelemetryServerAdapter} adapter The server adapter
|
||||
* (necessary in order to retrieve data dictionary)
|
||||
* @param objectService the ObjectService which allows for lookup of
|
||||
* objects by ID
|
||||
* @constructor
|
||||
*/
|
||||
function RemsTelemetryInitializer(adapter, objectService) {
|
||||
function makeId(element) {
|
||||
return PREFIX + element.identifier;
|
||||
}
|
||||
|
||||
function initializeTaxonomy(dictionary) {
|
||||
function getTaxonomyObject(domainObjects) {
|
||||
return domainObjects[TAXONOMY_ID];
|
||||
}
|
||||
|
||||
function populateModel (taxonomyObject) {
|
||||
return taxonomyObject.useCapability(
|
||||
"mutation",
|
||||
function (model) {
|
||||
model.name = dictionary.name;
|
||||
model.composition = dictionary.instruments.map(makeId);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
objectService.getObjects([TAXONOMY_ID])
|
||||
.then(getTaxonomyObject)
|
||||
.then(populateModel);
|
||||
}
|
||||
initializeTaxonomy(adapter.dictionary);
|
||||
}
|
||||
return RemsTelemetryInitializer;
|
||||
}
|
||||
);
|
@ -155,7 +155,7 @@ gulp.task('serve', function () {
|
||||
var app = require('./app.js');
|
||||
});
|
||||
|
||||
gulp.task('develop', ['serve', 'install', 'watch']);
|
||||
gulp.task('develop', ['serve', 'stylesheets', 'watch']);
|
||||
|
||||
gulp.task('install', [ 'assets', 'scripts' ]);
|
||||
|
||||
|
@ -32,7 +32,8 @@
|
||||
[
|
||||
'example/imagery',
|
||||
'example/eventGenerator',
|
||||
'example/generator'
|
||||
'example/generator',
|
||||
'platform/features/my-items'
|
||||
].forEach(
|
||||
openmct.legacyRegistry.enable.bind(openmct.legacyRegistry)
|
||||
);
|
||||
|
@ -104,9 +104,17 @@ body.desktop .mini-tab-icon {
|
||||
}
|
||||
}
|
||||
|
||||
@mixin btnSetButtonFirst() {
|
||||
@include border-left-radius($controlCr);
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
@mixin btnSetButtonLast() {
|
||||
@include border-right-radius($controlCr);
|
||||
}
|
||||
|
||||
.l-btn-set {
|
||||
// Buttons that have a very tight conceptual grouping - no internal space between them.
|
||||
// Structure: .btn-set > mct-representation class=first|last > .s-button
|
||||
font-size: 0; // Remove space between s-button elements due to white space in markup
|
||||
|
||||
.s-button {
|
||||
@ -114,20 +122,16 @@ body.desktop .mini-tab-icon {
|
||||
margin-left: 1px;
|
||||
}
|
||||
|
||||
.first {
|
||||
.s-button,
|
||||
&.s-button {
|
||||
@include border-left-radius($controlCr);
|
||||
margin-left: 0;
|
||||
}
|
||||
> .s-button {
|
||||
// Styles for .s-button as immediate descendants in .l-btn-set
|
||||
&:first-child { @include btnSetButtonFirst(); }
|
||||
&:last-child { @include btnSetButtonLast(); }
|
||||
}
|
||||
|
||||
.last {
|
||||
.s-button,
|
||||
&.s-button {
|
||||
@include border-right-radius($controlCr);
|
||||
}
|
||||
}
|
||||
// Must use following due to DOM structure of action buttons,
|
||||
// which have structure like .l-btn-set > mct-representation class=first|last > .s-button
|
||||
.first > .s-button { @include btnSetButtonFirst(); }
|
||||
.last > .s-button { @include btnSetButtonLast(); }
|
||||
}
|
||||
|
||||
.paused {
|
||||
|
@ -273,6 +273,7 @@
|
||||
|
||||
.btn-bar.right .menu,
|
||||
.menus-to-left .menu {
|
||||
z-index: 79;
|
||||
left: auto;
|
||||
right: 0;
|
||||
width: auto;
|
||||
|
@ -409,16 +409,6 @@ define([
|
||||
]
|
||||
}
|
||||
],
|
||||
"roots": [
|
||||
{
|
||||
"id": "mine",
|
||||
"model": {
|
||||
"name": "My Items",
|
||||
"type": "folder",
|
||||
"composition": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": TransactingMutationListener,
|
||||
|
45
platform/features/my-items/bundle.js
Normal file
45
platform/features/my-items/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([
|
||||
'legacyRegistry'
|
||||
], function (
|
||||
legacyRegistry
|
||||
) {
|
||||
|
||||
legacyRegistry.register("platform/features/my-items", {
|
||||
"name": "My Items",
|
||||
"description": "Defines a root named My Items",
|
||||
"extensions": {
|
||||
"roots": [
|
||||
{
|
||||
"id": "mine",
|
||||
"model": {
|
||||
"name": "My Items",
|
||||
"type": "folder",
|
||||
"composition": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
@ -23,12 +23,12 @@
|
||||
class="abs holder holder-plot has-control-bar">
|
||||
<div class="l-control-bar" ng-show="!plot.hideExportButtons">
|
||||
<span class="l-btn-set">
|
||||
<a class="s-button t-export labeled"
|
||||
<a class="s-button t-export labeled icon-download"
|
||||
ng-click="plot.exportPNG()"
|
||||
title="Export This View's Data as PNG">
|
||||
PNG
|
||||
</a>
|
||||
<a class="s-button t-export labeled last"
|
||||
<a class="s-button t-export labeled"
|
||||
ng-click="plot.exportJPG()"
|
||||
title="Export This View's Data as JPG">
|
||||
JPG
|
||||
|
@ -128,6 +128,8 @@ define(
|
||||
latest[service] = name;
|
||||
|
||||
app.service(name, dependencies.concat([provider]));
|
||||
|
||||
$log.info("Registering provider for " + service);
|
||||
}
|
||||
|
||||
// Register an array of providers as a single dependency;
|
||||
@ -138,6 +140,13 @@ define(
|
||||
var name = makeName("provider", service, "*"),
|
||||
list = providerLists[service];
|
||||
|
||||
$log.info([
|
||||
"Compositing",
|
||||
list.length,
|
||||
"providers for",
|
||||
service
|
||||
].join(" "));
|
||||
|
||||
app.service(name, list.concat([echoMany]));
|
||||
});
|
||||
}
|
||||
|
@ -248,6 +248,13 @@ define([
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
this.types.listKeys().forEach(function (typeKey) {
|
||||
var type = this.types.get(typeKey);
|
||||
var legacyDefinition = type.toLegacyDefinition();
|
||||
legacyDefinition.key = typeKey;
|
||||
this.legacyExtension('types', legacyDefinition);
|
||||
}.bind(this));
|
||||
|
||||
legacyRegistry.register('adapter', this.legacyBundle);
|
||||
legacyRegistry.enable('adapter');
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@ define([
|
||||
'./actions/ActionDialogDecorator',
|
||||
'./directives/MCTView',
|
||||
'./services/Instantiate',
|
||||
'./services/MissingModelCompatibilityDecorator',
|
||||
'./capabilities/APICapabilityDecorator',
|
||||
'./policies/AdapterCompositionPolicy',
|
||||
'./runs/AlternateCompositionInitializer'
|
||||
@ -33,6 +34,7 @@ define([
|
||||
ActionDialogDecorator,
|
||||
MCTView,
|
||||
Instantiate,
|
||||
MissingModelCompatibilityDecorator,
|
||||
APICapabilityDecorator,
|
||||
AdapterCompositionPolicy,
|
||||
AlternateCompositionInitializer
|
||||
@ -75,6 +77,12 @@ define([
|
||||
provides: "actionService",
|
||||
implementation: ActionDialogDecorator,
|
||||
depends: ["openmct"]
|
||||
},
|
||||
{
|
||||
type: "decorator",
|
||||
provides: "modelService",
|
||||
implementation: MissingModelCompatibilityDecorator,
|
||||
depends: ["openmct"]
|
||||
}
|
||||
],
|
||||
policies: [
|
||||
|
@ -21,8 +21,8 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define([], function () {
|
||||
function AdapterCompositionPolicy(mct) {
|
||||
this.mct = mct;
|
||||
function AdapterCompositionPolicy(openmct) {
|
||||
this.openmct = openmct;
|
||||
}
|
||||
|
||||
AdapterCompositionPolicy.prototype.allow = function (
|
||||
@ -32,16 +32,10 @@ define([], function () {
|
||||
var containerObject = containerType.getInitialModel();
|
||||
var childObject = childType.getInitialModel();
|
||||
|
||||
containerObject.type = containerType.getKey();
|
||||
childObject.type = childType.getKey();
|
||||
|
||||
var composition = this.mct.Composition(containerObject);
|
||||
|
||||
if (composition) {
|
||||
return composition.canContain(childObject);
|
||||
}
|
||||
|
||||
return true;
|
||||
return this.openmct.composition.checkPolicy(
|
||||
containerObject,
|
||||
childObject
|
||||
);
|
||||
};
|
||||
|
||||
return AdapterCompositionPolicy;
|
||||
|
94
src/adapter/services/MissingModelCompatibilityDecorator.js
Normal file
94
src/adapter/services/MissingModelCompatibilityDecorator.js
Normal file
@ -0,0 +1,94 @@
|
||||
/*****************************************************************************
|
||||
* 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
|
||||
) {
|
||||
|
||||
/**
|
||||
* Compatibility decorator for New API.
|
||||
*
|
||||
* When the model service returns no results, this attempts to load
|
||||
* the model from the new Object API and returns that instead. In order
|
||||
* to prevent infinite recursion, this only tries to fetch from the API
|
||||
* a single time.
|
||||
*
|
||||
*/
|
||||
function MissingModelCompatibilityDecorator(api, modelService) {
|
||||
this.api = api;
|
||||
this.modelService = modelService;
|
||||
this.apiFetching = {}; // to prevent loops, if we have already
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a set of ids from the public api and return a promise for their
|
||||
* models. If a model is requested twice, respond with a missing result.
|
||||
*/
|
||||
MissingModelCompatibilityDecorator.prototype.apiFetch = function (ids) {
|
||||
var results = {},
|
||||
promises = ids.map(function (id) {
|
||||
if (this.apiFetching[id]) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.apiFetching[id] = true;
|
||||
|
||||
return this.api.objects.get(objectUtils.parseKeyString(id))
|
||||
.then(function (newDO) {
|
||||
results[id] = objectUtils.toOldFormat(newDO);
|
||||
});
|
||||
}, this);
|
||||
|
||||
return Promise.all(promises).then(function () {
|
||||
return results;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a promise for model results based on provided ids. Will attempt
|
||||
* to fetch any missing results from the object api.
|
||||
*/
|
||||
MissingModelCompatibilityDecorator.prototype.getModels = function (ids) {
|
||||
return this.modelService.getModels(ids)
|
||||
.then(function (models) {
|
||||
var missingIds = ids.filter(function (id) {
|
||||
return !models[id];
|
||||
});
|
||||
|
||||
if (!missingIds.length) {
|
||||
return models;
|
||||
}
|
||||
|
||||
return this.apiFetch(missingIds)
|
||||
.then(function (apiResults) {
|
||||
Object.keys(apiResults).forEach(function (k) {
|
||||
models[k] = apiResults[k];
|
||||
});
|
||||
return models;
|
||||
});
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
return MissingModelCompatibilityDecorator;
|
||||
});
|
||||
|
@ -21,7 +21,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'./Type',
|
||||
'./TimeConductor',
|
||||
'./objects/ObjectAPI',
|
||||
'./composition/CompositionAPI',
|
||||
@ -30,7 +29,6 @@ define([
|
||||
'./ui/GestureAPI',
|
||||
'./telemetry/TelemetryAPI'
|
||||
], function (
|
||||
Type,
|
||||
TimeConductor,
|
||||
ObjectAPI,
|
||||
CompositionAPI,
|
||||
@ -40,7 +38,6 @@ define([
|
||||
TelemetryAPI
|
||||
) {
|
||||
return {
|
||||
Type: Type,
|
||||
TimeConductor: TimeConductor,
|
||||
ObjectAPI: ObjectAPI,
|
||||
CompositionAPI: CompositionAPI,
|
||||
|
@ -23,11 +23,15 @@
|
||||
define([
|
||||
'lodash',
|
||||
'./object-utils',
|
||||
'./MutableObject'
|
||||
'./MutableObject',
|
||||
'./RootRegistry',
|
||||
'./RootObjectProvider'
|
||||
], function (
|
||||
_,
|
||||
utils,
|
||||
MutableObject
|
||||
MutableObject,
|
||||
RootRegistry,
|
||||
RootObjectProvider
|
||||
) {
|
||||
|
||||
|
||||
@ -35,21 +39,12 @@ define([
|
||||
* Utilities for loading, saving, and manipulating domain objects.
|
||||
* @interface ObjectAPI
|
||||
* @memberof module:openmct
|
||||
* @implements {module:openmct.ObjectProvider}
|
||||
*/
|
||||
|
||||
function ObjectAPI() {
|
||||
this.providers = {};
|
||||
this.rootRegistry = [];
|
||||
this.rootProvider = {
|
||||
'get': function () {
|
||||
return Promise.resolve({
|
||||
name: 'The root object',
|
||||
type: 'root',
|
||||
composition: this.rootRegistry
|
||||
});
|
||||
}.bind(this)
|
||||
};
|
||||
this.rootRegistry = new RootRegistry();
|
||||
this.rootProvider = new RootObjectProvider(this.rootRegistry);
|
||||
}
|
||||
|
||||
ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) {
|
||||
@ -57,13 +52,20 @@ define([
|
||||
};
|
||||
|
||||
// Retrieve the provider for a given key.
|
||||
ObjectAPI.prototype.getProvider = function (key) {
|
||||
if (key.identifier === 'ROOT') {
|
||||
ObjectAPI.prototype.getProvider = function (identifier) {
|
||||
if (identifier.key === 'ROOT') {
|
||||
return this.rootProvider;
|
||||
}
|
||||
return this.providers[key.namespace] || this.fallbackProvider;
|
||||
return this.providers[identifier.namespace] || this.fallbackProvider;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the root-level object.
|
||||
* @returns {Promise.<DomainObject>} a promise for the root object
|
||||
*/
|
||||
ObjectAPI.prototype.getRoot = function () {
|
||||
return this.rootProvider.get();
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new object provider for a particular namespace.
|
||||
@ -120,14 +122,25 @@ define([
|
||||
* has been saved, or be rejected if it cannot be saved
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a domain object.
|
||||
*
|
||||
* @method get
|
||||
* @memberof module:openmct.ObjectAPI#
|
||||
* @param {module:openmct.ObjectAPI~Identifier} identifier
|
||||
* the identifier 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) {
|
||||
ObjectAPI.prototype[method] = function () {
|
||||
var key = arguments[0],
|
||||
provider = this.getProvider(key);
|
||||
var identifier = arguments[0],
|
||||
provider = this.getProvider(identifier);
|
||||
|
||||
if (!provider) {
|
||||
throw new Error('No Provider Matched');
|
||||
@ -143,29 +156,14 @@ define([
|
||||
|
||||
/**
|
||||
* Add a root-level object.
|
||||
* @param {module:openmct.DomainObject} domainObject the root-level object
|
||||
* to add.
|
||||
* @param {module:openmct.ObjectAPI~Identifier|function} an array of
|
||||
* identifiers for root level objects, or a function that returns a
|
||||
* promise for an identifier or an array of root level objects.
|
||||
* @method addRoot
|
||||
* @memberof module:openmct.ObjectAPI#
|
||||
*/
|
||||
ObjectAPI.prototype.addRoot = function (key) {
|
||||
this.rootRegistry.unshift(key);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
});
|
||||
this.rootRegistry.addRoot(key);
|
||||
};
|
||||
|
||||
/**
|
||||
|
43
src/api/objects/RootObjectProvider.js
Normal file
43
src/api/objects/RootObjectProvider.js
Normal file
@ -0,0 +1,43 @@
|
||||
/*****************************************************************************
|
||||
* 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 RootObjectProvider(rootRegistry) {
|
||||
this.rootRegistry = rootRegistry;
|
||||
}
|
||||
|
||||
RootObjectProvider.prototype.get = function () {
|
||||
return this.rootRegistry.getRoots()
|
||||
.then(function (roots) {
|
||||
return {
|
||||
name: 'The root object',
|
||||
type: 'root',
|
||||
composition: roots
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return RootObjectProvider;
|
||||
});
|
57
src/api/objects/RootRegistry.js
Normal file
57
src/api/objects/RootRegistry.js
Normal file
@ -0,0 +1,57 @@
|
||||
/*****************************************************************************
|
||||
* 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'
|
||||
], function (
|
||||
_
|
||||
) {
|
||||
|
||||
function RootRegistry() {
|
||||
this.providers = [];
|
||||
}
|
||||
|
||||
RootRegistry.prototype.getRoots = function () {
|
||||
var promises = this.providers.map(function (provider) {
|
||||
return provider();
|
||||
});
|
||||
return Promise.all(promises)
|
||||
.then(_.flatten);
|
||||
};
|
||||
|
||||
function isKey(key) {
|
||||
return _.isObject(key) && _.has(key, 'key') && _.has(key, 'namespace');
|
||||
}
|
||||
|
||||
RootRegistry.prototype.addRoot = function (key) {
|
||||
if (isKey(key) || (_.isArray(key) && _.every(key, isKey))) {
|
||||
this.providers.push(function () {
|
||||
return key;
|
||||
});
|
||||
} else if (_.isFunction(key)) {
|
||||
this.providers.push(key);
|
||||
}
|
||||
};
|
||||
|
||||
return RootRegistry;
|
||||
|
||||
});
|
@ -28,50 +28,50 @@ define([
|
||||
|
||||
// take a key string and turn it into a key object
|
||||
// 'scratch:root' ==> {namespace: 'scratch', identifier: 'root'}
|
||||
var parseKeyString = function (key) {
|
||||
if (typeof key === 'object') {
|
||||
return key;
|
||||
var parseKeyString = function (identifier) {
|
||||
if (typeof identifier === 'object') {
|
||||
return identifier;
|
||||
}
|
||||
var namespace = '',
|
||||
identifier = key;
|
||||
key = identifier;
|
||||
for (var i = 0, escaped = false; i < key.length; i++) {
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
namespace += key[i];
|
||||
} else {
|
||||
if (key[i] === "\\") {
|
||||
if (identifier[i] === "\\") {
|
||||
escaped = true;
|
||||
} else if (key[i] === ":") {
|
||||
} else if (identifier[i] === ":") {
|
||||
// namespace = key.slice(0, i);
|
||||
identifier = key.slice(i + 1);
|
||||
key = identifier.slice(i + 1);
|
||||
break;
|
||||
}
|
||||
namespace += key[i];
|
||||
namespace += identifier[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (key === namespace) {
|
||||
if (identifier === namespace) {
|
||||
namespace = '';
|
||||
}
|
||||
|
||||
return {
|
||||
namespace: namespace,
|
||||
identifier: identifier
|
||||
key: key
|
||||
};
|
||||
};
|
||||
|
||||
// take a key and turn it into a key string
|
||||
// {namespace: 'scratch', identifier: 'root'} ==> 'scratch:root'
|
||||
var makeKeyString = function (key) {
|
||||
if (typeof key === 'string') {
|
||||
return key;
|
||||
var makeKeyString = function (identifier) {
|
||||
if (typeof identifier === 'string') {
|
||||
return identifier;
|
||||
}
|
||||
if (!key.namespace) {
|
||||
return key.identifier;
|
||||
if (!identifier.namespace) {
|
||||
return identifier.key;
|
||||
}
|
||||
return [
|
||||
key.namespace.replace(':', '\\:'),
|
||||
key.identifier.replace(':', '\\:')
|
||||
identifier.namespace.replace(':', '\\:'),
|
||||
identifier.key.replace(':', '\\:')
|
||||
].join(':');
|
||||
};
|
||||
|
||||
|
59
src/api/objects/test/RootObjectProviderSpec.js
Normal file
59
src/api/objects/test/RootObjectProviderSpec.js
Normal file
@ -0,0 +1,59 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'../RootObjectProvider'
|
||||
], function (
|
||||
RootObjectProvider
|
||||
) {
|
||||
describe('RootObjectProvider', function () {
|
||||
var rootRegistry,
|
||||
rootObjectProvider;
|
||||
|
||||
function done() {
|
||||
var isDone = false;
|
||||
waitsFor(function () {
|
||||
return isDone;
|
||||
});
|
||||
return function () {
|
||||
isDone = true;
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
rootRegistry = jasmine.createSpyObj('rootRegistry', ['getRoots']);
|
||||
rootRegistry.getRoots.andReturn(Promise.resolve(['some root']));
|
||||
rootObjectProvider = new RootObjectProvider(rootRegistry);
|
||||
});
|
||||
|
||||
it('supports fetching root', function () {
|
||||
rootObjectProvider.get()
|
||||
.then(function (root) {
|
||||
expect(root).toEqual({
|
||||
name: 'The root object',
|
||||
type: 'root',
|
||||
composition: ['some root']
|
||||
});
|
||||
})
|
||||
.then(done());
|
||||
});
|
||||
});
|
||||
});
|
102
src/api/objects/test/RootRegistrySpec.js
Normal file
102
src/api/objects/test/RootRegistrySpec.js
Normal file
@ -0,0 +1,102 @@
|
||||
/*****************************************************************************
|
||||
* 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([
|
||||
'../RootRegistry'
|
||||
], function (
|
||||
RootRegistry
|
||||
) {
|
||||
describe('RootRegistry', function () {
|
||||
var idA,
|
||||
idB,
|
||||
idC,
|
||||
registry;
|
||||
|
||||
function done() {
|
||||
var isDone = false;
|
||||
waitsFor(function () {
|
||||
return isDone;
|
||||
});
|
||||
return function () {
|
||||
isDone = true;
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
idA = {key: 'keyA', namespace: 'something'};
|
||||
idB = {key: 'keyB', namespace: 'something'};
|
||||
idC = {key: 'keyC', namespace: 'something'};
|
||||
registry = new RootRegistry();
|
||||
});
|
||||
|
||||
it('can register a root by key', function () {
|
||||
registry.addRoot(idA);
|
||||
registry.getRoots()
|
||||
.then(function (roots) {
|
||||
expect(roots).toEqual([idA]);
|
||||
})
|
||||
.then(done());
|
||||
});
|
||||
|
||||
it('can register multiple roots by key', function () {
|
||||
registry.addRoot([idA, idB]);
|
||||
registry.getRoots()
|
||||
.then(function (roots) {
|
||||
expect(roots).toEqual([idA, idB]);
|
||||
})
|
||||
.then(done());
|
||||
});
|
||||
|
||||
it('can register an asynchronous root ', function () {
|
||||
registry.addRoot(function () {
|
||||
return Promise.resolve(idA);
|
||||
});
|
||||
registry.getRoots()
|
||||
.then(function (roots) {
|
||||
expect(roots).toEqual([idA]);
|
||||
})
|
||||
.then(done());
|
||||
});
|
||||
|
||||
it('can register multiple asynchronous roots', function () {
|
||||
registry.addRoot(function () {
|
||||
return Promise.resolve([idA, idB]);
|
||||
});
|
||||
registry.getRoots()
|
||||
.then(function (roots) {
|
||||
expect(roots).toEqual([idA, idB]);
|
||||
})
|
||||
.then(done());
|
||||
});
|
||||
|
||||
it('can combine different types of registration', function () {
|
||||
registry.addRoot([idA, idB]);
|
||||
registry.addRoot(function () {
|
||||
return Promise.resolve([idC]);
|
||||
});
|
||||
registry.getRoots()
|
||||
.then(function (roots) {
|
||||
expect(roots).toEqual([idA, idB, idC]);
|
||||
})
|
||||
.then(done());
|
||||
});
|
||||
});
|
||||
});
|
@ -21,21 +21,12 @@
|
||||
*****************************************************************************/
|
||||
|
||||
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
|
||||
* @property {boolean} [creatable] true if users should be allowed to
|
||||
* create this type (default: false)
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Type describes a kind of domain object that may appear or be
|
||||
* created within Open MCT.
|
||||
*
|
||||
* @param {module:opemct.Type~TypeDefinition} definition
|
||||
* @param {module:opemct.TypeRegistry~TypeDefinition} definition
|
||||
* @class Type
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
@ -55,5 +46,29 @@ define(function () {
|
||||
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.label;
|
||||
def.cssclass = this.definition.cssclass;
|
||||
def.description = this.definition.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;
|
||||
});
|
@ -20,7 +20,18 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([], function () {
|
||||
define(['./Type'], function (Type) {
|
||||
/**
|
||||
* @typedef TypeDefinition
|
||||
* @memberof module:openmct.TypeRegistry~
|
||||
* @property {string} label the name for this type of object
|
||||
* @property {string} description a longer-form description of this type
|
||||
* @property {function (object)} [initialize] a function which initializes
|
||||
* the model for new domain objects of this type
|
||||
* @property {boolean} [creatable] true if users should be allowed to
|
||||
* create this type (default: false)
|
||||
* @property {string} [cssclass] the CSS class to apply for icons
|
||||
*/
|
||||
|
||||
/**
|
||||
* A TypeRegistry maintains the definitions for different types
|
||||
@ -37,13 +48,33 @@ define([], function () {
|
||||
*
|
||||
* @param {string} typeKey a string identifier for this type
|
||||
* @param {module:openmct.Type} type the type to add
|
||||
* @method addProvider
|
||||
* @method addType
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
*/
|
||||
TypeRegistry.prototype.addType = function (typeKey, type) {
|
||||
this.types[typeKey] = type;
|
||||
TypeRegistry.prototype.addType = function (typeKey, typeDef) {
|
||||
this.types[typeKey] = new Type(typeDef);
|
||||
};
|
||||
|
||||
/**
|
||||
* List keys for all registered types.
|
||||
* @method listKeys
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
* @returns {string[]} all registered type keys
|
||||
*/
|
||||
TypeRegistry.prototype.listKeys = function () {
|
||||
return Object.keys(this.types);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a registered type by its key.
|
||||
* @method get
|
||||
* @param {string} typeKey the key for htis type
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
* @returns {module:openmct.Type} the registered type
|
||||
*/
|
||||
TypeRegistry.prototype.get = function (typeKey) {
|
||||
return this.types[typeKey];
|
||||
};
|
||||
|
||||
return TypeRegistry;
|
||||
});
|
||||
|
@ -66,11 +66,13 @@ define([
|
||||
'../platform/exporters/bundle',
|
||||
'../platform/features/clock/bundle',
|
||||
'../platform/features/conductor/bundle',
|
||||
'../platform/features/fixed/bundle',
|
||||
'../platform/features/conductor-v2/conductor/bundle',
|
||||
'../platform/features/conductor-v2/compatibility/bundle',
|
||||
'../platform/features/conductor-v2/utcTimeSystem/bundle',
|
||||
'../platform/features/imagery/bundle',
|
||||
'../platform/features/layout/bundle',
|
||||
'../platform/features/my-items/bundle',
|
||||
'../platform/features/pages/bundle',
|
||||
'../platform/features/plot/bundle',
|
||||
'../platform/features/static-markup/bundle',
|
||||
@ -113,6 +115,7 @@ define([
|
||||
'platform/exporters',
|
||||
'platform/telemetry',
|
||||
'platform/features/clock',
|
||||
'platform/features/fixed',
|
||||
'platform/features/imagery',
|
||||
'platform/features/layout',
|
||||
'platform/features/pages',
|
||||
|
Loading…
x
Reference in New Issue
Block a user