~bcsaller/juju-gui/graph-component

« back to all changes in this revision

Viewing changes to app/views/topology/relation.js

  • Committer: Benjamin Saller
  • Date: 2012-10-31 10:49:50 UTC
  • mfrom: (221.1.1 graph-component)
  • Revision ID: bcsaller@gmail.com-20121031104950-d12owjo40m2kcqpg
wip

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
            return topology;
28
28
        }
29
29
        topology = _;
 
30
        topology.relation_pairs = [];
30
31
        return Module;
31
32
    };
32
33
 
33
34
    Module.dataBindings = function() {
34
35
        var db = topology.db();
35
36
        return [db.relations];
36
 
    }
 
37
    };
 
38
 
 
39
    Module.update = function() {
 
40
      var db = topology.db(),
 
41
          relations = db.relations.toArray();
 
42
 
 
43
      topology.relation_pairs = Module.processRelations(relations);
 
44
    };
 
45
 
 
46
    Module.processRelations = function(rels) {
 
47
      var pairs = [];
 
48
      Y.each(rels, function(rel) {
 
49
        var pair = Module.processRelation(rel);
 
50
 
 
51
        // skip peer for now
 
52
        if (pair.length === 2) {
 
53
          var bpair = views.BoxPair()
 
54
                             .model(rel)
 
55
                             .source(pair[0][1])
 
56
                             .target(pair[1][1]);
 
57
          // Copy the relation type to the box.
 
58
          if (bpair.display_name === undefined) {
 
59
            bpair.display_name = pair[0][0];
 
60
          }
 
61
          pairs.push(bpair);
 
62
        }
 
63
      });
 
64
      return pairs;
 
65
    };
 
66
 
 
67
    Module.processRelation = function(r) {
 
68
      var endpoints = r.get('endpoints'),
 
69
          rel_services = [];
 
70
 
 
71
      Y.each(endpoints, function(ep) {
 
72
        rel_services.push([ep[1].name, topology.service_boxes[ep[0]]]);
 
73
      });
 
74
      return rel_services;
 
75
    };
37
76
 
38
77
    /*
39
78
     * Event handler for clicking the 'add relation' item on the service