From 6881562630f73870aca25a0b4656e7430aabc262 Mon Sep 17 00:00:00 2001
From: Christoph Dornieden <cdor@informatik.uni-kiel.de>
Date: Fri, 17 Jun 2016 13:01:48 +0200
Subject: [PATCH] added graphing service

---
 .../architecture-visualisation-cola.js        |  2 -
 .../component.js                              |  4 +-
 .../style.js                                  |  4 +-
 app/models/baseentity.js                      |  1 +
 app/models/communication.js                   |  8 +--
 app/models/communicationinstance.js           |  6 +-
 app/models/node.js                            |  5 +-
 app/models/nodegroup.js                       |  5 +-
 app/models/service.js                         |  1 -
 app/models/serviceinstance.js                 |  4 +-
 app/routes/architectures/single.js            | 47 +++++++++-------
 app/services/graphing-service.js              | 56 +++++++++++++++++--
 12 files changed, 95 insertions(+), 48 deletions(-)

diff --git a/app/components/architecture-visualisation-cola.js b/app/components/architecture-visualisation-cola.js
index 14a538d..4c9af7c 100644
--- a/app/components/architecture-visualisation-cola.js
+++ b/app/components/architecture-visualisation-cola.js
@@ -141,5 +141,3 @@ export default Ember.Component.extend({
         // this.renderGraph();
     }
 });
-
-
diff --git a/app/components/architecture-visualisation-cytoscape/component.js b/app/components/architecture-visualisation-cytoscape/component.js
index 5858d31..13f1216 100644
--- a/app/components/architecture-visualisation-cytoscape/component.js
+++ b/app/components/architecture-visualisation-cytoscape/component.js
@@ -63,7 +63,7 @@ export default Ember.Component.extend({
 
           style: cytoscapeStyle,
 
-          elements: this.get('dummyGraph'), // TODO!
+          elements: this.get('graph'), // TODO!
 
           layout: {
             name: 'cola',
@@ -72,5 +72,3 @@ export default Ember.Component.extend({
         });
     }
 });
-
-
diff --git a/app/components/architecture-visualisation-cytoscape/style.js b/app/components/architecture-visualisation-cytoscape/style.js
index 5cfcb8b..3252616 100644
--- a/app/components/architecture-visualisation-cytoscape/style.js
+++ b/app/components/architecture-visualisation-cytoscape/style.js
@@ -3,7 +3,7 @@ export default `
 
 
 node {
-    content: data(name);
+    content: data(label);
     text-valign: center;
     text-halign: center;
 }
@@ -30,4 +30,4 @@ edge {
 }
 
 
-`;
\ No newline at end of file
+`;
diff --git a/app/models/baseentity.js b/app/models/baseentity.js
index dc29a62..23c9d13 100644
--- a/app/models/baseentity.js
+++ b/app/models/baseentity.js
@@ -3,4 +3,5 @@ import attr from 'ember-data/attr';
 
 export default Model.extend({
     // id: attr('string') - not allowed to be listed by ember
+    systemId: attr('string') 
 });
diff --git a/app/models/communication.js b/app/models/communication.js
index 859bfa0..711f3fc 100644
--- a/app/models/communication.js
+++ b/app/models/communication.js
@@ -1,10 +1,8 @@
 import BaseEntity from './baseentity';
 import attr from 'ember-data/attr';
 
-export default BaseEntity.extend({
-    system: attr('string'), // TODO: relation?
+export default BaseEntity.extend({    
     technology: attr('string'),
-    source: attr(), // FIXME relation
-    target: attr(), // FIXME relation
-    instances: attr(), // FIXME relation
+    sourceId: attr('string'),
+    targetId: attr('string')
 });
diff --git a/app/models/communicationinstance.js b/app/models/communicationinstance.js
index 2ec2e3a..bcd718d 100644
--- a/app/models/communicationinstance.js
+++ b/app/models/communicationinstance.js
@@ -2,7 +2,7 @@ import BaseEntity from './baseentity';
 import attr from 'ember-data/attr';
 
 export default BaseEntity.extend({
-    source: attr(), // FIXME relation
-    target: attr(), // FIXME relation
-    communication: attr(), // FIXME relation
+    sourceId: attr('string'),
+    targetId: attr('string'),
+    communicationId: attr('string')
 });
diff --git a/app/models/node.js b/app/models/node.js
index a218acf..8d50dbc 100644
--- a/app/models/node.js
+++ b/app/models/node.js
@@ -2,9 +2,8 @@ import BaseEntity from './baseentity';
 import attr from 'ember-data/attr';
 
 export default BaseEntity.extend({
-    name: attr(), // FIXME relation
-    services: attr(), // FIXME relation
+    name: attr('string'),
     ip: attr('string'),
     hostname: attr('string'),
-    group: attr('string'), // TODO: relation?
+    nodeGroupId: attr('string')
 });
diff --git a/app/models/nodegroup.js b/app/models/nodegroup.js
index 167a21f..eb8d434 100644
--- a/app/models/nodegroup.js
+++ b/app/models/nodegroup.js
@@ -2,7 +2,6 @@ import BaseEntity from './baseentity';
 import attr from 'ember-data/attr';
 
 export default BaseEntity.extend({
-    name: attr('string'),
-    system: attr(), // FIXME relation
-    nodes: attr() // FIXME relation
+    name: attr('string')
+
 });
diff --git a/app/models/service.js b/app/models/service.js
index f33a068..572f4e3 100644
--- a/app/models/service.js
+++ b/app/models/service.js
@@ -3,6 +3,5 @@ import attr from 'ember-data/attr';
 
 export default BaseEntity.extend({
     name: attr('string'),
-    system: attr(), // FIXME relation
     description: attr('string')
 });
diff --git a/app/models/serviceinstance.js b/app/models/serviceinstance.js
index 2899d22..e41e5a6 100644
--- a/app/models/serviceinstance.js
+++ b/app/models/serviceinstance.js
@@ -4,6 +4,6 @@ import DS from 'ember-data';
 
 export default BaseEntity.extend({
     name: attr('string'),
-    node: DS.belongsTo('node', {async: true}),
-    service: DS.belongsTo('service', {async: true})
+    nodeId: attr('string'),
+    serviceId: attr('string')
 });
diff --git a/app/routes/architectures/single.js b/app/routes/architectures/single.js
index 113eaab..606496c 100644
--- a/app/routes/architectures/single.js
+++ b/app/routes/architectures/single.js
@@ -1,25 +1,32 @@
 import Ember from 'ember';
 
 export default Ember.Route.extend({
-    session: Ember.inject.service(), // loads services/session.js
-    graphingService: Ember.inject.service(),
-    model(params) {
-        this.set('session.systemId', params.systemId); // add the system to all requests
-        const graphingService = this.get('graphingService');
-        const createGraph = graphingService.createGraph.bind(graphingService);
+  session: Ember.inject.service(), // loads services/session.js
+  graphingService: Ember.inject.service(),
+  model(params) {
+    this.set('session.systemId', params.systemId); // add the system to all requests
+    const graphingService = this.get('graphingService');
+    const createGraph = graphingService.createGraph.bind(graphingService);
 
-        this.set('loading', true);
-
-        return Ember.RSVP.Promise.all([
-            this.store.findAll('node'),
-            this.store.findAll('nodegroup'),
-            this.store.findAll('service'),
-            this.store.findAll('serviceinstance'),
-            this.store.findAll('communication'),
-            this.store.findAll('communicationinstance')
-        ]).then(createGraph).finally((graph) => {
-            this.set('loading', false);
-            return graph;
-        });
-    }
+    this.set('loading', true);
+    return Ember.RSVP.Promise.all([
+      this.store.findAll('node'),
+      this.store.findAll('nodegroup'),
+      this.store.findAll('service'),
+      this.store.findAll('serviceinstance'),
+      this.store.findAll('communication'),
+      this.store.findAll('communicationinstance')
+  ]).then(responses => {
+      return {
+        nodes: responses.get(0),
+        nodeGroups: responses.get(1),
+        services: responses.get(2),
+        serviceInstances: responses.get(3),
+        communications: responses.get(4),
+        communicationInstances: responses.get(5)
+    };}).then(createGraph).then((graph) => {
+      this.set('loading', false);
+      return graph;
+    });
+  }
 });
diff --git a/app/services/graphing-service.js b/app/services/graphing-service.js
index da002ef..a99db22 100644
--- a/app/services/graphing-service.js
+++ b/app/services/graphing-service.js
@@ -4,8 +4,56 @@ import Ember from 'ember';
  * parses a list of models and creates stores them
  */
 export default Ember.Service.extend({
-    createGraph(models) {
-        this.debug('loaded models', models);
-        return models;
-    }
+  createGraph(models) {
+    this.debug('loaded models', models);
+    const serviceInstances = models.serviceInstances;
+    const communicationInstances = models.communicationInstances;
+    const nodeGroups = models.nodeGroups;
+    const nodes = models.nodes;
+
+    var network = {
+      nodes: [],
+      edges: []
+    };
+
+    this.debug('loaded instances', serviceInstances);
+
+    nodeGroups.forEach(instance => {
+        const data = instance.toJSON({includeId: true});
+        data.label = data.name;
+
+      network.nodes.push({
+        data: data
+    });});
+
+    nodes.forEach(instance => {
+        const data = instance.toJSON({includeId: true});
+        data.label = data.name;
+        data.parent = data.nodeGroupId
+
+      network.nodes.push({
+        data: data
+    });});
+
+    serviceInstances.forEach(instance => {
+        const data = instance.toJSON({includeId: true});
+        data.label = data.name;
+        data.parent = data.nodeId;
+
+      network.nodes.push({
+        data: data
+    });});
+
+    communicationInstances.forEach(instance => {
+        const data = instance.toJSON({includeId: true});
+        data.label = data.name;
+        data.source = data.sourceId;
+        data.target = data.targetId;
+
+      network.edges.push({
+        data: data
+    });});
+
+    return network;
+  }
 });
-- 
GitLab