mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
[Views] Allow types to restrict views
Allow type definitions to restrict views; this specifically supports the restriction of autoflow tabular views to packets, and the omission of scrolling/plot views as applicable to packets. WTD-644.
This commit is contained in:
@ -81,15 +81,32 @@ define(
|
|||||||
return capabilities.map(hasCapability).reduce(and, true);
|
return capabilities.map(hasCapability).reduce(and, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if a view and domain object type can be paired;
|
||||||
|
// both can restrict the others they accept.
|
||||||
|
function viewMatchesType(view, type) {
|
||||||
|
var views = type && type.getDefinition().views,
|
||||||
|
matches = true;
|
||||||
|
|
||||||
|
// View is restricted to a certain type
|
||||||
|
if (view.type) {
|
||||||
|
matches = matches && type && type.instanceOf(view.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type wishes to restrict its specific views
|
||||||
|
if (Array.isArray(views)) {
|
||||||
|
matches = matches && (views.indexOf(view.key) > -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
function getViews(domainObject) {
|
function getViews(domainObject) {
|
||||||
var type = domainObject.useCapability("type");
|
var type = domainObject.useCapability("type");
|
||||||
|
|
||||||
// First, filter views by type (matched to domain object type.)
|
// First, filter views by type (matched to domain object type.)
|
||||||
// Second, filter by matching capabilities.
|
// Second, filter by matching capabilities.
|
||||||
return views.filter(function (view) {
|
return views.filter(function (view) {
|
||||||
return (!view.type) || type.instanceOf(view.type);
|
return viewMatchesType(view, type) && capabilitiesMatch(
|
||||||
}).filter(function (view) {
|
|
||||||
return capabilitiesMatch(
|
|
||||||
domainObject,
|
domainObject,
|
||||||
view.needs || [],
|
view.needs || [],
|
||||||
view.delegation || false
|
view.delegation || false
|
||||||
|
Reference in New Issue
Block a user