mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 06:08:11 +00:00
[Roots] Register roots with new API
Register roots added via old API with new API when the application starts. Fixes #1264.
This commit is contained in:
@ -27,7 +27,8 @@ define([
|
|||||||
'./services/Instantiate',
|
'./services/Instantiate',
|
||||||
'./capabilities/APICapabilityDecorator',
|
'./capabilities/APICapabilityDecorator',
|
||||||
'./policies/AdapterCompositionPolicy',
|
'./policies/AdapterCompositionPolicy',
|
||||||
'./runs/AlternateCompositionInitializer'
|
'./runs/AlternateCompositionInitializer',
|
||||||
|
'./runs/RootRegistrar'
|
||||||
], function (
|
], function (
|
||||||
legacyRegistry,
|
legacyRegistry,
|
||||||
ActionDialogDecorator,
|
ActionDialogDecorator,
|
||||||
@ -35,7 +36,8 @@ define([
|
|||||||
Instantiate,
|
Instantiate,
|
||||||
APICapabilityDecorator,
|
APICapabilityDecorator,
|
||||||
AdapterCompositionPolicy,
|
AdapterCompositionPolicy,
|
||||||
AlternateCompositionInitializer
|
AlternateCompositionInitializer,
|
||||||
|
RootRegistrar
|
||||||
) {
|
) {
|
||||||
legacyRegistry.register('src/adapter', {
|
legacyRegistry.register('src/adapter', {
|
||||||
"extensions": {
|
"extensions": {
|
||||||
@ -88,6 +90,10 @@ define([
|
|||||||
{
|
{
|
||||||
implementation: AlternateCompositionInitializer,
|
implementation: AlternateCompositionInitializer,
|
||||||
depends: ["openmct"]
|
depends: ["openmct"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
implementation: RootRegistrar,
|
||||||
|
depends: ["openmct", "roots[]"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
licenses: [
|
licenses: [
|
||||||
|
32
src/adapter/runs/RootRegistrar.js
Normal file
32
src/adapter/runs/RootRegistrar.js
Normal file
@ -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;
|
||||||
|
});
|
47
src/adapter/runs/RootRegistrarSpec.js
Normal file
47
src/adapter/runs/RootRegistrarSpec.js
Normal file
@ -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' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -28,50 +28,50 @@ define([
|
|||||||
|
|
||||||
// take a key string and turn it into a key object
|
// take a key string and turn it into a key object
|
||||||
// 'scratch:root' ==> {namespace: 'scratch', identifier: 'root'}
|
// 'scratch:root' ==> {namespace: 'scratch', identifier: 'root'}
|
||||||
var parseKeyString = function (key) {
|
var parseKeyString = function (identifier) {
|
||||||
if (typeof key === 'object') {
|
if (typeof identifier === 'object') {
|
||||||
return key;
|
return identifier;
|
||||||
}
|
}
|
||||||
var namespace = '',
|
var namespace = '',
|
||||||
identifier = key;
|
key = identifier;
|
||||||
for (var i = 0, escaped = false; i < key.length; i++) {
|
for (var i = 0, escaped = false; i < key.length; i++) {
|
||||||
if (escaped) {
|
if (escaped) {
|
||||||
escaped = false;
|
escaped = false;
|
||||||
namespace += key[i];
|
namespace += key[i];
|
||||||
} else {
|
} else {
|
||||||
if (key[i] === "\\") {
|
if (identifier[i] === "\\") {
|
||||||
escaped = true;
|
escaped = true;
|
||||||
} else if (key[i] === ":") {
|
} else if (identifier[i] === ":") {
|
||||||
// namespace = key.slice(0, i);
|
// namespace = key.slice(0, i);
|
||||||
identifier = key.slice(i + 1);
|
key = identifier.slice(i + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
namespace += key[i];
|
namespace += identifier[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key === namespace) {
|
if (identifier === namespace) {
|
||||||
namespace = '';
|
namespace = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
identifier: identifier
|
key: key
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// take a key and turn it into a key string
|
// take a key and turn it into a key string
|
||||||
// {namespace: 'scratch', identifier: 'root'} ==> 'scratch:root'
|
// {namespace: 'scratch', identifier: 'root'} ==> 'scratch:root'
|
||||||
var makeKeyString = function (key) {
|
var makeKeyString = function (identifier) {
|
||||||
if (typeof key === 'string') {
|
if (typeof identifier === 'string') {
|
||||||
return key;
|
return identifier;
|
||||||
}
|
}
|
||||||
if (!key.namespace) {
|
if (!identifier.namespace) {
|
||||||
return key.identifier;
|
return identifier.key;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
key.namespace.replace(':', '\\:'),
|
identifier.namespace.replace(':', '\\:'),
|
||||||
key.identifier.replace(':', '\\:')
|
identifier.key.replace(':', '\\:')
|
||||||
].join(':');
|
].join(':');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user