// ER diagram description parser
class ErDiags
{
- constructor(description)
+ constructor(description, callDot)
{
this.entities = { };
this.inheritances = [ ];
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.callDot = !!callDot;
+ if (this.callDot)
+ {
+ // Cache SVG graphs returned by server (in addition to server cache = good perfs)
+ this.mcdGraph = "";
+ this.mldGraph = "";
+ }
this.sqlText = "";
}
{
let element = document.getElementById(id);
mcdStyle = mcdStyle || "compact";
- if (this.mcdGraph.length > 0)
+ if (!!this.mcdGraph)
{
element.innerHTML = this.mcdGraph;
return;
});
});
mcdDot += '}';
- //console.log(mcdDot);
- ErDiags.AjaxGet(mcdDot, graphSvg => {
- this.mcdGraph = graphSvg;
- element.innerHTML = graphSvg;
- });
+ if (this.callDot)
+ {
+ // Draw graph in element
+ ErDiags.AjaxGet(mcdDot, graphSvg => {
+ this.mcdGraph = graphSvg;
+ element.innerHTML = graphSvg;
+ });
+ }
+ else //just show dot input
+ element.innerHTML = mcdDot.replace(/</g,"<").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 <TD>)
drawMld(id)
{
let element = document.getElementById(id);
- if (this.mldGraph.length > 0)
+ if (!!this.mldGraph)
{
element.innerHTML = this.mcdGraph;
return;
mldDot += '</table>>];\n';
});
mldDot += links + '\n';
- mldDot += '}\n';
- //console.log(mldDot);
- ErDiags.AjaxGet(mldDot, graphSvg => {
- this.mldGraph = graphSvg;
- element.innerHTML = graphSvg;
- });
+ mldDot += '}';
+ if (this.callDot)
+ {
+ ErDiags.AjaxGet(mldDot, graphSvg => {
+ this.mldGraph = graphSvg;
+ element.innerHTML = graphSvg;
+ });
+ }
+ else
+ element.innerHTML = mldDot.replace(/</g,"<").replace(/>/g,">");
}
fillSql(id)
{
let element = document.getElementById(id);
- if (this.sqlText.length > 0)
+ if (!!this.sqlText)
{
element.innerHTML = this.sqlText;
return;
});
sqlText += "\n);\n";
});
- //console.log(sqlText);
this.sqlText = sqlText;
element.innerHTML = "<pre><code>" + sqlText + "</code></pre>";
}