mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 06:08:11 +00:00
[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:
@ -165,6 +165,10 @@
|
|||||||
"implementation": "capabilities/PersistenceCapability.js",
|
"implementation": "capabilities/PersistenceCapability.js",
|
||||||
"depends": [ "persistenceService", "PERSISTENCE_SPACE" ]
|
"depends": [ "persistenceService", "PERSISTENCE_SPACE" ]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "metadata",
|
||||||
|
"implementation": "capabilities/MetadataCapability.js"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "mutation",
|
"key": "mutation",
|
||||||
"implementation": "capabilities/MutationCapability.js",
|
"implementation": "capabilities/MutationCapability.js",
|
||||||
|
62
platform/core/src/capabilities/MetadataCapability.js
Normal file
62
platform/core/src/capabilities/MetadataCapability.js
Normal 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;
|
||||||
|
}
|
||||||
|
);
|
Reference in New Issue
Block a user