mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
[Core] Bring in core bundle from sandbox
Bring in bundle platform/core from the sandbox branch, in preparation for clean up, tests, and integration. WTD-573
This commit is contained in:
41
platform/core/src/models/ModelAggregator.js
Normal file
41
platform/core/src/models/ModelAggregator.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining ModelAggregator. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function ModelAggregator(providers) {
|
||||
function mergeModels(provided, ids) {
|
||||
var result = {};
|
||||
ids.forEach(function (id) {
|
||||
provided.forEach(function (models) {
|
||||
if (models[id]) {
|
||||
result[id] = models[id];
|
||||
}
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
return {
|
||||
getModels: function (ids) {
|
||||
return Promise.all(providers.map(function (provider) {
|
||||
return provider.getModels(ids);
|
||||
})).then(function (provided) {
|
||||
return mergeModels(provided, ids);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return ModelAggregator;
|
||||
}
|
||||
);
|
36
platform/core/src/models/PersistedModelProvider.js
Normal file
36
platform/core/src/models/PersistedModelProvider.js
Normal file
@ -0,0 +1,36 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining PersistedModelProvider. Created by vwoeltje on 11/12/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function PersistedModelProvider(persistenceService, $q, SPACE) {
|
||||
function promiseModels(ids) {
|
||||
return $q.all(ids.map(function (id) {
|
||||
return persistenceService.readObject(SPACE, id);
|
||||
})).then(function (models) {
|
||||
var result = {};
|
||||
ids.forEach(function (id, index) {
|
||||
result[id] = models[index];
|
||||
});
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
getModels: promiseModels
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return PersistedModelProvider;
|
||||
}
|
||||
);
|
41
platform/core/src/models/RootModelProvider.js
Normal file
41
platform/core/src/models/RootModelProvider.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining RootModelProvider. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
define(
|
||||
['./StaticModelProvider.js'],
|
||||
function (StaticModelProvider) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function RootModelProvider(roots, $log) {
|
||||
var ids = roots.map(function (root) {
|
||||
return root.id;
|
||||
}),
|
||||
baseProvider = new StaticModelProvider(roots, $log);
|
||||
|
||||
function addRoot(models) {
|
||||
models.ROOT = {
|
||||
name: "The root object",
|
||||
composition: ids
|
||||
};
|
||||
return models;
|
||||
}
|
||||
|
||||
return {
|
||||
getModels: function(ids) {
|
||||
return baseProvider.getModels(ids).then(addRoot);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return RootModelProvider;
|
||||
}
|
||||
);
|
64
platform/core/src/models/StaticModelProvider.js
Normal file
64
platform/core/src/models/StaticModelProvider.js
Normal file
@ -0,0 +1,64 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining StaticModelProvider. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Loads static models, provided as declared extensions of bundles.
|
||||
* @constructor
|
||||
*/
|
||||
function StaticModelProvider(models, $log) {
|
||||
var modelMap = {};
|
||||
|
||||
function addModelToMap(model) {
|
||||
// Skip models which don't look right
|
||||
if (typeof model !== 'object' ||
|
||||
typeof model.id !== 'string' ||
|
||||
typeof model.model !== 'object') {
|
||||
$log.warn([
|
||||
"Skipping malformed domain object model exposed by ",
|
||||
((model || {}).bundle || {}).path
|
||||
].join(""));
|
||||
} else {
|
||||
modelMap[model.id] = model.model;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepoulate maps with models to make subsequent lookup faster.
|
||||
models.forEach(addModelToMap);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get models for these specified string identifiers.
|
||||
* These will be given as an object containing keys
|
||||
* and values, where keys are object identifiers and
|
||||
* values are models.
|
||||
* This result may contain either a subset or a
|
||||
* superset of the total objects.
|
||||
*
|
||||
* @param {Array<string>} ids the string identifiers for
|
||||
* models of interest.
|
||||
* @returns {Promise<object>} a promise for an object
|
||||
* containing key-value pairs, where keys are
|
||||
* ids and values are models
|
||||
* @method
|
||||
* @memberof StaticModelProvider#
|
||||
*/
|
||||
getModels: function (ids) {
|
||||
var result = {};
|
||||
ids.forEach(function (id) {
|
||||
result[id] = modelMap[id];
|
||||
});
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return StaticModelProvider;
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user