[API] Use ViewRegistry from dialog adapter

https://github.com/nasa/openmct/pull/1212#pullrequestreview-2458991
This commit is contained in:
Victor Woeltjen 2016-10-07 11:07:53 -07:00
parent 580e10b024
commit 00d0b71080
3 changed files with 23 additions and 14 deletions

View File

@ -120,6 +120,17 @@ define([
*/
this.inspectors = new ViewRegistry();
/**
* Registry for views which should appear in Edit Properties
* dialogs, and similar user interface elements used for
* modifying domain objects external to its regular views.
*
* @type {module:openmct.ViewRegistry}
* @memberof module:openmct.MCT#
* @name propertyEditors
*/
this.propertyEditors = new ViewRegistry();
/**
* Registry for views which should appear in the status indicator area.
* @type {module:openmct.ViewRegistry}

View File

@ -23,19 +23,13 @@
define([
'../../api/objects/object-utils'
], function (objectUtils) {
function ActionDialogDecorator(mct, newViews, actionService) {
this.actionService = actionService;
function ActionDialogDecorator(mct, actionService) {
this.mct = mct;
this.definitions = newViews.filter(function (newView) {
return newView.region === mct.regions.properties;
}).map(function (newView) {
return newView.factory;
});
this.actionService = actionService;
}
ActionDialogDecorator.prototype.getActions = function (context) {
var mct = this.mct;
var definitions = this.definitions;
return this.actionService.getActions(context).map(function (action) {
if (action.dialogService) {
@ -43,16 +37,13 @@ define([
context.domainObject.getModel(),
objectUtils.parseKeyString(context.domainObject.getId())
);
var providers = mct.propertyEditors.get(domainObject);
definitions = definitions.filter(function (definition) {
return definition.canView(domainObject);
});
if (definitions.length > 0) {
if (providers.length > 0) {
action.dialogService = Object.create(action.dialogService);
action.dialogService.getUserInput = function (form, value) {
return new mct.Dialog(
definitions[0].view(context.domainObject),
providers[0].view(context.domainObject),
form.title
).show();
};

View File

@ -31,6 +31,13 @@ define([], function () {
this.providers = [];
}
/**
* @private for platform-internal use
* @param {*} item the object to be viewed
* @returns {module:openmct.ViewProvider[]} any providers
* which can provide views of this object
*/
ViewRegistry.prototype.get = function (item) {
return this.providers.filter(function (provider) {
return provider.canView(item);