mirror of
https://github.com/nasa/openmct.git
synced 2025-01-27 14:49:28 +00:00
f9060a485d
* [Plugin] Add static root plugin Add StaticRootPlugin, which allows a file exported with the ImportExport plugin to be mounted as a static root in Open MCT. Allows deployers to configure standard displays for deployments by exporting displays they have already created. * Include all src files
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
define([
|
|
'./StaticModelProvider'
|
|
], function (
|
|
StaticModelProvider
|
|
) {
|
|
/**
|
|
* Static Root Plugin: takes an export file and exposes it as a new root
|
|
* object.
|
|
*/
|
|
function StaticRootPlugin(namespace, exportUrl) {
|
|
|
|
var rootIdentifier = {
|
|
namespace: namespace,
|
|
key: 'root'
|
|
};
|
|
|
|
var cachedProvider;
|
|
|
|
var loadProvider = function () {
|
|
return fetch(exportUrl)
|
|
.then(function (response) {
|
|
return response.json();
|
|
})
|
|
.then(function (importData) {
|
|
cachedProvider = new StaticModelProvider(importData, rootIdentifier);
|
|
return cachedProvider;
|
|
});
|
|
|
|
};
|
|
|
|
var getProvider = function () {
|
|
if (!cachedProvider) {
|
|
cachedProvider = loadProvider();
|
|
}
|
|
return Promise.resolve(cachedProvider);
|
|
};
|
|
|
|
return function install(openmct) {
|
|
openmct.objects.addRoot(rootIdentifier);
|
|
openmct.objects.addProvider(namespace, {
|
|
get: function (identifier) {
|
|
return getProvider().then(function (provider) {
|
|
return provider.get(identifier);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
}
|
|
|
|
return StaticRootPlugin;
|
|
});
|