mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 15:43:48 +00:00
[Containment] Add general policy for containment rules
Add general policy for supporting containment rules, WTD-962.
This commit is contained in:
53
platform/containment/src/CapabilityTable.js
Normal file
53
platform/containment/src/CapabilityTable.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*global define*/
|
||||
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Build a table indicating which types are expected to expose
|
||||
* which capabilities.
|
||||
*/
|
||||
function CapabilityTable(typeService, capabilityService) {
|
||||
var table = {};
|
||||
|
||||
// Build an initial model for a type
|
||||
function buildModel(type) {
|
||||
var model = Object.create(type.getInitialModel() || {});
|
||||
model.type = type.getKey();
|
||||
return model;
|
||||
}
|
||||
|
||||
// Get capabilities expected for this type
|
||||
function getCapabilities(type) {
|
||||
return capabilityService.getCapabilities(buildModel(type));
|
||||
}
|
||||
|
||||
// Populate the lookup table for this type's capabilities
|
||||
function addToTable(type) {
|
||||
var typeKey = type.getKey();
|
||||
Object.keys(getCapabilities(type)).forEach(function (key) {
|
||||
table[key] = table[key] || {};
|
||||
table[key][typeKey] = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Build the table
|
||||
(typeService.listTypes() || []).forEach(addToTable);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Check if a type is expected to expose a specific
|
||||
* capability.
|
||||
*/
|
||||
hasCapability: function (typeKey, capabilityKey) {
|
||||
return (table[capabilityKey] || {})[typeKey];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return CapabilityTable;
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user