[Tree] Show root for most trees

Modify tree so that it includes its root in most cases, for
WTD-922.
This commit is contained in:
Victor Woeltjen 2015-03-18 10:30:36 -07:00
parent bb4ea2d4ae
commit d863c2843c
5 changed files with 52 additions and 19 deletions

View File

@ -151,6 +151,12 @@
{ {
"key": "tree", "key": "tree",
"templateUrl": "templates/tree.html", "templateUrl": "templates/tree.html",
"type": "root",
"priority": "preferred"
},
{
"key": "tree",
"templateUrl": "templates/subtree.html",
"uses": [ "composition" ] "uses": [ "composition" ]
}, },
{ {

View File

@ -0,0 +1,14 @@
<ul class="tree">
<li ng-if="!composition">
<span class="tree-item">
<span class="icon wait-spinner"></span>
<span class="title-label">Loading...</span>
</span>
</li>
<li ng-repeat="child in composition">
<mct-representation key="'tree-node'"
mct-object="child"
ng-model="ngModel">
</mct-representation>
</li>
</ul>

View File

@ -1,13 +1,7 @@
<ul class="tree"> <ul class="tree">
<li ng-if="!composition"> <li>
<span class="tree-item">
<span class="icon wait-spinner"></span>
<span class="title-label">Loading...</span>
</span>
</li>
<li ng-repeat="child in composition">
<mct-representation key="'tree-node'" <mct-representation key="'tree-node'"
mct-object="child" mct-object="domainObject"
ng-model="ngModel"> ng-model="ngModel">
</mct-representation> </mct-representation>
</li> </li>

View File

@ -28,6 +28,7 @@ define(
function addRoot(models) { function addRoot(models) {
models.ROOT = { models.ROOT = {
name: "The root object", name: "The root object",
type: "root",
composition: ids composition: ids
}; };
return models; return models;

View File

@ -32,25 +32,43 @@ define(
* @param {ViewDefinition[]} views an array of view extensions * @param {ViewDefinition[]} views an array of view extensions
*/ */
function MCTRepresentation(representations, views, representers, $q, $log) { function MCTRepresentation(representations, views, representers, $q, $log) {
var pathMap = {}, var representationMap = {},
representationMap = {},
gestureMap = {}; gestureMap = {};
// Assemble all representations and views // Assemble all representations and views
// The distinction between views and representations is // The distinction between views and representations is
// not important her (view is-a representation) // not important her (view is-a representation)
representations.concat(views).forEach(function (representation) { representations.concat(views).forEach(function (representation) {
var path = [ var key = representation.key;
// Store the representation
representationMap[key] = representationMap[key] || [];
representationMap[representation.key].push(representation);
});
// Get a path to a representation
function getPath(representation) {
return [
representation.bundle.path, representation.bundle.path,
representation.bundle.resources, representation.bundle.resources,
representation.templateUrl representation.templateUrl
].join("/"); ].join("/");
}
// Consider allowing multiple templates with the same key // Look up a matching representation for this domain object
pathMap[representation.key] = path; function lookup(key, domainObject) {
representationMap[representation.key] = representation; var candidates = representationMap[key] || [],
}); type,
i;
// Filter candidates by object type
for (i = 0; i < candidates.length; i += 1) {
type = candidates[i].type;
if (!type || !domainObject ||
domainObject.getCapability('type').instanceOf(type)) {
return candidates[i];
}
}
}
function link($scope, element, attrs) { function link($scope, element, attrs) {
var activeRepresenters = representers.map(function (Representer) { var activeRepresenters = representers.map(function (Representer) {
@ -89,8 +107,8 @@ define(
// as appropriate for current representation key and // as appropriate for current representation key and
// domain object. // domain object.
function refresh() { function refresh() {
var representation = representationMap[$scope.key], var domainObject = $scope.domainObject,
domainObject = $scope.domainObject, representation = lookup($scope.key, domainObject),
uses = ((representation || {}).uses || []), uses = ((representation || {}).uses || []),
gestureKeys = ((representation || {}).gestures || []); gestureKeys = ((representation || {}).gestures || []);
@ -100,7 +118,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 = pathMap[$scope.key]; $scope.inclusion = representation && getPath(representation);
// Any existing gestures are no longer valid; release them. // Any existing gestures are no longer valid; release them.
activeRepresenters.forEach(function (activeRepresenter) { activeRepresenters.forEach(function (activeRepresenter) {