From 2514e44083326fea644b669bb351f9af918ec737 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 2 Dec 2015 10:21:00 -0800 Subject: [PATCH] [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 --- .../representation/src/MCTRepresentation.js | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index d1937389d2..b68a6ad81e 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -96,7 +96,7 @@ define( toClear = [], // Properties to clear out of scope on change counter = 0, couldRepresent = false, - lastId, + lastIdPath = [], lastKey, changeTemplate = templateLinker.link($scope, element); @@ -143,11 +143,24 @@ define( }); } - function unchanged(canRepresent, id, key) { + function unchanged(canRepresent, idPath, key) { return canRepresent && 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 @@ -159,10 +172,10 @@ define( path = representation && getPath(representation), uses = ((representation || {}).uses || []), canRepresent = !!(path && domainObject), - id = domainObject && domainObject.getId(), + idPath = getIdPath(domainObject), key = $scope.key; - if (unchanged(canRepresent, id, key)) { + if (unchanged(canRepresent, idPath, key)) { return; } @@ -190,7 +203,7 @@ define( // To allow simplified change detection next time around couldRepresent = canRepresent; - lastId = id; + lastIdPath = idPath; lastKey = key; // Populate scope with fields associated with the current