mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 22:17:49 +00:00
Merge pull request #1302 from nasa/types-nonfunctional-1294
[API] Fix type registration
This commit is contained in:
commit
eca9968a9f
5
API.md
5
API.md
@ -71,9 +71,10 @@ Custom types may be registered via
|
||||
[`openmct.types`]{@link module:openmct.MCT#types}:
|
||||
|
||||
```
|
||||
openmct.types.addType('my-type', new openmct.Type({
|
||||
openmct.types.addType('my-type', {
|
||||
label: "My Type",
|
||||
description: "This is a type that I added!"
|
||||
description: "This is a type that I added!",
|
||||
creatable: true
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -248,6 +248,13 @@ define([
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
this.types.listKeys().forEach(function (typeKey) {
|
||||
var type = this.types.get(typeKey);
|
||||
var legacyDefinition = type.toLegacyDefinition();
|
||||
legacyDefinition.key = typeKey;
|
||||
this.legacyExtension('types', legacyDefinition);
|
||||
}.bind(this));
|
||||
|
||||
legacyRegistry.register('adapter', this.legacyBundle);
|
||||
legacyRegistry.enable('adapter');
|
||||
/**
|
||||
|
@ -21,7 +21,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'./Type',
|
||||
'./TimeConductor',
|
||||
'./objects/ObjectAPI',
|
||||
'./composition/CompositionAPI',
|
||||
@ -30,7 +29,6 @@ define([
|
||||
'./ui/GestureAPI',
|
||||
'./telemetry/TelemetryAPI'
|
||||
], function (
|
||||
Type,
|
||||
TimeConductor,
|
||||
ObjectAPI,
|
||||
CompositionAPI,
|
||||
@ -40,7 +38,6 @@ define([
|
||||
TelemetryAPI
|
||||
) {
|
||||
return {
|
||||
Type: Type,
|
||||
TimeConductor: TimeConductor,
|
||||
ObjectAPI: ObjectAPI,
|
||||
CompositionAPI: CompositionAPI,
|
||||
|
@ -21,21 +21,12 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define(function () {
|
||||
/**
|
||||
* @typedef TypeDefinition
|
||||
* @memberof module:openmct.Type~
|
||||
* @property {Metadata} metadata displayable metadata about this type
|
||||
* @property {function (object)} [initialize] a function which initializes
|
||||
* the model for new domain objects of this type
|
||||
* @property {boolean} [creatable] true if users should be allowed to
|
||||
* create this type (default: false)
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Type describes a kind of domain object that may appear or be
|
||||
* created within Open MCT.
|
||||
*
|
||||
* @param {module:opemct.Type~TypeDefinition} definition
|
||||
* @param {module:opemct.TypeRegistry~TypeDefinition} definition
|
||||
* @class Type
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
@ -55,5 +46,29 @@ define(function () {
|
||||
return domainObject.type === this.key;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a definition for this type that can be registered using the
|
||||
* legacy bundle format.
|
||||
* @private
|
||||
*/
|
||||
Type.prototype.toLegacyDefinition = function () {
|
||||
var def = {};
|
||||
def.name = this.definition.label;
|
||||
def.cssclass = this.definition.cssclass;
|
||||
def.description = this.definition.description;
|
||||
def.properties = this.definition.form;
|
||||
|
||||
if (this.definition.initialize) {
|
||||
def.model = {};
|
||||
this.definition.initialize(def.model);
|
||||
}
|
||||
|
||||
if (this.definition.creatable) {
|
||||
def.features = ['creation'];
|
||||
}
|
||||
|
||||
return def;
|
||||
};
|
||||
|
||||
return Type;
|
||||
});
|
@ -20,7 +20,18 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([], function () {
|
||||
define(['./Type'], function (Type) {
|
||||
/**
|
||||
* @typedef TypeDefinition
|
||||
* @memberof module:openmct.TypeRegistry~
|
||||
* @property {string} label the name for this type of object
|
||||
* @property {string} description a longer-form description of this type
|
||||
* @property {function (object)} [initialize] a function which initializes
|
||||
* the model for new domain objects of this type
|
||||
* @property {boolean} [creatable] true if users should be allowed to
|
||||
* create this type (default: false)
|
||||
* @property {string} [cssclass] the CSS class to apply for icons
|
||||
*/
|
||||
|
||||
/**
|
||||
* A TypeRegistry maintains the definitions for different types
|
||||
@ -37,13 +48,33 @@ define([], function () {
|
||||
*
|
||||
* @param {string} typeKey a string identifier for this type
|
||||
* @param {module:openmct.Type} type the type to add
|
||||
* @method addProvider
|
||||
* @method addType
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
*/
|
||||
TypeRegistry.prototype.addType = function (typeKey, type) {
|
||||
this.types[typeKey] = type;
|
||||
TypeRegistry.prototype.addType = function (typeKey, typeDef) {
|
||||
this.types[typeKey] = new Type(typeDef);
|
||||
};
|
||||
|
||||
/**
|
||||
* List keys for all registered types.
|
||||
* @method listKeys
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
* @returns {string[]} all registered type keys
|
||||
*/
|
||||
TypeRegistry.prototype.listKeys = function () {
|
||||
return Object.keys(this.types);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a registered type by its key.
|
||||
* @method get
|
||||
* @param {string} typeKey the key for htis type
|
||||
* @memberof module:openmct.TypeRegistry#
|
||||
* @returns {module:openmct.Type} the registered type
|
||||
*/
|
||||
TypeRegistry.prototype.get = function (typeKey) {
|
||||
return this.types[typeKey];
|
||||
};
|
||||
|
||||
return TypeRegistry;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user