Files
openmct/platform/core/src/views/ViewProvider.js
Victor Woeltjen 0fdce798f7 [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
2014-11-20 12:58:21 -08:00

55 lines
1.5 KiB
JavaScript

/*global define,Promise*/
/**
* Module defining ViewProvider. Created by vwoeltje on 11/10/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function ViewProvider(views) {
function capabilitiesMatch(domainObject, capabilities, allowDelegation) {
var delegation = domainObject.getCapability("delegation");
allowDelegation = allowDelegation && (delegation !== undefined);
function hasCapability(c) {
return domainObject.hasCapability(c) ||
(allowDelegation && delegation.doesDelegateCapability(c));
}
function and(a, b) {
return a && b;
}
return capabilities.map(hasCapability).reduce(and, true);
}
function getViews(domainObject) {
var type = domainObject.useCapability("type");
return views.filter(function (view) {
return (!view.type) || type.instanceOf(view.type);
}).filter(function (view) {
return capabilitiesMatch(
domainObject,
view.needs || [],
view.delegation || false
);
});
}
return {
getViews: getViews
};
}
return ViewProvider;
}
);