X-Git-Url: https://git.auder.net/pieces/Cwda/c_white_knight.svg?a=blobdiff_plain;f=parser.js;h=0ab6a4321a15f59a62718d39cbfc699d17563e39;hb=6248a547ea724aaad739fdd224cbb40343f39e8b;hp=65ac9ec1fcb9ed8c3f2823707cb476650fcf9b1a;hpb=2a12fea9e4863a6d6d800c7d35fc31f4bbc87e4f;p=erdiag.git diff --git a/parser.js b/parser.js index 65ac9ec..0ab6a43 100644 --- a/parser.js +++ b/parser.js @@ -1,7 +1,7 @@ // ER diagram description parser class ErDiags { - constructor(description) + constructor(description, output, image) { this.entities = { }; this.inheritances = [ ]; @@ -9,10 +9,8 @@ class ErDiags this.tables = { }; this.mcdParsing(description); this.mldParsing(); - // Cache SVG graphs returned by server (in addition to server cache = good perfs) - this.mcdGraph = ""; - this.mldGraph = ""; - this.sqlText = ""; + this.output = output || "graph"; + this.image = image || "svg"; } static CARDINAL(symbol) @@ -170,10 +168,12 @@ class ErDiags name: attr.name, type: attr.type, isKey: attr.isKey, - qualifiers: attr.qualifiers, }; - if (!!attr.qualifiers && !!attr.qualifiers.match(/foreign/i)) + if (!!attr.qualifiers && !!attr.qualifiers.match(/references/i)) + { Object.assign(newField, {ref: attr.qualifiers.match(/references ([^\s]+)/i)[1]}); + newField.qualifiers = attr.qualifiers.replace(/references [^\s]+/i, ""); + } newTable.push(newField); }); this.tables[name] = newTable; @@ -187,8 +187,8 @@ class ErDiags 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, + qualifiers: this.tables[inh.parent][idx].qualifiers || "", + ref: inh.parent + "(" + this.tables[inh.parent][idx].name + ")", }); }); }); @@ -213,8 +213,8 @@ class ErDiags isKey: isKey, name: e2.name + "_" + attr.name, type: attr.type, - qualifiers: "foreign key references " + e2.name + " " + (!isKey && e.card[0]=='1' ? "not null" : ""), - ref: e2.name, //easier drawMld function (fewer regexps) + qualifiers: !isKey && e.card[0]=='1' ? "not null" : "", + ref: e2.name + "(" + attr.name + ")", }); } }); @@ -243,8 +243,8 @@ class ErDiags name: item.entity + "_" + f.name, isKey: true, type: f.type, - qualifiers: (f.qualifiers || "") + " foreign key references " + item.entity, - ref: item.entity, + qualifiers: f.qualifiers || "", + ref: item.entity + "(" + f.name + ")", }); }); }); @@ -282,28 +282,12 @@ class ErDiags // DRAWING + GET SQL FROM PARSING ///////////////////////////////// - static AjaxGet(dotInput, callback) - { - let xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) - callback(this.responseText); - }; - xhr.open("GET", "scripts/getGraphSvg.php?dot=" + encodeURIComponent(dotInput), true); - xhr.send(); - } - // "Modèle conceptuel des données". TODO: option for graph size // NOTE: randomizing helps to obtain better graphs (sometimes) drawMcd(id, mcdStyle) //mcdStyle: bubble, or compact { let element = document.getElementById(id); mcdStyle = mcdStyle || "compact"; - if (this.mcdGraph.length > 0) - { - element.innerHTML = this.mcdGraph; - return; - } // Build dot graph input let mcdDot = 'graph {\n'; mcdDot += 'rankdir="LR";\n'; @@ -417,23 +401,16 @@ class ErDiags }); }); mcdDot += '}'; - //console.log(mcdDot); - ErDiags.AjaxGet(mcdDot, graphSvg => { - this.mcdGraph = graphSvg; - element.innerHTML = graphSvg; - }); + if (this.output == "graph") //draw graph in element + element.innerHTML = ""; + else //output = "text": just show dot input + element.innerHTML = mcdDot.replace(//g,">"); } // "Modèle logique des données", from MCD without anomalies - // TODO: this one should draw links from foreign keys to keys (port=... in
" + sqlText + "
";
}