mirror of
https://github.com/nasa/openmct.git
synced 2025-04-16 07:26:53 +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:
parent
588c35de4e
commit
cd26d1284e
@ -165,6 +165,10 @@
|
||||
"implementation": "capabilities/PersistenceCapability.js",
|
||||
"depends": [ "persistenceService", "PERSISTENCE_SPACE" ]
|
||||
},
|
||||
{
|
||||
"key": "metadata",
|
||||
"implementation": "capabilities/MetadataCapability.js"
|
||||
},
|
||||
{
|
||||
"key": "mutation",
|
||||
"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;
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user