From 9a6090cd02c4556dd665141092ee6761a33efa69 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Fri, 5 Oct 2018 10:41:06 -0700 Subject: [PATCH] Legacy inspector view support --- platform/commonUI/edit/bundle.js | 3 +- .../edit/src/capabilities/EditorCapability.js | 37 ++------ .../views/TypeInspectorViewProvider.js | 95 +++++++++++++++++++ src/adapter/views/installLegacyViews.js | 9 ++ 4 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 src/adapter/views/TypeInspectorViewProvider.js diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index 422703354a..748e835d19 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -405,7 +405,8 @@ define([ "description": "Provides transactional editing capabilities", "implementation": EditorCapability, "depends": [ - "transactionService" + "transactionService", + "openmct" ] } ], diff --git a/platform/commonUI/edit/src/capabilities/EditorCapability.js b/platform/commonUI/edit/src/capabilities/EditorCapability.js index c60f91806f..d4e31bccbc 100644 --- a/platform/commonUI/edit/src/capabilities/EditorCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditorCapability.js @@ -36,9 +36,11 @@ define( */ function EditorCapability( transactionService, + openmct, domainObject ) { this.transactionService = transactionService; + this.openmct = openmct; this.domainObject = domainObject; } @@ -48,27 +50,19 @@ define( * or finish() are called. */ EditorCapability.prototype.edit = function () { - this.transactionService.startTransaction(); + console.warn('DEPRECATED: cannot edit via edit capability, use openmct.editor instead.'); + this.openmct.editor.edit(); this.domainObject.getCapability('status').set('editing', true); }; - function isEditContextRoot(domainObject) { - return domainObject.getCapability('status').get('editing'); - } - - function isEditing(domainObject) { - return isEditContextRoot(domainObject) || - domainObject.hasCapability('context') && - isEditing(domainObject.getCapability('context').getParent()); - } - /** * Determines whether this object, or any of its ancestors are * currently being edited. * @returns boolean */ EditorCapability.prototype.inEditContext = function () { - return isEditing(this.domainObject); + console.warn('DEPRECATION WARNING: isEditing checks must be done via openmct.editor.'); + return this.openmct.editor.isEditing(); }; /** @@ -77,7 +71,8 @@ define( * @returns {*} */ EditorCapability.prototype.isEditContextRoot = function () { - return isEditContextRoot(this.domainObject); + console.warn('DEPRECATION WARNING: isEditing checks must be done via openmct.editor.'); + return this.openmct.editor.isEditing(); }; /** @@ -86,10 +81,7 @@ define( * @returns {*} */ EditorCapability.prototype.save = function () { - var transactionService = this.transactionService; - return transactionService.commit().then(function () { - transactionService.startTransaction(); - }); + console.warn('DEPRECATED: cannot save via edit capability, use openmct.editor instead.'); }; EditorCapability.prototype.invoke = EditorCapability.prototype.edit; @@ -100,16 +92,7 @@ define( * @returns {*} */ EditorCapability.prototype.finish = function () { - var domainObject = this.domainObject; - - if (this.transactionService.isActive()) { - return this.transactionService.cancel().then(function () { - domainObject.getCapability("status").set("editing", false); - return domainObject; - }); - } else { - return Promise.resolve(domainObject); - } + console.warn('DEPRECATED: cannot finish via edit capability, use openmct.editor instead.'); }; /** diff --git a/src/adapter/views/TypeInspectorViewProvider.js b/src/adapter/views/TypeInspectorViewProvider.js new file mode 100644 index 0000000000..513d08e9d3 --- /dev/null +++ b/src/adapter/views/TypeInspectorViewProvider.js @@ -0,0 +1,95 @@ +define([ + +], function ( + +) { + const DEFAULT_VIEW_PRIORITY = 100; + + const PRIORITY_LEVELS = { + "fallback": Number.NEGATIVE_INFINITY, + "default": -100, + "none": 0, + "optional": DEFAULT_VIEW_PRIORITY, + "preferred": 1000, + "mandatory": Number.POSITIVE_INFINITY + }; + + function TypeInspectorViewProvider(typeDefinition, openmct, convertToLegacyObject) { + console.warn(`DEPRECATION WARNING: Migrate ${typeDefinition.key} from ${typeDefinition.bundle.path} to use the new Inspector View APIs. Legacy Inspector view support will be removed soon.`); + let representation = openmct.$injector.get('representations[]') + .filter((r) => r.key === typeDefinition.inspector)[0]; + + return { + key: representation.key, + name: representation.name, + cssClass: representation.cssClass, + description: representation.description, + canView: function (selection) { + if (!selection[0] || !selection[0].context.item) { + return false; + } + let domainObject = selection[0].context.item; + return domainObject.type === typeDefinition.key; + }, + view: function (selection) { + let domainObject = selection[0].context.item; + let $rootScope = openmct.$injector.get('$rootScope'); + let templateLinker = openmct.$injector.get('templateLinker'); + let scope = $rootScope.$new(); + let legacyObject = convertToLegacyObject(domainObject); + let isDestroyed = false; + scope.domainObject = legacyObject; + scope.model = legacyObject.getModel(); + + + return { + show: function (container) { + // TODO: implement "gestures" support ? + let uses = representation.uses || []; + let promises = []; + let results = uses.map(function (capabilityKey, i) { + let result = legacyObject.useCapability(capabilityKey); + if (result.then) { + promises.push(result.then(function (r) { + results[i] = r; + })); + } + return result; + }); + + function link() { + if (isDestroyed) { + return; + } + uses.forEach(function (key, i) { + scope[key] = results[i]; + }); + templateLinker.link( + scope, + openmct.$angular.element(container), + representation + ); + container.style.height = '100%'; + } + + if (promises.length) { + Promise.all(promises) + .then(function () { + link(); + scope.$digest(); + }); + } else { + link(); + } + }, + destroy: function () { + scope.$destroy(); + } + } + } + }; + }; + + return TypeInspectorViewProvider; + +}); diff --git a/src/adapter/views/installLegacyViews.js b/src/adapter/views/installLegacyViews.js index f61a24085c..d98796976f 100644 --- a/src/adapter/views/installLegacyViews.js +++ b/src/adapter/views/installLegacyViews.js @@ -1,8 +1,10 @@ define([ './LegacyViewProvider', + './TypeInspectorViewProvider', '../../api/objects/object-utils' ], function ( LegacyViewProvider, + TypeInspectorViewProvider, objectUtils ) { function installLegacyViews(openmct, legacyViews, instantiate) { @@ -16,6 +18,13 @@ define([ legacyViews.forEach(function (legacyView) { openmct.objectViews.addProvider(new LegacyViewProvider(legacyView, openmct, convertToLegacyObject)); }); + + let inspectorTypes = openmct.$injector.get('types[]') + .filter((t) => t.hasOwnProperty('inspector')); + + inspectorTypes.forEach(function (typeDefinition) { + openmct.inspectorViews.addProvider(new TypeInspectorViewProvider(typeDefinition, openmct, convertToLegacyObject)); + }); } return installLegacyViews;