fixed some crit/major sonarqube code smells
This commit is contained in:
parent
865349ee68
commit
a2d2e8d5e0
6 changed files with 65 additions and 115 deletions
|
@ -183,8 +183,6 @@ var NodeConnection = (function (_super) {
|
|||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
};
|
||||
NodeConnection.prototype.reposition = function () {
|
||||
};
|
||||
return NodeConnection;
|
||||
}(CanvasObject));
|
||||
var NewConnection = (function (_super) {
|
||||
|
@ -251,13 +249,11 @@ var NewConnection = (function (_super) {
|
|||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
};
|
||||
NewConnection.prototype.reposition = function () {
|
||||
};
|
||||
return NewConnection;
|
||||
}(CanvasObject));
|
||||
var DiagramNode = (function (_super) {
|
||||
__extends(DiagramNode, _super);
|
||||
function DiagramNode(id, x, y, label, meta, ctx, results, logs) {
|
||||
function DiagramNode(id, x, y, label, ctx, meta, results, logs) {
|
||||
if (meta === void 0) { meta = {}; }
|
||||
if (results === void 0) { results = new Array(); }
|
||||
if (logs === void 0) { logs = new Array(); }
|
||||
|
@ -462,11 +458,11 @@ var Diagrams = (function () {
|
|||
this.deleteNodeCallback = function () { };
|
||||
this.canvas = document.getElementById(canvasId);
|
||||
if (this.canvas === null) {
|
||||
throw "Could not getElementById " + canvasId;
|
||||
throw new Error("Could not getElementById " + canvasId);
|
||||
}
|
||||
var ctx = this.canvas.getContext("2d");
|
||||
if (ctx === null) {
|
||||
throw "Could not get 2d rendering context";
|
||||
throw new Error("Could not get 2d rendering context");
|
||||
}
|
||||
_diagram = this;
|
||||
this.ctx = ctx;
|
||||
|
@ -674,7 +670,7 @@ var Diagrams = (function () {
|
|||
if (meta === void 0) { meta = {}; }
|
||||
if (results === void 0) { results = new Array(); }
|
||||
if (logs === void 0) { logs = new Array(); }
|
||||
var node = new DiagramNode(id, x, y, label, meta, this.ctx, results, logs);
|
||||
var node = new DiagramNode(id, x, y, label, this.ctx, meta, results, logs);
|
||||
this.nodes.set(id, node);
|
||||
};
|
||||
Diagrams.prototype.addConnection = function (A, B) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -209,10 +209,6 @@ class NodeConnection extends CanvasObject {
|
|||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
reposition(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class NewConnection extends CanvasObject {
|
||||
|
@ -278,10 +274,6 @@ class NewConnection extends CanvasObject {
|
|||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
reposition(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class DiagramNode extends CanvasObject {
|
||||
|
@ -316,8 +308,8 @@ class DiagramNode extends CanvasObject {
|
|||
x: number,
|
||||
y: number,
|
||||
label: string,
|
||||
meta: Object = {},
|
||||
ctx: CanvasRenderingContext2D,
|
||||
meta: Object = {},
|
||||
results: Array<string> = new Array(),
|
||||
logs: Array<string> = new Array(),
|
||||
){
|
||||
|
@ -551,11 +543,11 @@ class Diagrams {
|
|||
){
|
||||
this.canvas = document.getElementById(canvasId) as HTMLCanvasElement;
|
||||
if (this.canvas === null){
|
||||
throw `Could not getElementById ${canvasId}`;
|
||||
throw new Error(`Could not getElementById ${canvasId}`);
|
||||
}
|
||||
let ctx = this.canvas.getContext("2d");
|
||||
if (ctx === null){
|
||||
throw `Could not get 2d rendering context`
|
||||
throw new Error(`Could not get 2d rendering context`)
|
||||
}
|
||||
_diagram = this;
|
||||
this.ctx = ctx;
|
||||
|
@ -720,7 +712,7 @@ class Diagrams {
|
|||
results: Array<string> = new Array(),
|
||||
logs: Array<string> = new Array()
|
||||
){
|
||||
let node = new DiagramNode(id, x, y, label, meta, this.ctx, results, logs);
|
||||
let node = new DiagramNode(id, x, y, label, this.ctx, meta, results, logs);
|
||||
this.nodes.set(id, node);
|
||||
}
|
||||
|
||||
|
@ -759,7 +751,6 @@ class Diagrams {
|
|||
fillParent(){
|
||||
this.canvas.width = this.canvas.clientWidth;
|
||||
this.canvas.height = this.canvas.clientHeight;
|
||||
//this.draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ var urlPrefix = getURLPrefix();
|
|||
function onTypeChange(node) {
|
||||
var e_1, _a, e_2, _b;
|
||||
if (node === void 0) { node = null; }
|
||||
var urlPrefix = getURLPrefix();
|
||||
var select = document.getElementById("typeInput");
|
||||
var type = select.value;
|
||||
var var1Div = document.getElementById("var1Div");
|
||||
|
@ -44,7 +43,6 @@ function onTypeChange(node) {
|
|||
var var2Label = document.getElementById("var2Label");
|
||||
var var3Div = document.getElementById("var3Div");
|
||||
var3Div.innerHTML = "";
|
||||
var var3Label = document.getElementById("var3Label");
|
||||
var var1Value = "";
|
||||
var var2Value = "";
|
||||
if (node != null) {
|
||||
|
@ -663,10 +661,8 @@ function onTypeChange(node) {
|
|||
function onMathChange(node) {
|
||||
if (node === void 0) { node = null; }
|
||||
var var1Input = document.getElementById("var1Input");
|
||||
var var1Label = document.getElementById("var1Label");
|
||||
var var2Input = document.getElementById("var2Input");
|
||||
var var2Label = document.getElementById("var2Label");
|
||||
var var3Label = document.getElementById("var3Label");
|
||||
var var2Value = "";
|
||||
if (node != null) {
|
||||
var2Value = node.meta.var2;
|
||||
|
@ -689,13 +685,9 @@ function onConditionChange(node) {
|
|||
if (node === void 0) { node = null; }
|
||||
var var1Input = document.getElementById("var1Input");
|
||||
var var1Label = document.getElementById("var1Label");
|
||||
var var1Div = document.getElementById("var1Div");
|
||||
var var2Input = document.getElementById("var2Input");
|
||||
var var2Label = document.getElementById("var2Label");
|
||||
var var2Div = document.getElementById("var2Div");
|
||||
var2Div.innerHTML = "";
|
||||
var var3Label = document.getElementById("var3Label");
|
||||
var var3Div = document.getElementById("var3Div");
|
||||
var var1Value = "";
|
||||
var var2Value = "";
|
||||
if (node != null) {
|
||||
|
@ -709,25 +701,25 @@ function onConditionChange(node) {
|
|||
var1Label.innerHTML = "Condition";
|
||||
switch (var1Value) {
|
||||
case "lowert": {
|
||||
var var2Input_1 = document.createElement("input");
|
||||
var2Input_1.name = "var2";
|
||||
var2Input_1.id = "var2Input";
|
||||
var2Input_1.type = "number";
|
||||
var2Input_1.value = var2Value;
|
||||
var2Input_1.classList.add("form-control");
|
||||
var var2Input = document.createElement("input");
|
||||
var2Input.name = "var2";
|
||||
var2Input.id = "var2Input";
|
||||
var2Input.type = "number";
|
||||
var2Input.value = var2Value;
|
||||
var2Input.classList.add("form-control");
|
||||
var2Label.innerHTML = "Threshold";
|
||||
var2Div.appendChild(var2Input_1);
|
||||
var2Div.appendChild(var2Input);
|
||||
break;
|
||||
}
|
||||
case "highert": {
|
||||
var var2Input_2 = document.createElement("input");
|
||||
var2Input_2.name = "var2";
|
||||
var2Input_2.id = "var2Input";
|
||||
var2Input_2.type = "number";
|
||||
var2Input_2.value = var2Value;
|
||||
var2Input_2.classList.add("form-control");
|
||||
var var2Input = document.createElement("input");
|
||||
var2Input.name = "var2";
|
||||
var2Input.id = "var2Input";
|
||||
var2Input.type = "number";
|
||||
var2Input.value = var2Value;
|
||||
var2Input.classList.add("form-control");
|
||||
var2Label.innerHTML = "Threshold";
|
||||
var2Div.appendChild(var2Input_2);
|
||||
var2Div.appendChild(var2Input);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -768,8 +760,6 @@ function onBrowserlessChange(node) {
|
|||
if (node === void 0) { node = null; }
|
||||
var var1Input = document.getElementById("var1Input");
|
||||
var var1Label = document.getElementById("var1Label");
|
||||
var var1Div = document.getElementById("var1Div");
|
||||
var var2Input = document.getElementById("var2Input");
|
||||
var var2Label = document.getElementById("var2Label");
|
||||
var var2Div = document.getElementById("var2Div");
|
||||
var2Div.innerHTML = "";
|
||||
|
@ -789,37 +779,37 @@ function onBrowserlessChange(node) {
|
|||
var1Label.innerHTML = "Function";
|
||||
switch (var1Value) {
|
||||
case "gurl": {
|
||||
var var2Input_3 = document.createElement("input");
|
||||
var2Input_3.name = "var2";
|
||||
var2Input_3.id = "var2Input";
|
||||
var2Input_3.value = var2Value;
|
||||
var2Input_3.classList.add("form-control");
|
||||
var var2Input = document.createElement("input");
|
||||
var2Input.name = "var2";
|
||||
var2Input.id = "var2Input";
|
||||
var2Input.value = var2Value;
|
||||
var2Input.classList.add("form-control");
|
||||
var2Label.innerHTML = "URL";
|
||||
var2Div.appendChild(var2Input_3);
|
||||
var2Div.appendChild(var2Input);
|
||||
break;
|
||||
}
|
||||
case "gurls": {
|
||||
var var2Input_4 = document.createElement("input");
|
||||
var2Input_4.name = "var2";
|
||||
var2Input_4.id = "var2Input";
|
||||
var2Input_4.value = "";
|
||||
var2Input_4.disabled = true;
|
||||
var2Input_4.classList.add("form-control");
|
||||
var var2Input = document.createElement("input");
|
||||
var2Input.name = "var2";
|
||||
var2Input.id = "var2Input";
|
||||
var2Input.value = "";
|
||||
var2Input.disabled = true;
|
||||
var2Input.classList.add("form-control");
|
||||
var2Label.innerHTML = "-";
|
||||
var2Div.appendChild(var2Input_4);
|
||||
var2Div.appendChild(var2Input);
|
||||
break;
|
||||
}
|
||||
case "func": {
|
||||
var var2Input_5 = document.createElement("textarea");
|
||||
var2Input_5.name = "var2Input";
|
||||
var2Input_5.id = "var2Input";
|
||||
var2Input_5.value = "module.exports = async ({ page, context }) => {\n await page.goto(\"https://192.168.178.254:8000\");\n\n const data = await page.content();\n\n return {\n data,\n type: 'text/plain', // 'application/html' 'application/json'\n };\n};";
|
||||
var2Input_5.classList.add("form-control");
|
||||
var2Input_5.rows = 15;
|
||||
var var2Input = document.createElement("textarea");
|
||||
var2Input.name = "var2Input";
|
||||
var2Input.id = "var2Input";
|
||||
var2Input.value = "module.exports = async ({ page, context }) => {\n await page.goto(\"https://192.168.178.254:8000\");\n\n const data = await page.content();\n\n return {\n data,\n type: 'text/plain', // 'application/html' 'application/json'\n };\n};";
|
||||
var2Input.classList.add("form-control");
|
||||
var2Input.rows = 15;
|
||||
var2Label.innerHTML = "Code";
|
||||
var2Div.appendChild(var2Input_5);
|
||||
var2Div.appendChild(var2Input);
|
||||
if (var2Value != "") {
|
||||
var2Input_5.value = var2Value;
|
||||
var2Input.value = var2Value;
|
||||
}
|
||||
var3Label.innerHTML = "Help";
|
||||
var helpLink1 = document.createElement("a");
|
||||
|
@ -837,16 +827,16 @@ function onBrowserlessChange(node) {
|
|||
break;
|
||||
}
|
||||
case "funcs": {
|
||||
var var2Input_6 = document.createElement("textarea");
|
||||
var2Input_6.name = "var2Input";
|
||||
var2Input_6.id = "var2Input";
|
||||
var2Input_6.value = "module.exports = async ({ page, context }) => {\n const { result } = context;\n await page.goto(result);\n\n // click something\n //await page.click(\"#elem\");\n \n // fill input\n //await page.$eval('#elem', el => el.value = 'some text');\n \n // select dropdown\n // await page.select('#elem', 'value')\n\n const data = await page.content();\n\n return {\n data,\n type: 'text/plain', // 'application/html' 'application/json'\n };\n};";
|
||||
var2Input_6.classList.add("form-control");
|
||||
var2Input_6.rows = 15;
|
||||
var var2Input = document.createElement("textarea");
|
||||
var2Input.name = "var2Input";
|
||||
var2Input.id = "var2Input";
|
||||
var2Input.value = "module.exports = async ({ page, context }) => {\n const { result } = context;\n await page.goto(result);\n\n // click something\n //await page.click(\"#elem\");\n \n // fill input\n //await page.$eval('#elem', el => el.value = 'some text');\n \n // select dropdown\n // await page.select('#elem', 'value')\n\n const data = await page.content();\n\n return {\n data,\n type: 'text/plain', // 'application/html' 'application/json'\n };\n};";
|
||||
var2Input.classList.add("form-control");
|
||||
var2Input.rows = 15;
|
||||
var2Label.innerHTML = "Code";
|
||||
var2Div.appendChild(var2Input_6);
|
||||
var2Div.appendChild(var2Input);
|
||||
if (var2Value != "") {
|
||||
var2Input_6.value = var2Value;
|
||||
var2Input.value = var2Value;
|
||||
}
|
||||
var3Label.innerHTML = "Help";
|
||||
var helpLink1 = document.createElement("a");
|
||||
|
@ -884,7 +874,6 @@ function editNode(node) {
|
|||
addFilterButton.click();
|
||||
var name = node.label;
|
||||
var type = node.meta.type;
|
||||
var var1 = node.meta.var1;
|
||||
var var2 = node.meta.var2;
|
||||
if (var2 === undefined) {
|
||||
var2 = "";
|
||||
|
@ -942,8 +931,8 @@ function editNode(node) {
|
|||
console.log("code");
|
||||
}
|
||||
else {
|
||||
result = result.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
code.innerHTML = "'" + result + "'";
|
||||
var cleanResult = result.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
code.innerHTML = "'" + cleanResult + "'";
|
||||
}
|
||||
cardDiv.appendChild(cardBody);
|
||||
pre.appendChild(code);
|
||||
|
@ -967,15 +956,7 @@ function editNode(node) {
|
|||
}
|
||||
function deleteNode(node) {
|
||||
_diagram.nodes.delete(node.id);
|
||||
for (var i = 0; i < _diagram.connections.length; i++) {
|
||||
var connection = _diagram.connections[i];
|
||||
var output = connection.output;
|
||||
var input = connection.input;
|
||||
if (node.id == output.id || node.id == input.id) {
|
||||
_diagram.connections.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
_diagram.connections = _diagram.connections.filter(function (conn) { return !(node.id == conn.input.id || node.id == conn.output.id); });
|
||||
}
|
||||
function submitEditNode(node) {
|
||||
var nameInput = document.getElementById("nameInput");
|
||||
|
@ -1072,7 +1053,6 @@ function clearCache() {
|
|||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
var data = new URLSearchParams();
|
||||
fetch(urlPrefix + "cache/clear", {
|
||||
method: "POST"
|
||||
}).then(function (response) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,7 +5,6 @@ function onTypeChange(node: DiagramNode | null = null){
|
|||
// onTypeChange handles changing of the type of a DiagramNode while editing or creating a new Node
|
||||
// It removes all input elements and each case is responsible for adding the input it needs
|
||||
// @ts-ignore
|
||||
let urlPrefix = getURLPrefix();
|
||||
let select = document.getElementById("typeInput") as HTMLSelectElement;
|
||||
let type = select.value;
|
||||
|
||||
|
@ -19,7 +18,6 @@ function onTypeChange(node: DiagramNode | null = null){
|
|||
|
||||
let var3Div = document.getElementById("var3Div") as HTMLDivElement;
|
||||
var3Div.innerHTML = "";
|
||||
let var3Label = document.getElementById("var3Label") as HTMLLabelElement;
|
||||
|
||||
let var1Value = "";
|
||||
let var2Value = "";
|
||||
|
@ -785,10 +783,8 @@ end
|
|||
function onMathChange(node: DiagramNode | null = null){
|
||||
// onMatchChange handles the changing of the inputs when type == math
|
||||
let var1Input = document.getElementById("var1Input") as HTMLSelectElement;
|
||||
let var1Label = document.getElementById("var1Label") as HTMLLabelElement;
|
||||
let var2Input = document.getElementById("var2Input") as HTMLInputElement;
|
||||
let var2Label = document.getElementById("var2Label") as HTMLLabelElement;
|
||||
let var3Label = document.getElementById("var3Label") as HTMLLabelElement;
|
||||
|
||||
let var2Value = "";
|
||||
if (node != null){
|
||||
|
@ -813,13 +809,9 @@ function onConditionChange(node: DiagramNode | null = null){
|
|||
// onConditionChange handles the changing of the inputs when type == condition
|
||||
let var1Input = document.getElementById("var1Input") as HTMLSelectElement;
|
||||
let var1Label = document.getElementById("var1Label") as HTMLLabelElement;
|
||||
let var1Div = document.getElementById("var1Div") as HTMLDivElement;
|
||||
let var2Input = document.getElementById("var2Input") as HTMLInputElement;
|
||||
let var2Label = document.getElementById("var2Label") as HTMLLabelElement;
|
||||
let var2Div = document.getElementById("var2Div") as HTMLDivElement;
|
||||
var2Div.innerHTML = "";
|
||||
let var3Label = document.getElementById("var3Label") as HTMLLabelElement;
|
||||
let var3Div = document.getElementById("var3Div") as HTMLDivElement;
|
||||
|
||||
let var1Value = "";
|
||||
let var2Value = "";
|
||||
|
@ -889,8 +881,6 @@ function onBrowserlessChange(node: DiagramNode | null = null){
|
|||
|
||||
let var1Input = document.getElementById("var1Input") as HTMLSelectElement;
|
||||
let var1Label = document.getElementById("var1Label") as HTMLLabelElement;
|
||||
let var1Div = document.getElementById("var1Div") as HTMLDivElement;
|
||||
let var2Input = document.getElementById("var2Input") as HTMLInputElement;
|
||||
let var2Label = document.getElementById("var2Label") as HTMLLabelElement;
|
||||
let var2Div = document.getElementById("var2Div") as HTMLDivElement;
|
||||
var2Div.innerHTML = "";
|
||||
|
@ -1057,8 +1047,6 @@ function editNode(node: DiagramNode){
|
|||
// @ts-ignore
|
||||
let type = node.meta.type;
|
||||
// @ts-ignore
|
||||
let var1 = node.meta.var1;
|
||||
// @ts-ignore
|
||||
let var2 = node.meta.var2;
|
||||
if (var2 === undefined){
|
||||
var2 = "";
|
||||
|
@ -1070,6 +1058,8 @@ function editNode(node: DiagramNode){
|
|||
let selectType = document.getElementById("typeInput") as HTMLSelectElement;
|
||||
selectType.value = type;
|
||||
|
||||
|
||||
|
||||
onTypeChange(node);
|
||||
let submitButton = document.getElementById("submitFilterButton") as HTMLButtonElement;
|
||||
submitButton.innerHTML = "Save";
|
||||
|
@ -1080,7 +1070,7 @@ function editNode(node: DiagramNode){
|
|||
} else {
|
||||
logHeader.innerHTML = "";
|
||||
}
|
||||
let logBody = document.getElementById("logTableBody") as HTMLElement;
|
||||
let logBody = document.getElementById("logTableBody") as HTMLTableSectionElement;
|
||||
logBody.innerHTML = "";
|
||||
for (let log of node.logs){
|
||||
let row = document.createElement("tr");
|
||||
|
@ -1109,8 +1099,8 @@ function editNode(node: DiagramNode){
|
|||
code = showResultLink;
|
||||
console.log("code");
|
||||
} else {
|
||||
result = result.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
code.innerHTML = `'${result}'`;
|
||||
let cleanResult = result.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
code.innerHTML = `'${cleanResult}'`;
|
||||
}
|
||||
cardDiv.appendChild(cardBody);
|
||||
pre.appendChild(code);
|
||||
|
@ -1123,15 +1113,9 @@ function editNode(node: DiagramNode){
|
|||
function deleteNode(node: DiagramNode){
|
||||
// deleteNode deletes a node from _diagram and removes all connections to/from it
|
||||
_diagram.nodes.delete(node.id)
|
||||
for (let i = 0; i < _diagram.connections.length; i++){
|
||||
let connection = _diagram.connections[i];
|
||||
let output = connection.output;
|
||||
let input = connection.input;
|
||||
if (node.id == output.id || node.id == input.id){
|
||||
_diagram.connections.splice(i, 1)
|
||||
i--;
|
||||
}
|
||||
}
|
||||
_diagram.connections = _diagram.connections.filter(
|
||||
conn => !(node.id == conn.input.id || node.id == conn.output.id)
|
||||
);
|
||||
}
|
||||
|
||||
function submitEditNode(node: DiagramNode){
|
||||
|
@ -1235,7 +1219,6 @@ function clearCache(){
|
|||
if (!confirmed){
|
||||
return // do nothing
|
||||
}
|
||||
let data = new URLSearchParams();
|
||||
fetch(urlPrefix+"cache/clear", {
|
||||
method: "POST"
|
||||
}).then((response) => {
|
||||
|
@ -1247,7 +1230,7 @@ function clearCache(){
|
|||
});
|
||||
}
|
||||
function clearCacheButtonInit(){
|
||||
let clearCacheButton = document.getElementById("clearCacheButton") as HTMLElement;
|
||||
let clearCacheButton = document.getElementById("clearCacheButton") as HTMLButtonElement;
|
||||
clearCacheButton.onclick = clearCache;
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', clearCacheButtonInit, false);
|
Loading…
Add table
Reference in a new issue