mirror of
https://github.com/nasa/openmct.git
synced 2025-05-30 14:14:19 +00:00
[Layout] Add notion of representers
Add representers as a category of extension; these are extra steps to perform when representing a domain object. This will be used to support automatic mutation/persistence of domain objects from a watch, while avoiding bloat within the mct-representation directive itself. This, in turn, simplifies the persistence strategy to be employed by Layout views when editing concludes. WTD-535.
This commit is contained in:
parent
b50f40f399
commit
67b9af54b3
@ -9,7 +9,7 @@
|
|||||||
{
|
{
|
||||||
"key": "mctRepresentation",
|
"key": "mctRepresentation",
|
||||||
"implementation": "MCTRepresentation.js",
|
"implementation": "MCTRepresentation.js",
|
||||||
"depends": [ "representations[]", "views[]", "gestureService", "$q", "$log" ]
|
"depends": [ "representations[]", "views[]", "representers[]", "$q", "$log" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gestures": [
|
"gestures": [
|
||||||
@ -36,6 +36,12 @@
|
|||||||
"implementation": "gestures/GestureProvider.js",
|
"implementation": "gestures/GestureProvider.js",
|
||||||
"depends": ["gestures[]"]
|
"depends": ["gestures[]"]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"representers": [
|
||||||
|
{
|
||||||
|
"implementation": "gestures/GestureRepresenter.js",
|
||||||
|
"depends": [ "gestureService" ]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ define(
|
|||||||
* representation extensions
|
* representation extensions
|
||||||
* @param {ViewDefinition[]} views an array of view extensions
|
* @param {ViewDefinition[]} views an array of view extensions
|
||||||
*/
|
*/
|
||||||
function MCTRepresentation(representations, views, gestureService, $q, $log) {
|
function MCTRepresentation(representations, views, representers, $q, $log) {
|
||||||
var pathMap = {},
|
var pathMap = {},
|
||||||
representationMap = {},
|
representationMap = {},
|
||||||
gestureMap = {};
|
gestureMap = {};
|
||||||
@ -52,8 +52,10 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function link($scope, element) {
|
function link($scope, element, attrs) {
|
||||||
var gestureHandle;
|
var activeRepresenters = representers.map(function (Representer) {
|
||||||
|
return new Representer($scope, element, attrs);
|
||||||
|
});
|
||||||
|
|
||||||
// General-purpose refresh mechanism; should set up the scope
|
// General-purpose refresh mechanism; should set up the scope
|
||||||
// as appropriate for current representation key and
|
// as appropriate for current representation key and
|
||||||
@ -73,9 +75,9 @@ define(
|
|||||||
$scope.inclusion = pathMap[$scope.key];
|
$scope.inclusion = pathMap[$scope.key];
|
||||||
|
|
||||||
// Any existing gestures are no longer valid; release them.
|
// Any existing gestures are no longer valid; release them.
|
||||||
if (gestureHandle) {
|
activeRepresenters.forEach(function (activeRepresenter) {
|
||||||
gestureHandle.destroy();
|
activeRepresenter.destroy();
|
||||||
}
|
});
|
||||||
|
|
||||||
// Log if a key was given, but no matching representation
|
// Log if a key was given, but no matching representation
|
||||||
// was found.
|
// was found.
|
||||||
@ -89,6 +91,11 @@ define(
|
|||||||
// Always provide the model, as "model"
|
// Always provide the model, as "model"
|
||||||
$scope.model = domainObject.getModel();
|
$scope.model = domainObject.getModel();
|
||||||
|
|
||||||
|
// Also provide the view configuration,
|
||||||
|
// for the specific view
|
||||||
|
$scope.configuration =
|
||||||
|
($scope.model.configuration || {})[$scope.key] || {};
|
||||||
|
|
||||||
// Also provide any of the capabilities requested
|
// Also provide any of the capabilities requested
|
||||||
uses.forEach(function (used) {
|
uses.forEach(function (used) {
|
||||||
$log.debug([
|
$log.debug([
|
||||||
@ -104,13 +111,11 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Finally, wire up any gestures that should be
|
// Finally, wire up any additional behavior (such as
|
||||||
// associated with this representation.
|
// gestures) associated with this representation.
|
||||||
gestureHandle = gestureService.attachGestures(
|
activeRepresenters.forEach(function (representer) {
|
||||||
element,
|
representer.represent(representation, domainObject);
|
||||||
domainObject,
|
});
|
||||||
gestureKeys
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
platform/representation/src/gestures/GestureRepresenter.js
Normal file
37
platform/representation/src/gestures/GestureRepresenter.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function GestureRepresenter(gestureService, scope, element) {
|
||||||
|
var gestureHandle;
|
||||||
|
|
||||||
|
function destroy() {
|
||||||
|
if (gestureHandle) {
|
||||||
|
gestureHandle.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function represent(representation, domainObject) {
|
||||||
|
// Clear out any existing gestures
|
||||||
|
destroy();
|
||||||
|
|
||||||
|
// Attach gestures - by way of the service.
|
||||||
|
gestureHandle = gestureService.attachGestures(
|
||||||
|
element,
|
||||||
|
domainObject,
|
||||||
|
(representation || {}).gestures || []
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
represent: represent,
|
||||||
|
destroy: destroy
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return GestureRepresenter;
|
||||||
|
}
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user