[Types] label -> name

Change label to name, log a warning to console if a typeDef
is registered with a label.

Fixes https://github.com/nasa/openmct/issues/1568.
This commit is contained in:
Pete Richards 2017-05-09 17:55:15 -07:00
parent 4e15d8fa1f
commit c5161887e2
4 changed files with 26 additions and 4 deletions

4
API.md
View File

@ -146,7 +146,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
});
@ -157,7 +157,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

@ -75,7 +75,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.label) {
console.warn(
'DEPRECIATION WARNING typeDef: ' + typeDef.label + '. ' +
'`label` is depreciated 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