Merge pull request #1571 from nasa/standardize-type-name

[Types] label -> name
This commit is contained in:
Pete Richards 2017-05-10 14:51:25 -07:00 committed by GitHub
commit 258020624c
4 changed files with 26 additions and 4 deletions

4
API.md
View File

@ -155,7 +155,7 @@ registry.
eg.
```javascript
openmct.types.addType('my-type', {
label: "My Type",
name: "My Type",
description: "This is a type that I added!",
creatable: true
});
@ -166,7 +166,7 @@ The `addType` function accepts two arguments:
for an object.
* An object type specification. An object type definition supports the following
attributes
* `label`: a `string` naming this object type
* `name`: a `string` naming this object type
* `description`: a `string` specifying a longer-form description of this type
* `initialize`: a `function` which initializes the model for new domain objects
of this type. This can be used for setting default values on an object when

View File

@ -47,7 +47,7 @@ define([
})
});
openmct.types.addType("generator", {
label: "Sine Wave Generator",
name: "Sine Wave Generator",
description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.",
cssClass: "icon-telemetry",
creatable: true,

View File

@ -53,7 +53,7 @@ define(function () {
*/
Type.prototype.toLegacyDefinition = function () {
var def = {};
def.name = this.definition.label;
def.name = this.definition.name;
def.cssClass = this.definition.cssClass;
def.description = this.definition.description;
def.properties = this.definition.form;

View File

@ -19,6 +19,7 @@
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global console*/
define(['./Type'], function (Type) {
/**
@ -52,9 +53,30 @@ define(['./Type'], function (Type) {
* @memberof module:openmct.TypeRegistry#
*/
TypeRegistry.prototype.addType = function (typeKey, typeDef) {
this.standardizeType(typeDef);
this.types[typeKey] = new Type(typeDef);
};
/**
* Takes a typeDef, standardizes it, and logs warnings about unsupported
* usage.
* @private
*/
TypeRegistry.prototype.standardizeType = function (typeDef) {
if (typeDef.hasOwnProperty('label')) {
console.warn(
'DEPRECATION WARNING typeDef: ' + typeDef.label + '. ' +
'`label` is deprecated in type definitions. Please use ' +
'`name` instead. This will cause errors in a future version ' +
'of Open MCT. For more information, see ' +
'https://github.com/nasa/openmct/issues/1568');
if (!typeDef.name) {
typeDef.name = typeDef.label;
}
delete typeDef.label;
}
};
/**
* List keys for all registered types.
* @method listKeys