From 6d2c5f7fd44f03bca62fa0faf0bb2d9e5e705a7a Mon Sep 17 00:00:00 2001 From: tylerbrewer2 Date: Thu, 6 Oct 2016 18:17:36 -0400 Subject: [PATCH 01/35] [Frontend] Ensure stacking order of save drop-down Fixes #1205 --- platform/commonUI/general/res/sass/controls/_menus.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/commonUI/general/res/sass/controls/_menus.scss b/platform/commonUI/general/res/sass/controls/_menus.scss index 61e87b5b2b..605eb71e93 100644 --- a/platform/commonUI/general/res/sass/controls/_menus.scss +++ b/platform/commonUI/general/res/sass/controls/_menus.scss @@ -258,6 +258,7 @@ .btn-bar.right .menu, .menus-to-left .menu { + z-index: 79; left: auto; right: 0; width: auto; From 137434af1b598915ff914e1d07ab54db658179cf Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 12 Oct 2016 14:06:39 -0700 Subject: [PATCH 02/35] [API] Enable fixed position view --- src/defaultRegistry.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/defaultRegistry.js b/src/defaultRegistry.js index e75b513a3c..6176d72fea 100644 --- a/src/defaultRegistry.js +++ b/src/defaultRegistry.js @@ -65,6 +65,7 @@ define([ '../platform/exporters/bundle', '../platform/features/clock/bundle', '../platform/features/conductor/bundle', + '../platform/features/fixed/bundle', '../platform/features/imagery/bundle', '../platform/features/layout/bundle', '../platform/features/pages/bundle', @@ -109,6 +110,7 @@ define([ 'platform/exporters', 'platform/telemetry', 'platform/features/clock', + 'platform/features/fixed', 'platform/features/imagery', 'platform/features/layout', 'platform/features/pages', From 1947802a35e1294d48c1587e776818dc79627ccd Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 13 Oct 2016 17:59:31 -0700 Subject: [PATCH 03/35] [ObjectAPI] support async root loading Overload addRoot method to support async root loading. By supplying a function you can defer loading to later, and by allowing those functions to return a promise, execution can be asynchronous. Remove "removeRoot" as the assumption will be that roots are opt in, and instead of removing a Root, an application developer should never configure it in the first place. Fixes https://github.com/nasa/openmct/issues/1251 --- src/api/objects/ObjectAPI.js | 44 ++++++++++-------------- src/api/objects/RootRegistry.js | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 src/api/objects/RootRegistry.js diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index eb67c7adbd..697716b3be 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -23,11 +23,13 @@ define([ 'lodash', './object-utils', - './MutableObject' + './MutableObject', + './RootRegistry' ], function ( _, utils, - MutableObject + MutableObject, + RootRegistry ) { @@ -40,14 +42,17 @@ define([ function ObjectAPI() { this.providers = {}; - this.rootRegistry = []; + this.rootRegistry = new RootRegistry(); this.rootProvider = { 'get': function () { - return Promise.resolve({ - name: 'The root object', - type: 'root', - composition: this.rootRegistry - }); + return this.rootRegistry.getRoots() + .then(function (roots) { + return { + name: 'The root object', + type: 'root', + composition: roots + }; + }); }.bind(this) }; } @@ -143,29 +148,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); }; /** diff --git a/src/api/objects/RootRegistry.js b/src/api/objects/RootRegistry.js new file mode 100644 index 0000000000..b2971be176 --- /dev/null +++ b/src/api/objects/RootRegistry.js @@ -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([ + '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); + }; + + + RootRegistry.prototype.addRoot = function (key) { + if (_.isObject(key) && _.has(key, 'identifier') && _.has(key, 'namespace')) { + this.providers.push(function () { + return Promise.resolve(key); + }); + } else if (_.isFunction(key)) { + this.providers.push(key); + } + }; + + // Assume no one ever removes a root. everything is opt in. + RootRegistry.prototype.removeRoot = function (key) { + throw new Error('you should never remove a root'); + }; + + return RootRegistry; + +}); From 891412bdb91297afff15a924c9c8f6081be1c42e Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 13 Oct 2016 18:04:37 -0700 Subject: [PATCH 04/35] [Roots] Move my-items to separate bundle My Items root is now opt-in, and does not need to be enabled for all deployments. My Items is enabled by default in the development edition. https://github.com/nasa/openmct/issues/1251 --- index.html | 3 +- platform/core/bundle.js | 10 ------- platform/features/my-items/bundle.js | 45 ++++++++++++++++++++++++++++ src/defaultRegistry.js | 1 + 4 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 platform/features/my-items/bundle.js diff --git a/index.html b/index.html index aa5d79cfdc..b6b1715116 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,8 @@ [ 'example/imagery', 'example/eventGenerator', - 'example/generator' + 'example/generator', + 'platform/features/my-items' ].forEach( openmct.legacyRegistry.enable.bind(openmct.legacyRegistry) ); diff --git a/platform/core/bundle.js b/platform/core/bundle.js index 26a49e16d9..93b64f5739 100644 --- a/platform/core/bundle.js +++ b/platform/core/bundle.js @@ -409,16 +409,6 @@ 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 new file mode 100644 index 0000000000..42b66ad3b4 --- /dev/null +++ b/platform/features/my-items/bundle.js @@ -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": [] + } + } + ] + } + }); +}); diff --git a/src/defaultRegistry.js b/src/defaultRegistry.js index efabce4d97..910dc8b94a 100644 --- a/src/defaultRegistry.js +++ b/src/defaultRegistry.js @@ -71,6 +71,7 @@ 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', From 6ec858b237a9422d1cd50e7fa1603add17de07d8 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 14 Oct 2016 12:37:03 -0700 Subject: [PATCH 05/35] [Docs] Update root registration in README. https://github.com/nasa/openmct/issues/1251 --- API.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/API.md b/API.md index 24083e1cf6..fff93ef2d7 100644 --- a/API.md +++ b/API.md @@ -118,18 +118,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 From b0940eb33ee479ea036a18fa6e23f20bf363bb98 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 14 Oct 2016 12:47:09 -0700 Subject: [PATCH 06/35] [Objects] refactor out RootObjectProvider Refactor RootObjectProvider to separate file for simplicty. https://github.com/nasa/openmct/issues/1251 --- src/api/objects/ObjectAPI.js | 19 ++++-------- src/api/objects/RootObjectProvider.js | 43 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 src/api/objects/RootObjectProvider.js diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index 697716b3be..6b68e075d0 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -24,12 +24,14 @@ define([ 'lodash', './object-utils', './MutableObject', - './RootRegistry' + './RootRegistry', + './RootObjectProvider' ], function ( _, utils, MutableObject, - RootRegistry + RootRegistry, + RootObjectProvider ) { @@ -43,18 +45,7 @@ define([ function ObjectAPI() { this.providers = {}; this.rootRegistry = new RootRegistry(); - this.rootProvider = { - 'get': function () { - return this.rootRegistry.getRoots() - .then(function (roots) { - return { - name: 'The root object', - type: 'root', - composition: roots - }; - }); - }.bind(this) - }; + this.rootProvider = new RootObjectProvider(this.rootRegistry); } ObjectAPI.prototype.supersecretSetFallbackProvider = function (p) { diff --git a/src/api/objects/RootObjectProvider.js b/src/api/objects/RootObjectProvider.js new file mode 100644 index 0000000000..fce0d26704 --- /dev/null +++ b/src/api/objects/RootObjectProvider.js @@ -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; +}); From 08c0aeb2d5e320f781ef125217d580df602e3c09 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 14 Oct 2016 13:12:45 -0700 Subject: [PATCH 07/35] [Test] Add tests for root registration Add unit tests for RootRegistry and RootObjectProvider. https://github.com/nasa/openmct/issues/1251 --- src/api/objects/RootObjectProvider.js | 2 +- src/api/objects/RootRegistry.js | 7 +- .../objects/test/RootObjectProviderSpec.js | 59 ++++++++++ src/api/objects/test/RootRegistrySpec.js | 102 ++++++++++++++++++ 4 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 src/api/objects/test/RootObjectProviderSpec.js create mode 100644 src/api/objects/test/RootRegistrySpec.js diff --git a/src/api/objects/RootObjectProvider.js b/src/api/objects/RootObjectProvider.js index fce0d26704..4b44d66f9c 100644 --- a/src/api/objects/RootObjectProvider.js +++ b/src/api/objects/RootObjectProvider.js @@ -37,7 +37,7 @@ define([ composition: roots }; }); - } + }; return RootObjectProvider; }); diff --git a/src/api/objects/RootRegistry.js b/src/api/objects/RootRegistry.js index b2971be176..cb0ff5d167 100644 --- a/src/api/objects/RootRegistry.js +++ b/src/api/objects/RootRegistry.js @@ -38,11 +38,14 @@ define([ .then(_.flatten); }; + function isKey(key) { + return _.isObject(key) && _.has(key, 'key') && _.has(key, 'namespace'); + } RootRegistry.prototype.addRoot = function (key) { - if (_.isObject(key) && _.has(key, 'identifier') && _.has(key, 'namespace')) { + if (isKey(key) || (_.isArray(key) && _.every(key, isKey))) { this.providers.push(function () { - return Promise.resolve(key); + return key; }); } else if (_.isFunction(key)) { this.providers.push(key); diff --git a/src/api/objects/test/RootObjectProviderSpec.js b/src/api/objects/test/RootObjectProviderSpec.js new file mode 100644 index 0000000000..2734c2e55f --- /dev/null +++ b/src/api/objects/test/RootObjectProviderSpec.js @@ -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()); + }); + }); +}); diff --git a/src/api/objects/test/RootRegistrySpec.js b/src/api/objects/test/RootRegistrySpec.js new file mode 100644 index 0000000000..4f918b9eb0 --- /dev/null +++ b/src/api/objects/test/RootRegistrySpec.js @@ -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()); + }); + }); +}); From d643efa9bbc150a33e9a5d471c6921c4f3589852 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 14 Oct 2016 13:16:00 -0700 Subject: [PATCH 08/35] [Style] Remove unused function https://github.com/nasa/openmct/issues/1251 --- src/api/objects/RootRegistry.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/api/objects/RootRegistry.js b/src/api/objects/RootRegistry.js index cb0ff5d167..2e04d83410 100644 --- a/src/api/objects/RootRegistry.js +++ b/src/api/objects/RootRegistry.js @@ -52,11 +52,6 @@ define([ } }; - // Assume no one ever removes a root. everything is opt in. - RootRegistry.prototype.removeRoot = function (key) { - throw new Error('you should never remove a root'); - }; - return RootRegistry; }); From b8cb41b1daedaf8d553a3eb40dd44cd3afbc45c7 Mon Sep 17 00:00:00 2001 From: Charles Hacskaylo Date: Fri, 14 Oct 2016 16:53:00 -0700 Subject: [PATCH 09/35] [Frontend] Fixes to export buttons Fixes #1235 Sass and markup mods; changes to .l-btn-set and related classes --- .../general/res/sass/controls/_buttons.scss | 30 +++++++++++-------- .../features/plot/res/templates/plot.html | 4 +-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/platform/commonUI/general/res/sass/controls/_buttons.scss b/platform/commonUI/general/res/sass/controls/_buttons.scss index 17e03941df..fe2c6d660c 100644 --- a/platform/commonUI/general/res/sass/controls/_buttons.scss +++ b/platform/commonUI/general/res/sass/controls/_buttons.scss @@ -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 { diff --git a/platform/features/plot/res/templates/plot.html b/platform/features/plot/res/templates/plot.html index 461389e2c1..53b5d348b0 100644 --- a/platform/features/plot/res/templates/plot.html +++ b/platform/features/plot/res/templates/plot.html @@ -23,12 +23,12 @@ class="abs holder holder-plot has-control-bar">
- PNG - JPG From 0759ba6722d966e5c2144ee4e6c1a1f46021ce78 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 17 Oct 2016 10:43:12 -0700 Subject: [PATCH 10/35] [Composition] Fix adapter composition policy ...as this had fallen out-of-date with existing APIs. Fixes #1257. --- .../policies/AdapterCompositionPolicy.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/adapter/policies/AdapterCompositionPolicy.js b/src/adapter/policies/AdapterCompositionPolicy.js index 50e9312d54..865b08cb59 100644 --- a/src/adapter/policies/AdapterCompositionPolicy.js +++ b/src/adapter/policies/AdapterCompositionPolicy.js @@ -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; From 4eca80a770d9bcd18432bba71e5db4a1526a7f81 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 18 Oct 2016 10:48:26 -0700 Subject: [PATCH 11/35] Revert "Async root registration" --- API.md | 13 ++- index.html | 3 +- platform/core/bundle.js | 10 ++ platform/features/my-items/bundle.js | 45 -------- src/api/objects/ObjectAPI.js | 43 +++++--- src/api/objects/RootObjectProvider.js | 43 -------- src/api/objects/RootRegistry.js | 57 ---------- .../objects/test/RootObjectProviderSpec.js | 59 ---------- src/api/objects/test/RootRegistrySpec.js | 102 ------------------ src/defaultRegistry.js | 1 - 10 files changed, 52 insertions(+), 324 deletions(-) delete mode 100644 platform/features/my-items/bundle.js delete mode 100644 src/api/objects/RootObjectProvider.js delete mode 100644 src/api/objects/RootRegistry.js delete mode 100644 src/api/objects/test/RootObjectProviderSpec.js delete mode 100644 src/api/objects/test/RootRegistrySpec.js 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', From 64ff4632009d22f9cd7a49c446443f5c4a8ba180 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 14:55:07 -0700 Subject: [PATCH 12/35] Revert "Revert "Async root registration"" --- API.md | 13 +-- index.html | 3 +- platform/core/bundle.js | 10 -- platform/features/my-items/bundle.js | 45 ++++++++ src/api/objects/ObjectAPI.js | 43 +++----- src/api/objects/RootObjectProvider.js | 43 ++++++++ src/api/objects/RootRegistry.js | 57 ++++++++++ .../objects/test/RootObjectProviderSpec.js | 59 ++++++++++ src/api/objects/test/RootRegistrySpec.js | 102 ++++++++++++++++++ src/defaultRegistry.js | 1 + 10 files changed, 324 insertions(+), 52 deletions(-) create mode 100644 platform/features/my-items/bundle.js create mode 100644 src/api/objects/RootObjectProvider.js create mode 100644 src/api/objects/RootRegistry.js create mode 100644 src/api/objects/test/RootObjectProviderSpec.js create mode 100644 src/api/objects/test/RootRegistrySpec.js diff --git a/API.md b/API.md index 24083e1cf6..fff93ef2d7 100644 --- a/API.md +++ b/API.md @@ -118,18 +118,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 diff --git a/index.html b/index.html index aa5d79cfdc..b6b1715116 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,8 @@ [ 'example/imagery', 'example/eventGenerator', - 'example/generator' + 'example/generator', + 'platform/features/my-items' ].forEach( openmct.legacyRegistry.enable.bind(openmct.legacyRegistry) ); diff --git a/platform/core/bundle.js b/platform/core/bundle.js index 26a49e16d9..93b64f5739 100644 --- a/platform/core/bundle.js +++ b/platform/core/bundle.js @@ -409,16 +409,6 @@ 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 new file mode 100644 index 0000000000..42b66ad3b4 --- /dev/null +++ b/platform/features/my-items/bundle.js @@ -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": [] + } + } + ] + } + }); +}); diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index eb67c7adbd..6b68e075d0 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -23,11 +23,15 @@ define([ 'lodash', './object-utils', - './MutableObject' + './MutableObject', + './RootRegistry', + './RootObjectProvider' ], function ( _, utils, - MutableObject + MutableObject, + RootRegistry, + RootObjectProvider ) { @@ -40,16 +44,8 @@ define([ 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) { @@ -143,29 +139,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); }; /** diff --git a/src/api/objects/RootObjectProvider.js b/src/api/objects/RootObjectProvider.js new file mode 100644 index 0000000000..4b44d66f9c --- /dev/null +++ b/src/api/objects/RootObjectProvider.js @@ -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; +}); diff --git a/src/api/objects/RootRegistry.js b/src/api/objects/RootRegistry.js new file mode 100644 index 0000000000..2e04d83410 --- /dev/null +++ b/src/api/objects/RootRegistry.js @@ -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; + +}); diff --git a/src/api/objects/test/RootObjectProviderSpec.js b/src/api/objects/test/RootObjectProviderSpec.js new file mode 100644 index 0000000000..2734c2e55f --- /dev/null +++ b/src/api/objects/test/RootObjectProviderSpec.js @@ -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()); + }); + }); +}); diff --git a/src/api/objects/test/RootRegistrySpec.js b/src/api/objects/test/RootRegistrySpec.js new file mode 100644 index 0000000000..4f918b9eb0 --- /dev/null +++ b/src/api/objects/test/RootRegistrySpec.js @@ -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()); + }); + }); +}); diff --git a/src/defaultRegistry.js b/src/defaultRegistry.js index a4070313dc..485caacca9 100644 --- a/src/defaultRegistry.js +++ b/src/defaultRegistry.js @@ -72,6 +72,7 @@ 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', From a143b21ea16add9328a58624ebe64cc3e9a6bcb9 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 14:43:04 -0700 Subject: [PATCH 13/35] [Roots] Register roots with new API Register roots added via old API with new API when the application starts. Fixes #1264. --- src/adapter/bundle.js | 10 ++++-- src/adapter/runs/RootRegistrar.js | 32 ++++++++++++++++++ src/adapter/runs/RootRegistrarSpec.js | 47 +++++++++++++++++++++++++++ src/api/objects/object-utils.js | 34 +++++++++---------- 4 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 src/adapter/runs/RootRegistrar.js create mode 100644 src/adapter/runs/RootRegistrarSpec.js diff --git a/src/adapter/bundle.js b/src/adapter/bundle.js index 0e2a4cf304..bdb6ed0ab3 100644 --- a/src/adapter/bundle.js +++ b/src/adapter/bundle.js @@ -27,7 +27,8 @@ define([ './services/Instantiate', './capabilities/APICapabilityDecorator', './policies/AdapterCompositionPolicy', - './runs/AlternateCompositionInitializer' + './runs/AlternateCompositionInitializer', + './runs/RootRegistrar' ], function ( legacyRegistry, ActionDialogDecorator, @@ -35,7 +36,8 @@ define([ Instantiate, APICapabilityDecorator, AdapterCompositionPolicy, - AlternateCompositionInitializer + AlternateCompositionInitializer, + RootRegistrar ) { legacyRegistry.register('src/adapter', { "extensions": { @@ -88,6 +90,10 @@ define([ { implementation: AlternateCompositionInitializer, depends: ["openmct"] + }, + { + implementation: RootRegistrar, + depends: ["openmct", "roots[]"] } ], licenses: [ diff --git a/src/adapter/runs/RootRegistrar.js b/src/adapter/runs/RootRegistrar.js new file mode 100644 index 0000000000..5ea828ccad --- /dev/null +++ b/src/adapter/runs/RootRegistrar.js @@ -0,0 +1,32 @@ +/***************************************************************************** + * 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(['../../api/objects/object-utils', 'lodash'], function (utils, _) { + function RootRegistrar(openmct, roots) { + _.map(roots, 'id').map(utils.parseKeyString) + .forEach(function (identifier) { + openmct.objects.addRoot(identifier); + }); + } + + return RootRegistrar; +}); diff --git a/src/adapter/runs/RootRegistrarSpec.js b/src/adapter/runs/RootRegistrarSpec.js new file mode 100644 index 0000000000..96e14be154 --- /dev/null +++ b/src/adapter/runs/RootRegistrarSpec.js @@ -0,0 +1,47 @@ +/***************************************************************************** + * 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(['./RootRegistrar'], function (RootRegistrar) { + describe("RootRegistrar", function () { + var openmct, + roots; + + beforeEach(function () { + roots = ['a:a', 'a:b', 'x:c'].map(function (id) { + return { id: id, model: { name: "My root " + id } }; + }); + openmct = { + objects: jasmine.createSpyObj('objects', ['addRoot']) + }; + return new RootRegistrar(openmct, roots); + }); + + it("adds legacy root extensions using ObjectAPI", function () { + expect(openmct.objects.addRoot) + .toHaveBeenCalledWith({ key: 'a', namespace: 'a' }); + expect(openmct.objects.addRoot) + .toHaveBeenCalledWith({ key: 'b', namespace: 'a' }); + expect(openmct.objects.addRoot) + .toHaveBeenCalledWith({ key: 'c', namespace: 'x' }); + }); + }); +}); diff --git a/src/api/objects/object-utils.js b/src/api/objects/object-utils.js index f749a8110b..9c37b72911 100644 --- a/src/api/objects/object-utils.js +++ b/src/api/objects/object-utils.js @@ -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(':'); }; From a3847bcca515041794d409edec371b76ee2b8fdb Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:18:50 -0700 Subject: [PATCH 14/35] [Roots] Add useful logging for components --- platform/framework/src/register/ServiceCompositor.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platform/framework/src/register/ServiceCompositor.js b/platform/framework/src/register/ServiceCompositor.js index 7b7f6911da..3c089c6e5a 100644 --- a/platform/framework/src/register/ServiceCompositor.js +++ b/platform/framework/src/register/ServiceCompositor.js @@ -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])); }); } From 7b0506bbdb42f3ff49cfcc4f5ad81a7f00ef2b0e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:19:11 -0700 Subject: [PATCH 15/35] [Roots] Remove legacy root model provider --- platform/core/bundle.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/platform/core/bundle.js b/platform/core/bundle.js index 93b64f5739..55879265c7 100644 --- a/platform/core/bundle.js +++ b/platform/core/bundle.js @@ -24,7 +24,6 @@ define([ "./src/objects/DomainObjectProvider", "./src/capabilities/CoreCapabilityProvider", "./src/models/StaticModelProvider", - "./src/models/RootModelProvider", "./src/models/ModelAggregator", "./src/models/ModelCacheService", "./src/models/PersistedModelProvider", @@ -57,7 +56,6 @@ define([ DomainObjectProvider, CoreCapabilityProvider, StaticModelProvider, - RootModelProvider, ModelAggregator, ModelCacheService, PersistedModelProvider, @@ -152,16 +150,6 @@ define([ "$log" ] }, - { - "provides": "modelService", - "type": "provider", - "implementation": RootModelProvider, - "depends": [ - "roots[]", - "$q", - "$log" - ] - }, { "provides": "modelService", "type": "aggregator", From 650824574c70cdf24d93b597fbb4766b11528541 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:20:02 -0700 Subject: [PATCH 16/35] [Roots] Add new root model provider ...to read roots from the new API's registry. --- src/adapter/bundle.js | 12 ++++-- .../components/NewRootModelProvider.js | 37 +++++++++++++++++++ src/api/objects/ObjectAPI.js | 7 ++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/adapter/components/NewRootModelProvider.js diff --git a/src/adapter/bundle.js b/src/adapter/bundle.js index bdb6ed0ab3..d5641c80d0 100644 --- a/src/adapter/bundle.js +++ b/src/adapter/bundle.js @@ -23,6 +23,7 @@ define([ 'legacyRegistry', './actions/ActionDialogDecorator', + './components/NewRootModelProvider', './directives/MCTView', './services/Instantiate', './capabilities/APICapabilityDecorator', @@ -32,6 +33,7 @@ define([ ], function ( legacyRegistry, ActionDialogDecorator, + NewRootModelProvider, MCTView, Instantiate, APICapabilityDecorator, @@ -77,6 +79,12 @@ define([ provides: "actionService", implementation: ActionDialogDecorator, depends: ["openmct"] + }, + { + "provides": "modelService", + "type": "provider", + "implementation": NewRootModelProvider, + "depends": ["openmct"] } ], policies: [ @@ -90,10 +98,6 @@ define([ { implementation: AlternateCompositionInitializer, depends: ["openmct"] - }, - { - implementation: RootRegistrar, - depends: ["openmct", "roots[]"] } ], licenses: [ diff --git a/src/adapter/components/NewRootModelProvider.js b/src/adapter/components/NewRootModelProvider.js new file mode 100644 index 0000000000..1de0363622 --- /dev/null +++ b/src/adapter/components/NewRootModelProvider.js @@ -0,0 +1,37 @@ +/***************************************************************************** + * 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(['../../api/objects/object-utils'], function (utils) { + function NewRootModelProvider(openmct) { + this.openmct = openmct; + } + + NewRootModelProvider.prototype.getModels = function (ids) { + return this.openmct.objects.getRoot().then(function (root) { + return { + ROOT: utils.toOldFormat(root) + }; + }); + }; + + return NewRootModelProvider; +}); diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index 6b68e075d0..9dfe31b589 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -60,6 +60,13 @@ define([ return this.providers[key.namespace] || this.fallbackProvider; }; + /** + * Get the root-level object. + * @returns {Promise.} a promise for the root object + */ + ObjectAPI.prototype.getRoot = function () { + return this.rootProvider.get(); + }; /** * Register a new object provider for a particular namespace. From 2a798134604738a606df43d5469714842b78fa87 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:20:59 -0700 Subject: [PATCH 17/35] [Roots] Remove unnecessary RootRegistrar --- src/adapter/bundle.js | 6 ++-- src/adapter/runs/RootRegistrar.js | 32 ------------------ src/adapter/runs/RootRegistrarSpec.js | 47 --------------------------- 3 files changed, 2 insertions(+), 83 deletions(-) delete mode 100644 src/adapter/runs/RootRegistrar.js delete mode 100644 src/adapter/runs/RootRegistrarSpec.js diff --git a/src/adapter/bundle.js b/src/adapter/bundle.js index d5641c80d0..d0a93abd4d 100644 --- a/src/adapter/bundle.js +++ b/src/adapter/bundle.js @@ -28,8 +28,7 @@ define([ './services/Instantiate', './capabilities/APICapabilityDecorator', './policies/AdapterCompositionPolicy', - './runs/AlternateCompositionInitializer', - './runs/RootRegistrar' + './runs/AlternateCompositionInitializer' ], function ( legacyRegistry, ActionDialogDecorator, @@ -38,8 +37,7 @@ define([ Instantiate, APICapabilityDecorator, AdapterCompositionPolicy, - AlternateCompositionInitializer, - RootRegistrar + AlternateCompositionInitializer ) { legacyRegistry.register('src/adapter', { "extensions": { diff --git a/src/adapter/runs/RootRegistrar.js b/src/adapter/runs/RootRegistrar.js deleted file mode 100644 index 5ea828ccad..0000000000 --- a/src/adapter/runs/RootRegistrar.js +++ /dev/null @@ -1,32 +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 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(['../../api/objects/object-utils', 'lodash'], function (utils, _) { - function RootRegistrar(openmct, roots) { - _.map(roots, 'id').map(utils.parseKeyString) - .forEach(function (identifier) { - openmct.objects.addRoot(identifier); - }); - } - - return RootRegistrar; -}); diff --git a/src/adapter/runs/RootRegistrarSpec.js b/src/adapter/runs/RootRegistrarSpec.js deleted file mode 100644 index 96e14be154..0000000000 --- a/src/adapter/runs/RootRegistrarSpec.js +++ /dev/null @@ -1,47 +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 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(['./RootRegistrar'], function (RootRegistrar) { - describe("RootRegistrar", function () { - var openmct, - roots; - - beforeEach(function () { - roots = ['a:a', 'a:b', 'x:c'].map(function (id) { - return { id: id, model: { name: "My root " + id } }; - }); - openmct = { - objects: jasmine.createSpyObj('objects', ['addRoot']) - }; - return new RootRegistrar(openmct, roots); - }); - - it("adds legacy root extensions using ObjectAPI", function () { - expect(openmct.objects.addRoot) - .toHaveBeenCalledWith({ key: 'a', namespace: 'a' }); - expect(openmct.objects.addRoot) - .toHaveBeenCalledWith({ key: 'b', namespace: 'a' }); - expect(openmct.objects.addRoot) - .toHaveBeenCalledWith({ key: 'c', namespace: 'x' }); - }); - }); -}); From 3f50bdb334bf67a9e1ae264725747dce8924591b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:47:11 -0700 Subject: [PATCH 18/35] [Roots] Distinguish objects.get ...which needs to accept full identifiers from namespace-specific object providers, which only need to accept keys. --- src/api/objects/ObjectAPI.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index 9dfe31b589..05b5caf657 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -39,7 +39,6 @@ define([ * Utilities for loading, saving, and manipulating domain objects. * @interface ObjectAPI * @memberof module:openmct - * @implements {module:openmct.ObjectProvider} */ function ObjectAPI() { @@ -53,11 +52,11 @@ 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; }; /** @@ -123,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'); @@ -140,6 +150,10 @@ define([ throw new Error('Provider does not support [' + method + '].'); } + if (method === 'get') { + return provider.get(identifier.key); + } + return provider[method].apply(provider, arguments); }; }); From f6253ae7ed8779bb803d714a839e17f57f485228 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:53:03 -0700 Subject: [PATCH 19/35] [Roots] Remove unnecessary model provider --- src/adapter/bundle.js | 8 ---- .../components/NewRootModelProvider.js | 37 ------------------- 2 files changed, 45 deletions(-) delete mode 100644 src/adapter/components/NewRootModelProvider.js diff --git a/src/adapter/bundle.js b/src/adapter/bundle.js index d0a93abd4d..0e2a4cf304 100644 --- a/src/adapter/bundle.js +++ b/src/adapter/bundle.js @@ -23,7 +23,6 @@ define([ 'legacyRegistry', './actions/ActionDialogDecorator', - './components/NewRootModelProvider', './directives/MCTView', './services/Instantiate', './capabilities/APICapabilityDecorator', @@ -32,7 +31,6 @@ define([ ], function ( legacyRegistry, ActionDialogDecorator, - NewRootModelProvider, MCTView, Instantiate, APICapabilityDecorator, @@ -77,12 +75,6 @@ define([ provides: "actionService", implementation: ActionDialogDecorator, depends: ["openmct"] - }, - { - "provides": "modelService", - "type": "provider", - "implementation": NewRootModelProvider, - "depends": ["openmct"] } ], policies: [ diff --git a/src/adapter/components/NewRootModelProvider.js b/src/adapter/components/NewRootModelProvider.js deleted file mode 100644 index 1de0363622..0000000000 --- a/src/adapter/components/NewRootModelProvider.js +++ /dev/null @@ -1,37 +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 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(['../../api/objects/object-utils'], function (utils) { - function NewRootModelProvider(openmct) { - this.openmct = openmct; - } - - NewRootModelProvider.prototype.getModels = function (ids) { - return this.openmct.objects.getRoot().then(function (root) { - return { - ROOT: utils.toOldFormat(root) - }; - }); - }; - - return NewRootModelProvider; -}); From 2cced53c97f73172b64faf8f6991b1a9ff083408 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 16:54:26 -0700 Subject: [PATCH 20/35] [Roots] Remove obsolete spec --- .../core/test/models/RootModelProviderSpec.js | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 platform/core/test/models/RootModelProviderSpec.js diff --git a/platform/core/test/models/RootModelProviderSpec.js b/platform/core/test/models/RootModelProviderSpec.js deleted file mode 100644 index a7e027c4ab..0000000000 --- a/platform/core/test/models/RootModelProviderSpec.js +++ /dev/null @@ -1,105 +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. - *****************************************************************************/ - -/** - * RootModelProviderSpec. Created by vwoeltje on 11/6/14. - */ -define( - ["../../src/models/RootModelProvider"], - function (RootModelProvider) { - - describe("The root model provider", function () { - var roots = [ - { - "id": "a", - "model": { - "name": "Thing A", - "someProperty": "Some Value A" - } - }, - { - "id": "b", - "model": { - "name": "Thing B", - "someProperty": "Some Value B" - } - } - ], - captured, - mockLog, - mockQ, - provider; - - function mockPromise(value) { - return { - then: function (callback) { - return mockPromise(callback(value)); - } - }; - } - - function capture(value) { - captured = value; - } - - - beforeEach(function () { - mockQ = { when: mockPromise }; - mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]); - provider = new RootModelProvider(roots, mockQ, mockLog); - }); - - it("provides models from extension declarations", function () { - // Verify that we got the promise as the return value - provider.getModels(["a", "b"]).then(capture); - - // Verify that the promise has the desired models - expect(captured.a.name).toEqual("Thing A"); - expect(captured.a.someProperty).toEqual("Some Value A"); - expect(captured.b.name).toEqual("Thing B"); - expect(captured.b.someProperty).toEqual("Some Value B"); - }); - - it("provides models with a location", function () { - provider.getModels(["a", "b"]).then(capture); - expect(captured.a.location).toBe('ROOT'); - expect(captured.b.location).toBe('ROOT'); - }); - - - it("does not provide models which are not in extension declarations", function () { - provider.getModels(["c"]).then(capture); - - // Verify that the promise has the desired models - expect(captured.c).toBeUndefined(); - }); - - it("provides a ROOT object with roots in its composition", function () { - provider.getModels(["ROOT"]).then(capture); - - expect(captured.ROOT).toBeDefined(); - expect(captured.ROOT.composition).toEqual(["a", "b"]); - }); - - }); - } -); From b49fef78f53b5abde9657317f88dcd5e8a75e18c Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 19 Oct 2016 17:02:12 -0700 Subject: [PATCH 21/35] [Roots] Remove obsolete provider --- platform/core/src/models/RootModelProvider.js | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 platform/core/src/models/RootModelProvider.js diff --git a/platform/core/src/models/RootModelProvider.js b/platform/core/src/models/RootModelProvider.js deleted file mode 100644 index 205d41e66b..0000000000 --- a/platform/core/src/models/RootModelProvider.js +++ /dev/null @@ -1,79 +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. - *****************************************************************************/ - -/** - * Module defining RootModelProvider. Created by vwoeltje on 11/7/14. - */ -define( - ['./StaticModelProvider'], - function (StaticModelProvider) { - - /** - * Provides the root object (id = "ROOT"), which is the top-level - * domain object shown when the application is started, from which all - * other domain objects are reached. - * - * The root model provider works as the static model provider, - * except that it aggregates roots[] instead of models[], and - * exposes them all as composition of the root object ROOT, - * whose model is also provided by this service. - * - * @memberof platform/core - * @constructor - * @implements {ModelService} - * @param {Array} roots all `roots[]` extensions - * @param $q Angular's $q, for promises - * @param $log Angular's $log, for logging - */ - function RootModelProvider(roots, $q, $log) { - // Pull out identifiers to used as ROOT's - var ids = roots.map(function (root) { - return root.id; - }); - - // Assign an initial location to root models - roots.forEach(function (root) { - if (!root.model) { - root.model = {}; - } - root.model.location = 'ROOT'; - }); - - this.baseProvider = new StaticModelProvider(roots, $q, $log); - this.rootModel = { - name: "The root object", - type: "root", - composition: ids - }; - } - - RootModelProvider.prototype.getModels = function (ids) { - var rootModel = this.rootModel; - return this.baseProvider.getModels(ids).then(function (models) { - models.ROOT = rootModel; - return models; - }); - }; - - return RootModelProvider; - } -); From 4cc020f0eacf27d66eaa4da008ae0132ae1998e8 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 20 Oct 2016 14:32:34 -0700 Subject: [PATCH 22/35] [Examples] Simplified MSL example, fixed object tree not loading by default, renamed. Fixes #1256. Fixes #1255 --- example/msl/bundle.js | 12 +--- example/msl/src/RemsTelemetryInitializer.js | 71 --------------------- 2 files changed, 2 insertions(+), 81 deletions(-) delete mode 100644 example/msl/src/RemsTelemetryInitializer.js diff --git a/example/msl/bundle.js b/example/msl/bundle.js index fbd0843935..5b8e6070c8 100644 --- a/example/msl/bundle.js +++ b/example/msl/bundle.js @@ -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", diff --git a/example/msl/src/RemsTelemetryInitializer.js b/example/msl/src/RemsTelemetryInitializer.js deleted file mode 100644 index 695f05d257..0000000000 --- a/example/msl/src/RemsTelemetryInitializer.js +++ /dev/null @@ -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; - } -); From d4730e16560d71f52656df6157254c64c7935c7f Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 26 Oct 2016 10:08:30 -0700 Subject: [PATCH 23/35] Revert "[Roots] Remove legacy root model provider" This reverts commit 7b0506bbdb42f3ff49cfcc4f5ad81a7f00ef2b0e. --- platform/core/bundle.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/core/bundle.js b/platform/core/bundle.js index 55879265c7..93b64f5739 100644 --- a/platform/core/bundle.js +++ b/platform/core/bundle.js @@ -24,6 +24,7 @@ define([ "./src/objects/DomainObjectProvider", "./src/capabilities/CoreCapabilityProvider", "./src/models/StaticModelProvider", + "./src/models/RootModelProvider", "./src/models/ModelAggregator", "./src/models/ModelCacheService", "./src/models/PersistedModelProvider", @@ -56,6 +57,7 @@ define([ DomainObjectProvider, CoreCapabilityProvider, StaticModelProvider, + RootModelProvider, ModelAggregator, ModelCacheService, PersistedModelProvider, @@ -150,6 +152,16 @@ define([ "$log" ] }, + { + "provides": "modelService", + "type": "provider", + "implementation": RootModelProvider, + "depends": [ + "roots[]", + "$q", + "$log" + ] + }, { "provides": "modelService", "type": "aggregator", From 9dec99824e5535f80dd350fefe6d979edee24b3c Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 26 Oct 2016 10:08:35 -0700 Subject: [PATCH 24/35] Revert "[Roots] Remove obsolete spec" This reverts commit 2cced53c97f73172b64faf8f6991b1a9ff083408. --- .../core/test/models/RootModelProviderSpec.js | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 platform/core/test/models/RootModelProviderSpec.js diff --git a/platform/core/test/models/RootModelProviderSpec.js b/platform/core/test/models/RootModelProviderSpec.js new file mode 100644 index 0000000000..a7e027c4ab --- /dev/null +++ b/platform/core/test/models/RootModelProviderSpec.js @@ -0,0 +1,105 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +/** + * RootModelProviderSpec. Created by vwoeltje on 11/6/14. + */ +define( + ["../../src/models/RootModelProvider"], + function (RootModelProvider) { + + describe("The root model provider", function () { + var roots = [ + { + "id": "a", + "model": { + "name": "Thing A", + "someProperty": "Some Value A" + } + }, + { + "id": "b", + "model": { + "name": "Thing B", + "someProperty": "Some Value B" + } + } + ], + captured, + mockLog, + mockQ, + provider; + + function mockPromise(value) { + return { + then: function (callback) { + return mockPromise(callback(value)); + } + }; + } + + function capture(value) { + captured = value; + } + + + beforeEach(function () { + mockQ = { when: mockPromise }; + mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]); + provider = new RootModelProvider(roots, mockQ, mockLog); + }); + + it("provides models from extension declarations", function () { + // Verify that we got the promise as the return value + provider.getModels(["a", "b"]).then(capture); + + // Verify that the promise has the desired models + expect(captured.a.name).toEqual("Thing A"); + expect(captured.a.someProperty).toEqual("Some Value A"); + expect(captured.b.name).toEqual("Thing B"); + expect(captured.b.someProperty).toEqual("Some Value B"); + }); + + it("provides models with a location", function () { + provider.getModels(["a", "b"]).then(capture); + expect(captured.a.location).toBe('ROOT'); + expect(captured.b.location).toBe('ROOT'); + }); + + + it("does not provide models which are not in extension declarations", function () { + provider.getModels(["c"]).then(capture); + + // Verify that the promise has the desired models + expect(captured.c).toBeUndefined(); + }); + + it("provides a ROOT object with roots in its composition", function () { + provider.getModels(["ROOT"]).then(capture); + + expect(captured.ROOT).toBeDefined(); + expect(captured.ROOT.composition).toEqual(["a", "b"]); + }); + + }); + } +); From 70985c5dbd049d12aad1b45686554056aba18a17 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 26 Oct 2016 10:08:37 -0700 Subject: [PATCH 25/35] Revert "[Roots] Remove obsolete provider" This reverts commit b49fef78f53b5abde9657317f88dcd5e8a75e18c. Fixes #1284 --- platform/core/src/models/RootModelProvider.js | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 platform/core/src/models/RootModelProvider.js diff --git a/platform/core/src/models/RootModelProvider.js b/platform/core/src/models/RootModelProvider.js new file mode 100644 index 0000000000..205d41e66b --- /dev/null +++ b/platform/core/src/models/RootModelProvider.js @@ -0,0 +1,79 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +/** + * Module defining RootModelProvider. Created by vwoeltje on 11/7/14. + */ +define( + ['./StaticModelProvider'], + function (StaticModelProvider) { + + /** + * Provides the root object (id = "ROOT"), which is the top-level + * domain object shown when the application is started, from which all + * other domain objects are reached. + * + * The root model provider works as the static model provider, + * except that it aggregates roots[] instead of models[], and + * exposes them all as composition of the root object ROOT, + * whose model is also provided by this service. + * + * @memberof platform/core + * @constructor + * @implements {ModelService} + * @param {Array} roots all `roots[]` extensions + * @param $q Angular's $q, for promises + * @param $log Angular's $log, for logging + */ + function RootModelProvider(roots, $q, $log) { + // Pull out identifiers to used as ROOT's + var ids = roots.map(function (root) { + return root.id; + }); + + // Assign an initial location to root models + roots.forEach(function (root) { + if (!root.model) { + root.model = {}; + } + root.model.location = 'ROOT'; + }); + + this.baseProvider = new StaticModelProvider(roots, $q, $log); + this.rootModel = { + name: "The root object", + type: "root", + composition: ids + }; + } + + RootModelProvider.prototype.getModels = function (ids) { + var rootModel = this.rootModel; + return this.baseProvider.getModels(ids).then(function (models) { + models.ROOT = rootModel; + return models; + }); + }; + + return RootModelProvider; + } +); From 40fb144d094422205854187ac9ba72be9d9f0043 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Wed, 26 Oct 2016 12:55:47 -0700 Subject: [PATCH 26/35] [Dev] develop with stylesheets Remove 'install' step from gulp develop task, instead run 'stylesheets' to build stylesheets. Result is much faster execution of gulp develop as is expected for a development tool. Fixes https://github.com/nasa/openmct/issues/1268. --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index e9a5d0fcf0..d3d6b5d21d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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' ]); From 81de6119fe6da3d5a8ecc38140bb26e4bdfeb953 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 27 Oct 2016 11:56:57 -0700 Subject: [PATCH 27/35] [Compat] model service adapter Provide adapter that ensures model service can fetch models provided via new API. Fixes https://github.com/nasa/openmct/issues/1279 --- src/adapter/bundle.js | 8 ++ .../MissingModelCompatibilityDecorator.js | 77 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/adapter/services/MissingModelCompatibilityDecorator.js diff --git a/src/adapter/bundle.js b/src/adapter/bundle.js index 0e2a4cf304..3cc360c243 100644 --- a/src/adapter/bundle.js +++ b/src/adapter/bundle.js @@ -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: [ diff --git a/src/adapter/services/MissingModelCompatibilityDecorator.js b/src/adapter/services/MissingModelCompatibilityDecorator.js new file mode 100644 index 0000000000..446aa0f478 --- /dev/null +++ b/src/adapter/services/MissingModelCompatibilityDecorator.js @@ -0,0 +1,77 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2016, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define([ + '../../api/objects/object-utils' +], function ( + objectUtils +) { + + function MissingModelCompatibilityDecorator(api, modelService) { + this.api = api; + this.modelService = modelService; + this.apiFetching = {}; // to prevent loops, if we have already + } + + 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; + }); + }; + + 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; +}); + From d813029046637b4c3513dd12a18e7dc36c0a50b8 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 27 Oct 2016 11:58:01 -0700 Subject: [PATCH 28/35] [API] Providers get with identifier Providers fetch objects using a full identifier. This ensures a consistent interface. Related to https://github.com/nasa/openmct/issues/1279 --- src/api/objects/ObjectAPI.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index 05b5caf657..6fc9383a55 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -150,10 +150,6 @@ define([ throw new Error('Provider does not support [' + method + '].'); } - if (method === 'get') { - return provider.get(identifier.key); - } - return provider[method].apply(provider, arguments); }; }); From 30b769d7412e98d02545f17f342139c246d141d3 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 27 Oct 2016 12:10:45 -0700 Subject: [PATCH 29/35] [API] Repair type registration Fixes #1294 --- src/MCT.js | 7 +++++++ src/api/Type.js | 24 ++++++++++++++++++++++++ src/api/types/TypeRegistry.js | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/MCT.js b/src/MCT.js index c1b328b736..31cf0dbf47 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -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'); /** diff --git a/src/api/Type.js b/src/api/Type.js index 717e417b21..af0bf73fab 100644 --- a/src/api/Type.js +++ b/src/api/Type.js @@ -55,5 +55,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; }); diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index e01bea4a9d..7a58ac52a6 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -44,6 +44,26 @@ define([], function () { this.types[typeKey] = type; }; + /** + * List keys for all registered types. + * @method list + * @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; }); From 23eff4b924cfa11232e76fbc1f8d85c39add7e90 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 27 Oct 2016 12:16:07 -0700 Subject: [PATCH 30/35] [API] Fix TypeRegistry docstring Fixes #1295 --- src/api/types/TypeRegistry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index 7a58ac52a6..ffea660510 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -37,7 +37,7 @@ 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) { From 833bad067edaceb6ce812cd0a468cc14c2dfb55a Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 27 Oct 2016 12:16:57 -0700 Subject: [PATCH 31/35] [API] Add creatable property to example --- API.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index fff93ef2d7..bc6422ad43 100644 --- a/API.md +++ b/API.md @@ -73,7 +73,8 @@ Custom types may be registered via ``` openmct.types.addType('my-type', new openmct.Type({ label: "My Type", - description: "This is a type that I added!" + description: "This is a type that I added!", + creatable: true }); ``` From 2bf05ae40ffb79b0f555828ba7900b0e50b5acfc Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 27 Oct 2016 12:21:16 -0700 Subject: [PATCH 32/35] [API] Add missing semicolon, satisfy JSHint --- src/api/types/TypeRegistry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index ffea660510..720a43d6c4 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -63,7 +63,7 @@ define([], function () { */ TypeRegistry.prototype.get = function (typeKey) { return this.types[typeKey]; - } + }; return TypeRegistry; }); From 12333f34179e34509abca8b54a2a961e63659b98 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 27 Oct 2016 12:22:46 -0700 Subject: [PATCH 33/35] [API] Use correct method name in docstring --- src/api/types/TypeRegistry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index 720a43d6c4..dc49df1887 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -46,7 +46,7 @@ define([], function () { /** * List keys for all registered types. - * @method list + * @method listKeys * @memberof module:openmct.TypeRegistry# * @returns {string[]} all registered type keys */ From a3459679d055e3817eefcb5d1a600fb8ec9c8abb Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 27 Oct 2016 13:01:29 -0700 Subject: [PATCH 34/35] [JSDoc] basic jsdoc --- .../MissingModelCompatibilityDecorator.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/adapter/services/MissingModelCompatibilityDecorator.js b/src/adapter/services/MissingModelCompatibilityDecorator.js index 446aa0f478..d0a11aef9c 100644 --- a/src/adapter/services/MissingModelCompatibilityDecorator.js +++ b/src/adapter/services/MissingModelCompatibilityDecorator.js @@ -26,12 +26,25 @@ define([ 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) { @@ -51,6 +64,10 @@ define([ }); }; + /** + * 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) { From 9a0fcc045c876c1bb78472d40862fdfc2aeff177 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 27 Oct 2016 15:30:34 -0700 Subject: [PATCH 35/35] [API] Simplify type registration https://github.com/nasa/openmct/pull/1302#discussion_r85417042 --- API.md | 2 +- src/api/api.js | 3 --- src/api/{ => types}/Type.js | 11 +---------- src/api/types/TypeRegistry.js | 17 ++++++++++++++--- 4 files changed, 16 insertions(+), 17 deletions(-) rename src/api/{ => types}/Type.js (83%) diff --git a/API.md b/API.md index bc6422ad43..8bef3c3889 100644 --- a/API.md +++ b/API.md @@ -71,7 +71,7 @@ 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!", creatable: true diff --git a/src/api/api.js b/src/api/api.js index f68460578b..c118e84ef7 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -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, diff --git a/src/api/Type.js b/src/api/types/Type.js similarity index 83% rename from src/api/Type.js rename to src/api/types/Type.js index af0bf73fab..c135972b31 100644 --- a/src/api/Type.js +++ b/src/api/types/Type.js @@ -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 */ diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index dc49df1887..6a887850a2 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -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 @@ -40,8 +51,8 @@ define([], function () { * @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); }; /**