[Info Bubble] Add metadata capability

Add metadata capability, which will be used to populate
contents of an info bubble. WTD-884.
This commit is contained in:
Victor Woeltjen 2015-06-04 12:09:30 -07:00
parent 588c35de4e
commit cd26d1284e
2 changed files with 66 additions and 0 deletions

View File

@ -165,6 +165,10 @@
"implementation": "capabilities/PersistenceCapability.js",
"depends": [ "persistenceService", "PERSISTENCE_SPACE" ]
},
{
"key": "metadata",
"implementation": "capabilities/MetadataCapability.js"
},
{
"key": "mutation",
"implementation": "capabilities/MutationCapability.js",

View File

@ -0,0 +1,62 @@
/*global define*/
define(
function () {
"use strict";
/**
* A piece of information about a domain object.
* @typedef {Object} MetadataProperty
* @property {string} name the human-readable name of this property
* @property {string} value the human-readable value of this property,
* for this specific domain object
*/
/**
* Implements the `metadata` capability of a domain object, providing
* properties of that object for display.
*
* Usage: `domainObject.useCapability("metadata")`
*
* ...which will return an array of objects containing `name` and
* `value` properties describing that domain object (suitable for
* display.)
*
* @constructor
*/
function MetadataCapability(domainObject) {
return {
/**
* Get metadata about this object.
* @returns {MetadataProperty[]} metadata about this object
*/
invoke: function () {
var type = domainObject.getCapability('type'),
model = domainObject.getModel(),
metadata = [{
name: "ID",
value: domainObject.getId()
}];
function addProperty(typeProperty) {
var name = typeProperty.getDefinition().name,
value = typeProperty.getValue(model);
if (typeof value === 'string' ||
typeof value === 'number') {
metadata.push({
name: name,
value: value
});
}
}
(type ? type.getProperties() : []).forEach(addProperty);
return metadata;
}
};
}
return MetadataCapability;
}
);