| Index: app/views/topology/relation.js |
| === modified file 'app/views/topology/relation.js' |
| --- app/views/topology/relation.js 2013-01-24 16:10:04 +0000 |
| +++ app/views/topology/relation.js 2013-01-24 19:02:40 +0000 |
| @@ -54,7 +54,7 @@ |
| initializer: function(options) { |
| RelationModule.superclass.constructor.apply(this, arguments); |
| - this.relPairs = []; |
| + this.relations = []; |
| }, |
| render: function() { |
| @@ -69,8 +69,7 @@ |
| var db = topo.get('db'); |
| var self = this; |
| var relations = db.relations.toArray(); |
| - this.relPairs = this.processRelations(relations); |
| - topo.relPairs = this.relPairs; |
| + this.relations = this.decorateRelations(relations); |
| this.updateLinks(); |
| this.updateSubordinateRelationsCount(); |
| @@ -86,38 +85,44 @@ |
| this.update(); |
| }, |
| - processRelation: function(r) { |
| + processRelation: function(relation) { |
| var self = this; |
| var topo = self.get('component'); |
| - var endpoints = r.get('endpoints'); |
| + var endpoints = relation.get('endpoints'); |
| var rel_services = []; |
| - Y.each(endpoints, function(ep) { |
| - rel_services.push([ep[1].name, topo.service_boxes[ep[0]]]); |
| + Y.each(endpoints, function(endpoint) { |
| + rel_services.push([endpoint[1].name, topo.service_boxes[endpoint[0]]]); |
| }); |
| return rel_services; |
| }, |
| - processRelations: function(rels) { |
| + /** |
| + * |
| + * @method decorateRelations |
| + * @param {Array} relations The relations currently in effect. |
| + * @return {Array} Relation pairs. |
| + */ |
| + decorateRelations: function(relations) { |
| var self = this; |
| - var pairs = []; |
| - Y.each(rels, function(rel) { |
| - var pair = self.processRelation(rel); |
| + var decorated = []; |
| + Y.each(relations, function(relation) { |
| + var pair = self.processRelation(relation); |
| // skip peer for now |
| if (pair.length === 2) { |
| - var bpair = views.BoxPair() |
| - .model(rel) |
| - .source(pair[0][1]) |
| - .target(pair[1][1]); |
| + var source = pair[0][1]; |
| + var target = pair[1][1]; |
| + var decoratedRelation = views.DecoratedRelation( |
| + relation, source, target); |
| // Copy the relation type to the box. |
| - if (bpair.display_name === undefined) { |
| - bpair.display_name = pair[0][0]; |
| + if (decoratedRelation.display_name === undefined) { |
| + decoratedRelation.display_name = pair[0][0]; |
| } |
| - pairs.push(bpair); |
| + decorated.push(decoratedRelation); |
| } |
| }); |
| - return pairs; |
| + return decorated; |
| }, |
| updateLinks: function() { |
| @@ -141,13 +146,13 @@ |
| updateLinkEndpoints: function(evt) { |
| var self = this; |
| var service = evt.service; |
| - Y.each(Y.Array.filter(self.relPairs, function(relation) { |
| - return relation.source().id === service.id || |
| - relation.target().id === service.id; |
| + Y.each(Y.Array.filter(self.relations, function(relation) { |
| + return relation.source.id === service.id || |
| + relation.target.id === service.id; |
| }), function(relation) { |
| var rel_group = d3.select('#' + relation.id); |
| - var connectors = relation.source() |
| - .getConnectorPair(relation.target()); |
| + var connectors = relation.source |
| + .getConnectorPair(relation.target); |
| var s = connectors[0]; |
| var t = connectors[1]; |
| rel_group.select('line') |
| @@ -171,8 +176,9 @@ |
| var self = this; |
| var vis = this.get('component').vis; |
| var g = vis.selectAll('g.rel-group') |
| - .data(self.relPairs, function(r) { |
| - return r.modelIds(); |
| + .data(self.relations, |
| + function(r) { |
| + return r.compositeId; |
| }); |
| var enter = g.enter(); |
| @@ -183,15 +189,14 @@ |
| }) |
| .attr('class', function(d) { |
| // Mark the rel-group as a subordinate relation if need be. |
| - return (d.scope === 'container' ? |
| - 'subordinate-rel-group ' : '') + |
| + return (d.isSubordinate ? 'subordinate-rel-group ' : '') + |
| 'rel-group'; |
| }) |
| .append('svg:line', 'g.service') |
| .attr('class', function(d) { |
| // Style relation lines differently depending on status. |
| return (d.pending ? 'pending-relation ' : '') + |
| - (d.scope === 'container' ? 'subordinate-relation ' : '') + |
| + (d.isSubordinate ? 'subordinate-relation ' : '') + |
| 'relation'; |
| }); |
| @@ -202,7 +207,7 @@ |
| .attr('class', 'rel-label') |
| .attr('transform', function(d) { |
| // XXX: This has to happen on update, not enter |
| - var connectors = d.source().getConnectorPair(d.target()); |
| + var connectors = d.source.getConnectorPair(d.target); |
| var s = connectors[0]; |
| var t = connectors[1]; |
| return 'translate(' + |
| @@ -230,8 +235,8 @@ |
| }, |
| drawRelation: function(relation) { |
| - var connectors = relation.source() |
| - .getConnectorPair(relation.target()); |
| + var connectors = relation.source |
| + .getConnectorPair(relation.target); |
| var s = connectors[0]; |
| var t = connectors[1]; |
| var link = d3.select(this); |
| @@ -767,12 +772,12 @@ |
| }, |
| /* |
| - * Utility function to get subordinate relations for a service. |
| - */ |
| + * Utility function to get subordinate relations for a service. |
| + */ |
| subordinateRelationsForService: function(service) { |
| - return this.relPairs.filter(function(p) { |
| - return (p.source() === service || p.target() === service) && |
| - p.scope === 'container'; |
| + return this.relations.filter(function(relation) { |
| + return (relation.source === service || relation.target === service) && |
| + relation.isSubordinate; |
| }); |
| }, |
| @@ -834,7 +839,7 @@ |
| }, |
| relationClick: function(d, self) { |
| - if (d.scope === 'container') { |
| + if (d.isSubordinate) { |
| var subRelDialog = views.createModalPanel( |
| 'You may not remove a subordinate relation.', |
| '#rmsubrelation-modal-panel'); |