diff --git a/API.md b/API.md index fff93ef2d7..24083e1cf6 100644 --- a/API.md +++ b/API.md @@ -118,11 +118,18 @@ To do so, use the [`addRoot`]{@link module:openmct.ObjectAPI#addRoot} method of the [object API]{@link module:openmct.ObjectAPI}: ``` -openmct.objects.addRoot({ key: "my-key", namespace: "my-namespace" }); +openmct.objects.addRoot({ + identifier: { key: "my-key", namespace: "my-namespace" } + name: "My Root-level Object", + type: "my-type" +}); ``` -Root objects are loaded just like any other objects, i.e. via an object -provider. +You can also remove this root-level object via its identifier: + +``` +openmct.objects.removeRoot({ key: "my-key", namespace: "my-namespace" }); +``` ### Adding Composition Providers diff --git a/index.html b/index.html index b6b1715116..aa5d79cfdc 100644 --- a/index.html +++ b/index.html @@ -32,8 +32,7 @@ [ 'example/imagery', 'example/eventGenerator', - 'example/generator', - 'platform/features/my-items' + 'example/generator' ].forEach( openmct.legacyRegistry.enable.bind(openmct.legacyRegistry) ); diff --git a/platform/core/bundle.js b/platform/core/bundle.js index 93b64f5739..26a49e16d9 100644 --- a/platform/core/bundle.js +++ b/platform/core/bundle.js @@ -409,6 +409,16 @@ define([ ] } ], + "roots": [ + { + "id": "mine", + "model": { + "name": "My Items", + "type": "folder", + "composition": [] + } + } + ], "runs": [ { "implementation": TransactingMutationListener, diff --git a/platform/features/my-items/bundle.js b/platform/features/my-items/bundle.js deleted file mode 100644 index 42b66ad3b4..0000000000 --- a/platform/features/my-items/bundle.js +++ /dev/null @@ -1,45 +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. - *****************************************************************************/ - -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": [] - } - } - ] - } - }); -}); diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index 6b68e075d0..eb67c7adbd 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -23,15 +23,11 @@ define([ 'lodash', './object-utils', - './MutableObject', - './RootRegistry', - './RootObjectProvider' + './MutableObject' ], function ( _, utils, - MutableObject, - RootRegistry, - RootObjectProvider + MutableObject ) { @@ -44,8 +40,16 @@ define([ function ObjectAPI() { this.providers = {}; - this.rootRegistry = new RootRegistry(); - this.rootProvider = new RootObjectProvider(this.rootRegistry); + this.rootRegistry = []; + this.rootProvider = { + 'get': function () { + return Promise.resolve({ + name: 'The root object', + type: 'root', + composition: this.rootRegistry + }); + }.bind(this) + }; } ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) { @@ -139,14 +143,29 @@ define([ /** * Add a root-level object. - * @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. + * @param {module:openmct.DomainObject} domainObject the root-level object + * to add. * @method addRoot * @memberof module:openmct.ObjectAPI# */ ObjectAPI.prototype.addRoot = function (key) { - this.rootRegistry.addRoot(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 + ); + }); }; /** diff --git a/src/api/objects/RootObjectProvider.js b/src/api/objects/RootObjectProvider.js deleted file mode 100644 index 4b44d66f9c..0000000000 --- a/src/api/objects/RootObjectProvider.js +++ /dev/null @@ -1,43 +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. - *****************************************************************************/ - -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; -}); diff --git a/src/api/objects/RootRegistry.js b/src/api/objects/RootRegistry.js deleted file mode 100644 index 2e04d83410..0000000000 --- a/src/api/objects/RootRegistry.js +++ /dev/null @@ -1,57 +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. - *****************************************************************************/ - -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; - -}); diff --git a/src/api/objects/test/RootObjectProviderSpec.js b/src/api/objects/test/RootObjectProviderSpec.js deleted file mode 100644 index 2734c2e55f..0000000000 --- a/src/api/objects/test/RootObjectProviderSpec.js +++ /dev/null @@ -1,59 +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. - *****************************************************************************/ -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()); - }); - }); -}); diff --git a/src/api/objects/test/RootRegistrySpec.js b/src/api/objects/test/RootRegistrySpec.js deleted file mode 100644 index 4f918b9eb0..0000000000 --- a/src/api/objects/test/RootRegistrySpec.js +++ /dev/null @@ -1,102 +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. - *****************************************************************************/ -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()); - }); - }); -}); diff --git a/src/defaultRegistry.js b/src/defaultRegistry.js index 485caacca9..a4070313dc 100644 --- a/src/defaultRegistry.js +++ b/src/defaultRegistry.js @@ -72,7 +72,6 @@ define([ '../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',