[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.)
This commit is contained in:
Victor Woeltjen 2015-10-28 15:17:36 -07:00
parent 3d59f6df0b
commit ab008ae497
3 changed files with 30 additions and 17 deletions

View File

@ -9,7 +9,7 @@
{ {
"key": "mctRepresentation", "key": "mctRepresentation",
"implementation": "MCTRepresentation.js", "implementation": "MCTRepresentation.js",
"depends": [ "representations[]", "views[]", "representers[]", "$q", "$sce", "$log" ] "depends": [ "representations[]", "views[]", "representers[]", "$q", "templateLinker", "$log" ]
} }
], ],
"gestures": [ "gestures": [

View File

@ -55,7 +55,7 @@ define(
* representation extensions * representation extensions
* @param {ViewDefinition[]} views an array of view 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 = {}, var representationMap = {},
gestureMap = {}; gestureMap = {};
@ -72,11 +72,11 @@ define(
// Get a path to a representation // Get a path to a representation
function getPath(representation) { function getPath(representation) {
return $sce.trustAsResourceUrl([ return [
representation.bundle.path, representation.bundle.path,
representation.bundle.resources, representation.bundle.resources,
representation.templateUrl representation.templateUrl
].join("/")); ].join("/");
} }
// Look up a matching representation for this domain object // 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) { var activeRepresenters = representers.map(function (Representer) {
return new Representer($scope, element, attrs); return new Representer($scope, element, attrs);
}), }),
toClear = [], // Properties to clear out of scope on change 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 // Populate scope with any capabilities indicated by the
// representation's extension definition // representation's extension definition
@ -158,7 +163,7 @@ define(
// Look up the actual template path, pass it to ng-include // Look up the actual template path, pass it to ng-include
// via the "inclusion" field // via the "inclusion" field
$scope.inclusion = representation && getPath(representation); changeTemplate(representation && getPath(representation));
// Any existing representers are no longer valid; release them. // Any existing representers are no longer valid; release them.
destroyRepresenters(); destroyRepresenters();
@ -227,16 +232,18 @@ define(
} }
return { return {
transclude: 'element',
priority: 601,
terminal: true,
// Only applicable at the element level // Only applicable at the element level
restrict: "E", restrict: "E",
// Handle Angular's linking step // Handle Angular's linking step
link: link, link: link,
// Use ng-include as a template; "inclusion" will be the real
// template path
template: '<ng-include src="inclusion"></ng-include>',
// Two-way bind key and parameters, get the represented domain // Two-way bind key and parameters, get the represented domain
// object as "mct-object" // object as "mct-object"
scope: { scope: {

View File

@ -63,6 +63,7 @@ define(
TemplateLinker.prototype.link = function (scope, element, transclude) { TemplateLinker.prototype.link = function (scope, element, transclude) {
var originalElement = element, var originalElement = element,
activeElement = element, activeElement = element,
activeTemplateUrl,
self = this; self = this;
function removeElement() { function removeElement() {
@ -91,13 +92,18 @@ define(
} }
} }
return function (templateUrl) { function changeTemplate(templateUrl) {
if (templateUrl !== activeTemplateUrl) {
if (templateUrl) { if (templateUrl) {
self.load(templateUrl).then(applyTemplate); self.load(templateUrl).then(applyTemplate);
} else { } else {
removeElement(); removeElement();
} }
}; activeTemplateUrl = templateUrl;
}
}
return changeTemplate;
}; };
return TemplateLinker; return TemplateLinker;