[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",
"implementation": "MCTRepresentation.js",
"depends": [ "representations[]", "views[]", "representers[]", "$q", "$sce", "$log" ]
"depends": [ "representations[]", "views[]", "representers[]", "$q", "templateLinker", "$log" ]
}
],
"gestures": [

View File

@ -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: '<ng-include src="inclusion"></ng-include>',
// Two-way bind key and parameters, get the represented domain
// object as "mct-object"
scope: {

View File

@ -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;