Fix bugs, update TODO list
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 2 Feb 2018 19:14:10 +0000 (20:14 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 2 Feb 2018 19:14:10 +0000 (20:14 +0100)
.gitignore
README.md
parser.js

index 1377554..6b59895 100644 (file)
@@ -1 +1,3 @@
 *.swp
+#index.html for local tests
+index.html
index 4806b37..f4e75d1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -5,14 +5,6 @@ Inspired by [this repository](https://code.google.com/archive/p/merisier/).
 This parser reads ER diagrams definition files, and produces two types of diagrams + SQL code.
 [Graphviz](https://www.graphviz.org/) is used on server side to translate parsed graph descriptions into SVG objects.
 
-**TODO** list:
-
- - functional integrity constraints (CIF),
- - inter-relations constraints (or, and, xor...),
- - inheritance with the right symbol (triangle).
-
-*Note:* temporary dependency to [underscore](http://underscorejs.org/); good library but used so far only for its shuffle() method.
-
 -----
 
 An entity is defined as follow
@@ -63,3 +55,14 @@ Finally, blocks must be separated by new lines. For a usage example, see example
 Note that the "drawMcd" method can take a second argument, which indicates the type of graph.
  * "bubble" draws the standard graph, as seen [here](https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#/media/File:ER_Diagram_MMORPG.png) for example
  * "compact" (default) use the same box for an entity and its attributes
+
+-----
+
+**TODO** list:
+
+ - functional integrity constraints (CIF)
+ - inter-relations constraints (or, and, xor...)
+ - inheritance with the right symbol (triangle)
+ - put online somewhere (user enter graph description and get SVG + SQL)
+
+*Implementation note:* temporary dependency to [underscore](http://underscorejs.org/); good library but used so far only for its shuffle() method.
index 41eff93..f41a755 100644 (file)
--- a/parser.js
+++ b/parser.js
@@ -89,7 +89,7 @@ class ErDiags
        // attributes: ArrayOf {name, [isKey], [type], [qualifiers]}
        parseAttributes(lines, start, end)
        {
-               let attributes = [];
+               let attributes = [ ];
                for (let i=start; i<end; i++)
                {
                        let field = { };
@@ -199,7 +199,7 @@ class ErDiags
                                        a.entities.forEach( e2 => {
                                                if (e2.name == e.name)
                                                        return;
-                                               e2.attributes.forEach( attr => {
+                                               this.entities[e2.name].attributes.forEach( attr => {
                                                        if (attr.isKey)
                                                        {
                                                                this.tables[e.name].push({
@@ -242,7 +242,7 @@ class ErDiags
                                        });
                                });
                                // Add relationship potential own attributes
-                               a.attributes.forEach( attr => {
+                               (a.attributes || [ ]).forEach( attr => {
                                        newTable.fields.push({
                                                name: attr.name,
                                                isKey: false,