mirror of
https://github.com/nasa/openmct.git
synced 2025-04-07 11:26:49 +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",
|
||||
"implementation": "MCTRepresentation.js",
|
||||
"depends": [ "representations[]", "views[]", "gestureService", "$q", "$log" ]
|
||||
"depends": [ "representations[]", "views[]", "representers[]", "$q", "$log" ]
|
||||
}
|
||||
],
|
||||
"gestures": [
|
||||
@ -36,6 +36,12 @@
|
||||
"implementation": "gestures/GestureProvider.js",
|
||||
"depends": ["gestures[]"]
|
||||
}
|
||||
],
|
||||
"representers": [
|
||||
{
|
||||
"implementation": "gestures/GestureRepresenter.js",
|
||||
"depends": [ "gestureService" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ define(
|
||||
* representation 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 = {},
|
||||
representationMap = {},
|
||||
gestureMap = {};
|
||||
@ -52,8 +52,10 @@ define(
|
||||
});
|
||||
|
||||
|
||||
function link($scope, element) {
|
||||
var gestureHandle;
|
||||
function link($scope, element, attrs) {
|
||||
var activeRepresenters = representers.map(function (Representer) {
|
||||
return new Representer($scope, element, attrs);
|
||||
});
|
||||
|
||||
// General-purpose refresh mechanism; should set up the scope
|
||||
// as appropriate for current representation key and
|
||||
@ -73,9 +75,9 @@ define(
|
||||
$scope.inclusion = pathMap[$scope.key];
|
||||
|
||||
// Any existing gestures are no longer valid; release them.
|
||||
if (gestureHandle) {
|
||||
gestureHandle.destroy();
|
||||
}
|
||||
activeRepresenters.forEach(function (activeRepresenter) {
|
||||
activeRepresenter.destroy();
|
||||
});
|
||||
|
||||
// Log if a key was given, but no matching representation
|
||||
// was found.
|
||||
@ -89,6 +91,11 @@ define(
|
||||
// Always provide the model, as "model"
|
||||
$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
|
||||
uses.forEach(function (used) {
|
||||
$log.debug([
|
||||
@ -104,13 +111,11 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
// Finally, wire up any gestures that should be
|
||||
// associated with this representation.
|
||||
gestureHandle = gestureService.attachGestures(
|
||||
element,
|
||||
domainObject,
|
||||
gestureKeys
|
||||
);
|
||||
// Finally, wire up any additional behavior (such as
|
||||
// gestures) associated with this representation.
|
||||
activeRepresenters.forEach(function (representer) {
|
||||
representer.represent(representation, domainObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
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