-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsidebar.js
110 lines (103 loc) · 3.24 KB
/
sidebar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Set the width of the side navigation to 250px */
function openSchemaForm($event, table) {
document.getElementById("mySidenav").style.width = "40%";
document.querySelector(".overlay").style.display = "block";
if ($event) {
$event.stopPropagation();
}
const nameField = document.getElementById("schema-form-name");
const fieldContainer = document.getElementById("field-form-container");
if (table) {
nameField.value = table.schemaName;
fieldContainer.innerHTML = table.columns
.map(
(col) =>
`
<div class="field-row">
<input class="sidebarFieldInput" placeholder="Field Name" type="text" value="${
col.name
}" />
<select class="sidebarFieldInput">
<option>Choose Data</option>
${Object.entries(DATA_TYPES).map(
([key, value]) => `<option value=${key}>${value}</option>`
)}
</select>
<label class="letterN">N</label>
<i class="fa fa-gear" role="button" id="gear-button"></i>
<i
onclick="removeField(event)"
class="fa fa-trash-o"
style="margin-left: 20px; font-size: 20px; color: red"
></i>
</div>
`
)
.join("");
} else {
nameField.value = "";
fieldContainer.innerHTML = `
<div class="field-row">
<input class="sidebarFieldInput" placeholder="Field Name" type="text" />
<select class="sidebarFieldInput">
<option>Choose Data</option>
${Object.entries(DATA_TYPES).map(
([key, value]) => `<option value=${key}>${value}</option>`
)}
</select>
<label class="letterN">N</label>
<i class="fa fa-gear" role="button" id="gear-button"></i>
<i
onclick="removeField(event)"
class="fa fa-trash-o"
style="margin-left: 20px; font-size: 20px; color: red"
></i>
</div>
`;
}
}
/* Set the width of the side navigation to 0 */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.querySelector(".overlay").style.display = "none";
}
const fieldCreator = (index) => {
const row = document.createElement("div");
row.setAttribute("class", "field-row");
row.setAttribute("id", `${index}`);
row.insertAdjacentHTML(
"beforeend",
`
<input class="sidebarFieldInput" placeholder="Field Name" type="text" />
<select class="sidebarFieldInput">
<option>Choose Data</option>
${Object.entries(DATA_TYPES).map(
([key, value]) => `<option value=${key}>${value}</option>`
)}
</select>
<label class="letterN">N</label>
<i class="fa fa-gear" role="button" id="gear-button"></i>
<i
onclick="removeField(event)"
class="fa fa-trash-o"
style="margin-left: 20px; font-size: 20px; color: red"
></i>
`
);
return row;
};
let = fieldArray = [];
function addfield() {
fieldArray.push(fieldCreator(fieldArray.length));
updateDom();
}
function removeField($event) {
$event.target.parentNode.parentNode.removeChild($event.target.parentNode);
fieldArray = fieldArray.filter((_, i) => i === $event.target.parentNode.id);
}
function updateDom() {
document
.querySelector("#field-form-container")
.replaceChildren(...fieldArray);
}
addfield();