mirror of
https://github.com/nasa/openmct.git
synced 2024-12-29 17:38:53 +00:00
Merge pull request #1010 from nasa/api-type-proto
[API Prototype] Type registration
This commit is contained in:
commit
5de7a96ccc
@ -18,6 +18,7 @@
|
||||
"node-uuid": "^1.4.7",
|
||||
"comma-separated-values": "^3.6.4",
|
||||
"FileSaver.js": "^0.0.2",
|
||||
"zepto": "^1.1.6"
|
||||
"zepto": "^1.1.6",
|
||||
"eventemitter3": "^1.2.0"
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,15 @@
|
||||
<script type="text/javascript">
|
||||
require(['main'], function (mct) {
|
||||
require([
|
||||
'./tutorials/todo/todo',
|
||||
'./tutorials/todo/bundle',
|
||||
'./example/imagery/bundle',
|
||||
'./example/eventGenerator/bundle',
|
||||
'./example/generator/bundle'
|
||||
], mct.run.bind(mct));
|
||||
], function (todoPlugin) {
|
||||
todoPlugin(mct);
|
||||
mct.start();
|
||||
})
|
||||
});
|
||||
</script>
|
||||
<link rel="stylesheet" href="platform/commonUI/general/res/css/startup-base.css">
|
||||
|
20
main.js
20
main.js
@ -28,6 +28,7 @@ requirejs.config({
|
||||
"angular-route": "bower_components/angular-route/angular-route.min",
|
||||
"csv": "bower_components/comma-separated-values/csv.min",
|
||||
"es6-promise": "bower_components/es6-promise/promise.min",
|
||||
"EventEmitter": "bower_components/eventemitter3/index",
|
||||
"moment": "bower_components/moment/moment",
|
||||
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
|
||||
"saveAs": "bower_components/FileSaver.js/FileSaver.min",
|
||||
@ -43,6 +44,9 @@ requirejs.config({
|
||||
"angular-route": {
|
||||
"deps": ["angular"]
|
||||
},
|
||||
"EventEmitter": {
|
||||
"exports": "EventEmitter"
|
||||
},
|
||||
"moment-duration-format": {
|
||||
"deps": ["moment"]
|
||||
},
|
||||
@ -58,6 +62,7 @@ requirejs.config({
|
||||
define([
|
||||
'./platform/framework/src/Main',
|
||||
'legacyRegistry',
|
||||
'./src/MCT',
|
||||
|
||||
'./platform/framework/bundle',
|
||||
'./platform/core/bundle',
|
||||
@ -93,11 +98,14 @@ define([
|
||||
'./platform/search/bundle',
|
||||
'./platform/status/bundle',
|
||||
'./platform/commonUI/regions/bundle'
|
||||
], function (Main, legacyRegistry) {
|
||||
return {
|
||||
legacyRegistry: legacyRegistry,
|
||||
run: function () {
|
||||
], function (Main, legacyRegistry, MCT) {
|
||||
var mct = new MCT();
|
||||
|
||||
mct.legacyRegistry = legacyRegistry;
|
||||
mct.run = mct.start;
|
||||
mct.on('start', function () {
|
||||
return new Main().run(legacyRegistry);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return mct;
|
||||
});
|
||||
|
31
src/MCT.js
Normal file
31
src/MCT.js
Normal file
@ -0,0 +1,31 @@
|
||||
define([
|
||||
'EventEmitter',
|
||||
'legacyRegistry',
|
||||
'./api/api'
|
||||
], function (EventEmitter, legacyRegistry, api) {
|
||||
function MCT() {
|
||||
EventEmitter.call(this);
|
||||
this.legacyBundle = { extensions: {} };
|
||||
}
|
||||
|
||||
MCT.prototype = Object.create(EventEmitter.prototype);
|
||||
|
||||
Object.keys(api).forEach(function (k) {
|
||||
MCT.prototype[k] = api[k];
|
||||
});
|
||||
|
||||
MCT.prototype.type = function (key, type) {
|
||||
var legacyDef = type.toLegacyDefinition();
|
||||
legacyDef.key = key;
|
||||
this.legacyBundle.extensions.types =
|
||||
this.legacyBundle.extensions.types || [];
|
||||
this.legacyBundle.extensions.types.push(legacyDef);
|
||||
};
|
||||
|
||||
MCT.prototype.start = function () {
|
||||
legacyRegistry.register('adapter', this.legacyBundle);
|
||||
this.emit('start');
|
||||
};
|
||||
|
||||
return MCT;
|
||||
});
|
43
src/api/Type.js
Normal file
43
src/api/Type.js
Normal file
@ -0,0 +1,43 @@
|
||||
define(function () {
|
||||
/**
|
||||
* @typedef TypeDefinition
|
||||
* @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)
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {TypeDefinition} definition
|
||||
* @constructor
|
||||
*/
|
||||
function Type(definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.metadata.label;
|
||||
def.glyph = this.definition.metadata.glyph;
|
||||
def.description = this.definition.metadata.description;
|
||||
|
||||
if (this.definition.initialize) {
|
||||
def.model = {};
|
||||
this.definition.initialize(def.model);
|
||||
}
|
||||
|
||||
if (this.definition.creatable) {
|
||||
def.features = ['creation'];
|
||||
}
|
||||
return def;
|
||||
};
|
||||
|
||||
return Type;
|
||||
});
|
9
src/api/api.js
Normal file
9
src/api/api.js
Normal file
@ -0,0 +1,9 @@
|
||||
define([
|
||||
'./Type'
|
||||
], function (
|
||||
Type
|
||||
) {
|
||||
return {
|
||||
Type: Type
|
||||
};
|
||||
});
|
@ -48,6 +48,7 @@ requirejs.config({
|
||||
"angular-route": "bower_components/angular-route/angular-route.min",
|
||||
"csv": "bower_components/comma-separated-values/csv.min",
|
||||
"es6-promise": "bower_components/es6-promise/promise.min",
|
||||
"EventEmitter": "bower_components/eventemitter3/index",
|
||||
"moment": "bower_components/moment/moment",
|
||||
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
|
||||
"saveAs": "bower_components/FileSaver.js/FileSaver.min",
|
||||
@ -64,6 +65,9 @@ requirejs.config({
|
||||
"angular-route": {
|
||||
"deps": [ "angular" ]
|
||||
},
|
||||
"EventEmitter": {
|
||||
"exports": "EventEmitter"
|
||||
},
|
||||
"moment-duration-format": {
|
||||
"deps": [ "moment" ]
|
||||
},
|
||||
|
@ -9,18 +9,6 @@ define([
|
||||
"name": "To-do Plugin",
|
||||
"description": "Allows creating and editing to-do lists.",
|
||||
"extensions": {
|
||||
"types": [
|
||||
{
|
||||
"key": "example.todo",
|
||||
"name": "To-Do List",
|
||||
"glyph": "2",
|
||||
"description": "A list of things that need to be done.",
|
||||
"features": ["creation"],
|
||||
"model": {
|
||||
"tasks": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"views": [
|
||||
{
|
||||
"key": "example.todo",
|
||||
|
19
tutorials/todo/todo.js
Normal file
19
tutorials/todo/todo.js
Normal file
@ -0,0 +1,19 @@
|
||||
define(function () {
|
||||
return function todoPlugin(mct) {
|
||||
var todoType = new mct.Type({
|
||||
metadata: {
|
||||
label: "To-Do List",
|
||||
glyph: "2",
|
||||
description: "A list of things that need to be done."
|
||||
},
|
||||
initialize: function (model) {
|
||||
model.tasks = [];
|
||||
},
|
||||
creatable: true
|
||||
});
|
||||
|
||||
mct.type('example.todo', todoType);
|
||||
|
||||
return mct;
|
||||
};
|
||||
});
|
Loading…
Reference in New Issue
Block a user