[Representation] Check full ID path

...when determining if a representation needs to be
refreshed. Avoids representations becoming stale
when switching or navigating among linked instances
of the same domain object.

https://github.com/nasa/openmctweb/issues/302
This commit is contained in:
Victor Woeltjen 2015-12-02 10:21:00 -08:00
parent 3fd4304de1
commit 2514e44083

View File

@ -96,7 +96,7 @@ define(
toClear = [], // Properties to clear out of scope on change toClear = [], // Properties to clear out of scope on change
counter = 0, counter = 0,
couldRepresent = false, couldRepresent = false,
lastId, lastIdPath = [],
lastKey, lastKey,
changeTemplate = templateLinker.link($scope, element); changeTemplate = templateLinker.link($scope, element);
@ -143,11 +143,24 @@ define(
}); });
} }
function unchanged(canRepresent, id, key) { function unchanged(canRepresent, idPath, key) {
return canRepresent && return canRepresent &&
couldRepresent && couldRepresent &&
id === lastId && key === lastKey &&
key === lastKey; idPath.length === lastIdPath.length &&
idPath.every(function (id, i) {
return id === lastIdPath[i];
});
}
function getIdPath(domainObject) {
if (!domainObject) {
return [];
}
return domainObject.getCapability('context')
.getPath().map(function (pathObject) {
return pathObject.getId();
});
} }
// General-purpose refresh mechanism; should set up the scope // General-purpose refresh mechanism; should set up the scope
@ -159,10 +172,10 @@ define(
path = representation && getPath(representation), path = representation && getPath(representation),
uses = ((representation || {}).uses || []), uses = ((representation || {}).uses || []),
canRepresent = !!(path && domainObject), canRepresent = !!(path && domainObject),
id = domainObject && domainObject.getId(), idPath = getIdPath(domainObject),
key = $scope.key; key = $scope.key;
if (unchanged(canRepresent, id, key)) { if (unchanged(canRepresent, idPath, key)) {
return; return;
} }
@ -190,7 +203,7 @@ define(
// To allow simplified change detection next time around // To allow simplified change detection next time around
couldRepresent = canRepresent; couldRepresent = canRepresent;
lastId = id; lastIdPath = idPath;
lastKey = key; lastKey = key;
// Populate scope with fields associated with the current // Populate scope with fields associated with the current