mirror of
https://github.com/nasa/openmct.git
synced 2025-06-20 16:10:23 +00:00
[Representation] Refresh only capabilities on modified
When changes to a domain object's modification timestamp are detected, refresh only the capabilities associated with that domain object (instead of rebuilding the whole view.) Specifically avoids latency when layout views are rebuilt, WTD-716.
This commit is contained in:
@ -57,6 +57,34 @@ define(
|
|||||||
return new Representer($scope, element, attrs);
|
return new Representer($scope, element, attrs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Populate scope with any capabilities indicated by the
|
||||||
|
// representation's extension definition
|
||||||
|
function refreshCapabilities() {
|
||||||
|
var representation = representationMap[$scope.key],
|
||||||
|
domainObject = $scope.domainObject,
|
||||||
|
uses = ((representation || {}).uses || []);
|
||||||
|
|
||||||
|
if (domainObject) {
|
||||||
|
// Update model
|
||||||
|
$scope.model = domainObject.getModel();
|
||||||
|
|
||||||
|
// Provide any of the capabilities requested
|
||||||
|
uses.forEach(function (used) {
|
||||||
|
$log.debug([
|
||||||
|
"Requesting capability ",
|
||||||
|
used,
|
||||||
|
" for representation ",
|
||||||
|
$scope.key
|
||||||
|
].join(""));
|
||||||
|
$q.when(
|
||||||
|
domainObject.useCapability(used)
|
||||||
|
).then(function (c) {
|
||||||
|
$scope[used] = c;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// domain object.
|
// domain object.
|
||||||
@ -88,29 +116,14 @@ define(
|
|||||||
// Populate scope with fields associated with the current
|
// Populate scope with fields associated with the current
|
||||||
// domain object (if one has been passed in)
|
// domain object (if one has been passed in)
|
||||||
if (domainObject) {
|
if (domainObject) {
|
||||||
// Always provide the model, as "model"
|
// Initialize any capabilities
|
||||||
$scope.model = domainObject.getModel();
|
refreshCapabilities();
|
||||||
|
|
||||||
// Also provide the view configuration,
|
// Also provide the view configuration,
|
||||||
// for the specific view
|
// for the specific view
|
||||||
$scope.configuration =
|
$scope.configuration =
|
||||||
($scope.model.configuration || {})[$scope.key] || {};
|
($scope.model.configuration || {})[$scope.key] || {};
|
||||||
|
|
||||||
// Also provide any of the capabilities requested
|
|
||||||
uses.forEach(function (used) {
|
|
||||||
$log.debug([
|
|
||||||
"Requesting capability ",
|
|
||||||
used,
|
|
||||||
" for representation ",
|
|
||||||
$scope.key
|
|
||||||
].join(""));
|
|
||||||
$q.when(
|
|
||||||
domainObject.useCapability(used)
|
|
||||||
).then(function (c) {
|
|
||||||
$scope[used] = c;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Finally, wire up any additional behavior (such as
|
// Finally, wire up any additional behavior (such as
|
||||||
// gestures) associated with this representation.
|
// gestures) associated with this representation.
|
||||||
activeRepresenters.forEach(function (representer) {
|
activeRepresenters.forEach(function (representer) {
|
||||||
@ -130,7 +143,7 @@ define(
|
|||||||
// Finally, also update when there is a new version of that
|
// Finally, also update when there is a new version of that
|
||||||
// same domain object; these changes should be tracked in the
|
// same domain object; these changes should be tracked in the
|
||||||
// model's "modified" field, by the mutation capability.
|
// model's "modified" field, by the mutation capability.
|
||||||
$scope.$watch("domainObject.getModel().modified", refresh);
|
$scope.$watch("domainObject.getModel().modified", refreshCapabilities);
|
||||||
|
|
||||||
// Do one initial refresh, so that we don't need another
|
// Do one initial refresh, so that we don't need another
|
||||||
// digest iteration just to populate the scope. Failure to
|
// digest iteration just to populate the scope. Failure to
|
||||||
|
@ -115,7 +115,7 @@ define(
|
|||||||
mockScope.key = "abc";
|
mockScope.key = "abc";
|
||||||
|
|
||||||
// Trigger the watch
|
// Trigger the watch
|
||||||
mockScope.$watch.mostRecentCall.args[1]();
|
mockScope.$watch.calls[0].args[1]();
|
||||||
|
|
||||||
expect(mockScope.inclusion).toEqual("a/b/c/template.html");
|
expect(mockScope.inclusion).toEqual("a/b/c/template.html");
|
||||||
});
|
});
|
||||||
@ -126,7 +126,7 @@ define(
|
|||||||
mockScope.key = "xyz";
|
mockScope.key = "xyz";
|
||||||
|
|
||||||
// Trigger the watch
|
// Trigger the watch
|
||||||
mockScope.$watch.mostRecentCall.args[1]();
|
mockScope.$watch.calls[0].args[1]();
|
||||||
|
|
||||||
expect(mockScope.inclusion).toEqual("x/y/z/template.html");
|
expect(mockScope.inclusion).toEqual("x/y/z/template.html");
|
||||||
});
|
});
|
||||||
@ -138,7 +138,7 @@ define(
|
|||||||
mockScope.domainObject = mockDomainObject;
|
mockScope.domainObject = mockDomainObject;
|
||||||
|
|
||||||
// Trigger the watch
|
// Trigger the watch
|
||||||
mockScope.$watch.mostRecentCall.args[1]();
|
mockScope.$watch.calls[0].args[1]();
|
||||||
|
|
||||||
expect(mockDomainObject.useCapability)
|
expect(mockDomainObject.useCapability)
|
||||||
.toHaveBeenCalledWith("testCapability");
|
.toHaveBeenCalledWith("testCapability");
|
||||||
@ -155,7 +155,7 @@ define(
|
|||||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// Trigger the watch
|
// Trigger the watch
|
||||||
mockScope.$watch.mostRecentCall.args[1]();
|
mockScope.$watch.calls[0].args[1]();
|
||||||
|
|
||||||
// Should have gotten a warning - that's an unknown key
|
// Should have gotten a warning - that's an unknown key
|
||||||
expect(mockLog.warn).toHaveBeenCalled();
|
expect(mockLog.warn).toHaveBeenCalled();
|
||||||
|
Reference in New Issue
Block a user