mirror of
https://github.com/nasa/openmct.git
synced 2025-06-21 08:39:59 +00:00
[API] Move view off of type
This commit is contained in:
66
src/MCT.js
66
src/MCT.js
@ -1,8 +1,14 @@
|
|||||||
define([
|
define([
|
||||||
'EventEmitter',
|
'EventEmitter',
|
||||||
'legacyRegistry',
|
'legacyRegistry',
|
||||||
|
'uuid',
|
||||||
'./api/api'
|
'./api/api'
|
||||||
], function (EventEmitter, legacyRegistry, api) {
|
], function (
|
||||||
|
EventEmitter,
|
||||||
|
legacyRegistry,
|
||||||
|
uuid,
|
||||||
|
api
|
||||||
|
) {
|
||||||
function MCT() {
|
function MCT() {
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
this.legacyBundle = { extensions: {} };
|
this.legacyBundle = { extensions: {} };
|
||||||
@ -16,7 +22,41 @@ define([
|
|||||||
MCT.prototype.MCT = MCT;
|
MCT.prototype.MCT = MCT;
|
||||||
|
|
||||||
MCT.prototype.view = function (region, factory) {
|
MCT.prototype.view = function (region, factory) {
|
||||||
|
var viewKey = region + uuid();
|
||||||
|
var adaptedViewKey = "adapted-view-" + viewKey;
|
||||||
|
|
||||||
|
this.legacyBundle.extensions.views =
|
||||||
|
this.legacyBundle.extensions.views || [];
|
||||||
|
this.legacyBundle.extensions.views.push({
|
||||||
|
name: "A view",
|
||||||
|
key: adaptedViewKey,
|
||||||
|
template: '<mct-view key="\'' +
|
||||||
|
viewKey +
|
||||||
|
'\'" ' +
|
||||||
|
'mct-object="domainObject">' +
|
||||||
|
'</mct-view>'
|
||||||
|
});
|
||||||
|
|
||||||
|
this.legacyBundle.extensions.policies =
|
||||||
|
this.legacyBundle.extensions.policies || [];
|
||||||
|
this.legacyBundle.extensions.policies.push({
|
||||||
|
category: "view",
|
||||||
|
implementation: function Policy() {
|
||||||
|
this.allow = function (view, domainObject) {
|
||||||
|
if (view.key === adaptedViewKey) {
|
||||||
|
return !!factory(domainObject);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.legacyBundle.extensions.newViews =
|
||||||
|
this.legacyBundle.extensions.newViews || [];
|
||||||
|
this.legacyBundle.extensions.newViews.push({
|
||||||
|
factory: factory,
|
||||||
|
key: viewKey
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
MCT.prototype.type = function (key, type) {
|
MCT.prototype.type = function (key, type) {
|
||||||
@ -26,29 +66,7 @@ define([
|
|||||||
this.legacyBundle.extensions.types || [];
|
this.legacyBundle.extensions.types || [];
|
||||||
this.legacyBundle.extensions.types.push(legacyDef);
|
this.legacyBundle.extensions.types.push(legacyDef);
|
||||||
|
|
||||||
var viewFactory = type.view(this.regions.main);
|
type.key = key;
|
||||||
if (viewFactory) {
|
|
||||||
var viewKey = key + "." + this.regions.main;
|
|
||||||
|
|
||||||
this.legacyBundle.extensions.views =
|
|
||||||
this.legacyBundle.extensions.views || [];
|
|
||||||
this.legacyBundle.extensions.views.push({
|
|
||||||
name: "A view",
|
|
||||||
key: "adapted-view",
|
|
||||||
template: '<mct-view key="\'' +
|
|
||||||
viewKey +
|
|
||||||
'\'" ' +
|
|
||||||
'mct-object="domainObject">' +
|
|
||||||
'</mct-view>'
|
|
||||||
});
|
|
||||||
|
|
||||||
this.legacyBundle.extensions.newViews =
|
|
||||||
this.legacyBundle.extensions.newViews || [];
|
|
||||||
this.legacyBundle.extensions.newViews.push({
|
|
||||||
factory: viewFactory,
|
|
||||||
key: viewKey
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MCT.prototype.start = function () {
|
MCT.prototype.start = function () {
|
||||||
|
@ -17,6 +17,16 @@ define(function () {
|
|||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a domain object is an instance of this type.
|
||||||
|
* @param domainObject
|
||||||
|
* @returns {boolean} true if the domain object is of this type
|
||||||
|
*/
|
||||||
|
Type.prototype.check = function (domainObject) {
|
||||||
|
// Depends on assignment from MCT.
|
||||||
|
return domainObject.getModel().type === this.key;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a definition for this type that can be registered using the
|
* Get a definition for this type that can be registered using the
|
||||||
* legacy bundle format.
|
* legacy bundle format.
|
||||||
|
@ -97,11 +97,10 @@ define([
|
|||||||
$message.toggle(tasks.length < 1);
|
$message.toggle(tasks.length < 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
todoType.view(mct.regions.main, function (domainObject) {
|
|
||||||
return new TodoView(domainObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
mct.type('example.todo', todoType);
|
mct.type('example.todo', todoType);
|
||||||
|
mct.view(mct.regions.main, function (domainObject) {
|
||||||
|
return todoType.check(domainObject) && new TodoView(domainObject);
|
||||||
|
});
|
||||||
|
|
||||||
return mct;
|
return mct;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user