[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. eg.
```javascript ```javascript
openmct.types.addType('my-type', { openmct.types.addType('my-type', {
label: "My Type", name: "My Type",
description: "This is a type that I added!", description: "This is a type that I added!",
creatable: true creatable: true
}); });
@ -157,7 +157,7 @@ The `addType` function accepts two arguments:
for an object. for an object.
* An object type specification. An object type definition supports the following * An object type specification. An object type definition supports the following
attributes 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 * `description`: a `string` specifying a longer-form description of this type
* `initialize`: a `function` which initializes the model for new domain objects * `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 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", { 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.", description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.",
cssClass: "icon-telemetry", cssClass: "icon-telemetry",
creatable: true, creatable: true,

View File

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

View File

@ -19,6 +19,7 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/*global console*/
define(['./Type'], function (Type) { define(['./Type'], function (Type) {
/** /**
@ -52,9 +53,30 @@ define(['./Type'], function (Type) {
* @memberof module:openmct.TypeRegistry# * @memberof module:openmct.TypeRegistry#
*/ */
TypeRegistry.prototype.addType = function (typeKey, typeDef) { TypeRegistry.prototype.addType = function (typeKey, typeDef) {
this.standardizeType(typeDef);
this.types[typeKey] = new Type(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. * List keys for all registered types.
* @method listKeys * @method listKeys