X-Git-Url: https://git.auder.net/js/img/current/gitweb.js?a=blobdiff_plain;f=parser.js;h=41eff934592d31c99143611465a7e1f001ae4f63;hb=3ca1e50c87c462e39ba19b5c7720715353315080;hp=db70f7f282e074c415a990ac1ad422b6c2683624;hpb=351d7a8448c574b40ed5d1cb488519d7b3f70ca5;p=erdiag.git diff --git a/parser.js b/parser.js index db70f7f..41eff93 100644 --- a/parser.js +++ b/parser.js @@ -9,9 +9,6 @@ class ErDiags this.tables = { }; this.mcdParsing(description); this.mldParsing(); - - console.log(this.tables); - // Cache SVG graphs returned by server (in addition to server cache = good perfs) this.mcdGraph = ""; this.mldGraph = ""; @@ -178,6 +175,20 @@ class ErDiags }); this.tables[name] = newTable; }); + // Add foreign keys information for children (inheritance). TODO: allow several levels + // NOTE: modelisation assume each child has its own table, refering parent (other options exist) + this.inheritances.forEach( inh => { + let idx = this.tables[inh.parent].findIndex( item => { return item.isKey; }); + inh.children.forEach( c => { + this.tables[c].push({ + name: inh.parent + "_id", + type: this.tables[inh.parent][idx].type, + isKey: true, + qualifiers: (this.tables[inh.parent][idx].qualifiers || "") + " foreign key references " + inh.parent, + ref: inh.parent, + }); + }); + }); // Pass 2: parse associations, add foreign keys when cardinality is 0,1 or 1,1 this.associations.forEach( a => { let newTableAttrs = [ ]; @@ -193,7 +204,7 @@ class ErDiags { this.tables[e.name].push({ isKey: e.card.length >= 2 && e.card[1] == 'R', //"weak tables" foreign keys become part of the key - name: "#" + e2.name + "_" + attr.name, + name: e2.name + "_" + attr.name, type: attr.type, qualifiers: "foreign key references " + e2.name + " " + (e.card[0]=='1' ? "not null" : ""), ref: e2.name, //easier drawMld function (fewer regexps) @@ -225,7 +236,7 @@ class ErDiags name: item.entity + "_" + f.name, isKey: true, type: f.type, - qualifiers: (f.qualifiers+" " || "") + "foreign key references " + item.entity + " not null", + qualifiers: (f.qualifiers || "") + " foreign key references " + item.entity + " not null", ref: item.entity, }); }); @@ -328,10 +339,10 @@ class ErDiags // https://www.developpez.net/forums/d1088964/general-developpement/alm/modelisation/structure-agregation-l-association-d-association/ _.shuffle(i.children).forEach( c => { if (Math.random() < 0.5) - mcdDot += '"' + c + '":name -- "' + i.parent; + mcdDot += '"' + c + '":name -- "' + i.parent + '":name [dir="forward",arrowhead="vee",'; else - mcdDot += '"' + i.parent + '":name -- "' + c; - mcdDot += '":name [dir="forward", arrowhead="vee", style="dashed"];\n'; + mcdDot += '"' + i.parent + '":name -- "' + c + '":name [dir="back",arrowtail="vee",'; + mcdDot += 'style="dashed"];\n'; }); }); // Relationships: @@ -383,7 +394,7 @@ class ErDiags }); }); mcdDot += '}'; - console.log(mcdDot); + //console.log(mcdDot); ErDiags.AjaxGet(mcdDot, graphSvg => { this.mcdGraph = graphSvg; element.innerHTML = graphSvg; @@ -402,6 +413,7 @@ class ErDiags } // Build dot graph input (assuming foreign keys not already present...) let mldDot = 'graph {\n'; + mldDot += 'rankdir="LR";\n'; mldDot += 'node [shape=plaintext];\n'; let links = ""; _.shuffle(Object.keys(this.tables)).forEach( name => { @@ -409,21 +421,31 @@ class ErDiags mldDot += '