From ab008ae49765b5e8a5a010ee65170b00fb5a0d61 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Oct 2015 15:17:36 -0700 Subject: [PATCH] [Representation] Begin integration ...of templateLinker into mct-representation. Not working currently due to prevalence of mct-representation instances with transcluding directives (hitting a multiple transclusion error.) --- platform/representation/bundle.json | 2 +- .../representation/src/MCTRepresentation.js | 27 ++++++++++++------- platform/representation/src/TemplateLinker.js | 18 ++++++++----- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/platform/representation/bundle.json b/platform/representation/bundle.json index 51ad8a0af8..7d6ddd3113 100644 --- a/platform/representation/bundle.json +++ b/platform/representation/bundle.json @@ -9,7 +9,7 @@ { "key": "mctRepresentation", "implementation": "MCTRepresentation.js", - "depends": [ "representations[]", "views[]", "representers[]", "$q", "$sce", "$log" ] + "depends": [ "representations[]", "views[]", "representers[]", "$q", "templateLinker", "$log" ] } ], "gestures": [ diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index 98a814c362..cefda36b42 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -55,7 +55,7 @@ define( * representation extensions * @param {ViewDefinition[]} views an array of view extensions */ - function MCTRepresentation(representations, views, representers, $q, $sce, $log) { + function MCTRepresentation(representations, views, representers, $q, templateLinker, $log) { var representationMap = {}, gestureMap = {}; @@ -72,11 +72,11 @@ define( // Get a path to a representation function getPath(representation) { - return $sce.trustAsResourceUrl([ + return [ representation.bundle.path, representation.bundle.resources, representation.templateUrl - ].join("/")); + ].join("/"); } // Look up a matching representation for this domain object @@ -94,12 +94,17 @@ define( } } - function link($scope, element, attrs) { + function link($scope, element, attrs, ctrl, transclude) { var activeRepresenters = representers.map(function (Representer) { return new Representer($scope, element, attrs); }), toClear = [], // Properties to clear out of scope on change - counter = 0; + counter = 0, + changeTemplate = templateLinker.link( + $scope, + element, + transclude + ); // Populate scope with any capabilities indicated by the // representation's extension definition @@ -158,7 +163,7 @@ define( // Look up the actual template path, pass it to ng-include // via the "inclusion" field - $scope.inclusion = representation && getPath(representation); + changeTemplate(representation && getPath(representation)); // Any existing representers are no longer valid; release them. destroyRepresenters(); @@ -227,16 +232,18 @@ define( } return { + transclude: 'element', + + priority: 601, + + terminal: true, + // Only applicable at the element level restrict: "E", // Handle Angular's linking step link: link, - // Use ng-include as a template; "inclusion" will be the real - // template path - template: '', - // Two-way bind key and parameters, get the represented domain // object as "mct-object" scope: { diff --git a/platform/representation/src/TemplateLinker.js b/platform/representation/src/TemplateLinker.js index 0dfa180d51..c3f8eb0208 100644 --- a/platform/representation/src/TemplateLinker.js +++ b/platform/representation/src/TemplateLinker.js @@ -63,6 +63,7 @@ define( TemplateLinker.prototype.link = function (scope, element, transclude) { var originalElement = element, activeElement = element, + activeTemplateUrl, self = this; function removeElement() { @@ -91,13 +92,18 @@ define( } } - return function (templateUrl) { - if (templateUrl) { - self.load(templateUrl).then(applyTemplate); - } else { - removeElement(); + function changeTemplate(templateUrl) { + if (templateUrl !== activeTemplateUrl) { + if (templateUrl) { + self.load(templateUrl).then(applyTemplate); + } else { + removeElement(); + } + activeTemplateUrl = templateUrl; } - }; + } + + return changeTemplate; }; return TemplateLinker;