X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=inline;f=parser.js;h=d6cee80cab3350e63d20bd40f8cb937e70944426;hb=b06f8fe6700d326e5bfae39e01a6ec58c1f46680;hp=3d31d8dbaa505eeb8e738f7b837cd36cf5d61b03;hpb=79de03374d902dfea55cf8bca5c9e0e07f976a58;p=erdiag.git
diff --git a/parser.js b/parser.js
index 3d31d8d..d6cee80 100644
--- a/parser.js
+++ b/parser.js
@@ -1,7 +1,7 @@
// ER diagram description parser
class ErDiags
{
- constructor(description, callDot)
+ constructor(description, output, image)
{
this.entities = { };
this.inheritances = [ ];
@@ -9,14 +9,8 @@ class ErDiags
this.tables = { };
this.mcdParsing(description);
this.mldParsing();
- 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 = "";
+ this.output = output || "compact";
+ this.image = image || "svg";
}
static CARDINAL(symbol)
@@ -174,12 +168,11 @@ class ErDiags
name: attr.name,
type: attr.type,
isKey: attr.isKey,
- qualifiers: attr.qualifiers,
};
if (!!attr.qualifiers && !!attr.qualifiers.match(/references/i))
{
Object.assign(newField, {ref: attr.qualifiers.match(/references ([^\s]+)/i)[1]});
- attr.qualifiers = attr.qualifiers.replace(/references [^\s]+/i, "");
+ newField.qualifiers = attr.qualifiers.replace(/references [^\s]+/i, "");
}
newTable.push(newField);
});
@@ -194,8 +187,13 @@ class ErDiags
name: inh.parent + "_id",
type: this.tables[inh.parent][idx].type,
isKey: true,
+<<<<<<< HEAD
+ 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 + ")",
+>>>>>>> 40b4a9d230d105a61e22bef0a63a6e8d515524e9
});
});
});
@@ -289,28 +287,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)
- {
- element.innerHTML = this.mcdGraph;
- return;
- }
// Build dot graph input
let mcdDot = 'graph {\n';
mcdDot += 'rankdir="LR";\n';
@@ -424,14 +406,8 @@ class ErDiags
});
});
mcdDot += '}';
- if (this.callDot)
- {
- // Draw graph in element
- ErDiags.AjaxGet(mcdDot, graphSvg => {
- this.mcdGraph = graphSvg;
- element.innerHTML = graphSvg;
- });
- }
+ if (this.output == "graph") //draw graph in element
+ element.innerHTML = "";
else //just show dot input
element.innerHTML = mcdDot.replace(//g,">");
}
@@ -440,11 +416,6 @@ class ErDiags
drawMld(id)
{
let element = document.getElementById(id);
- if (!!this.mldGraph)
- {
- element.innerHTML = this.mcdGraph;
- return;
- }
// Build dot graph input (assuming foreign keys not already present...)
let mldDot = 'graph {\n';
mldDot += 'rankdir="LR";\n';
@@ -470,13 +441,8 @@ class ErDiags
});
mldDot += links + '\n';
mldDot += '}';
- if (this.callDot)
- {
- ErDiags.AjaxGet(mldDot, graphSvg => {
- this.mldGraph = graphSvg;
- element.innerHTML = graphSvg;
- });
- }
+ if (this.output == "graph")
+ element.innerHTML = "";
else
element.innerHTML = mldDot.replace(//g,">");
}