mirror of
https://github.com/nasa/openmct.git
synced 2025-04-23 18:33:46 +00:00
[API] Add MCTView directive as an adapter
This commit is contained in:
parent
a07e2fb8e5
commit
136f2ae785
11
src/MCT.js
11
src/MCT.js
@ -21,6 +21,13 @@ define([
|
||||
this.legacyBundle.extensions.types =
|
||||
this.legacyBundle.extensions.types || [];
|
||||
this.legacyBundle.extensions.types.push(legacyDef);
|
||||
|
||||
var viewFactory = type.view(this.regions.main);
|
||||
if (viewFactory) {
|
||||
this.legacyBundle.extensions.views =
|
||||
this.legacyBundle.extensions.views || [];
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
MCT.prototype.start = function () {
|
||||
@ -28,5 +35,9 @@ define([
|
||||
this.emit('start');
|
||||
};
|
||||
|
||||
MCT.prototype.regions = {
|
||||
main: "MAIN"
|
||||
};
|
||||
|
||||
return MCT;
|
||||
});
|
||||
|
40
src/adapter/directives/MCTView.js
Normal file
40
src/adapter/directives/MCTView.js
Normal file
@ -0,0 +1,40 @@
|
||||
define(function () {
|
||||
function MCTView(newViews) {
|
||||
var factories = {};
|
||||
|
||||
newViews.forEach(function (newView) {
|
||||
factories[newView.key] = newView.factory;
|
||||
});
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function (scope, element, attrs) {
|
||||
var key = undefined;
|
||||
var mctObject = undefined;
|
||||
|
||||
function maybeShow() {
|
||||
if (!factories[key]) {
|
||||
return;
|
||||
}
|
||||
if (!mctObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
var view = factories[key](mctObject);
|
||||
var elements = view.elements;
|
||||
element.empty();
|
||||
element.append(elements);
|
||||
}
|
||||
|
||||
scope.$watch('key', setKey);
|
||||
scope.$watch('mctObject', setObject);
|
||||
},
|
||||
scope: {
|
||||
key: "=",
|
||||
mctObject: "="
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return MCTView;
|
||||
});
|
@ -15,8 +15,16 @@ define(function () {
|
||||
*/
|
||||
function Type(definition) {
|
||||
this.definition = definition;
|
||||
this.views = {};
|
||||
}
|
||||
|
||||
Type.prototype.view = function (region, factory) {
|
||||
if (arguments.length > 1) {
|
||||
this.views[region] = factory;
|
||||
}
|
||||
return this.views[region];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a definition for this type that can be registered using the
|
||||
* legacy bundle format.
|
||||
|
Loading…
x
Reference in New Issue
Block a user