From 22d2be894248522874b962b0a079bc117f1dec7e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 6 Jan 2015 10:01:01 -0800 Subject: [PATCH] [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. --- platform/core/src/views/ViewProvider.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/platform/core/src/views/ViewProvider.js b/platform/core/src/views/ViewProvider.js index f6caec903a..d1535328e8 100644 --- a/platform/core/src/views/ViewProvider.js +++ b/platform/core/src/views/ViewProvider.js @@ -81,15 +81,32 @@ define( 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) { var type = domainObject.useCapability("type"); // First, filter views by type (matched to domain object type.) // Second, filter by matching capabilities. return views.filter(function (view) { - return (!view.type) || type.instanceOf(view.type); - }).filter(function (view) { - return capabilitiesMatch( + return viewMatchesType(view, type) && capabilitiesMatch( domainObject, view.needs || [], view.delegation || false