-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_sqlite.html
367 lines (319 loc) · 12.1 KB
/
old_sqlite.html
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<title>SQLite Dashboard</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/dashboard/">
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<style>
body {
font-size: .875rem;
}
.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
/* rtl:raw:
right: 0;
*/
bottom: 0;
/* rtl:remove */
left: 0;
z-index: 100; /* Behind the navbar */
padding: 48px 0 0; /* Height of navbar */
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
@media (max-width: 767.98px) {
.sidebar {
top: 5rem;
}
}
.sidebar-sticky {
position: relative;
top: 0;
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
}
.sidebar .nav-link .feather {
margin-right: 4px;
color: #727272;
}
.sidebar .nav-link.active {
color: #2470dc;
}
.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .navbar-toggler {
top: .25rem;
right: 1rem;
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
</head>
<body>
<script>
window.onload = (event) => {
console.log("Page is fully loaded");
refreshData();
};
async function refreshData() {
console.log("Refreshing data...");
document.getElementById("sql-table-loading-div").style.display = 'block';
const response = await fetch("http://127.0.0.1:8082/list", {method: "GET", headers: new Headers({'content-type': 'application/json'})})
const data = await response.json();
clearTable();
buildSqlTable(data);
}
async function submitRec() {
let fnameValue = document.getElementById("fname-input").value
let lnameValue = document.getElementById("lname-input").value
let emailValue = document.getElementById("email-input").value
console.log("Submitting Record for: " + fnameValue + " " + lnameValue + " with email: " + emailValue + ".")
let insertUrl = "http://127.0.0.1:8082/insert" + "?fname=" + fnameValue + "&lname=" + lnameValue + "&email=" + emailValue
const response = await fetch(insertUrl, {method: "POST"})
const data = await response.json();
document.getElementById("fname-input").value = ""
document.getElementById("lname-input").value = ""
document.getElementById("email-input").value = ""
refreshData();
}
async function searchRecs() {
let searchValue = document.getElementById("searchbox").value
let searchUrl = "http://127.0.0.1:8082/search" + "?value=" + searchValue
const response = await fetch(searchUrl, {method: "GET"})
const data = await response.json();
clearTable();
buildSqlTable(data);
}
async function deleteRec(recId) {
let deleteUrl = "http://127.0.0.1:8082/delete" + "?id=" + recId
const response = await fetch(deleteUrl, {method: "DELETE"})
const data = await response.json();
refreshData();
}
async function prepEditRecord(recId) {
clearModal();
const listOneUrl = "http://127.0.0.1:8082/listOne" + "?id=" + recId
const response = await fetch(listOneUrl, {method: "GET"})
const data = await response.json();
document.getElementById("id-edit-input").value = data[0]['id'];
document.getElementById("fname-edit-input").value = data[0]['fname'];
document.getElementById("lname-edit-input").value = data[0]['lname'];
document.getElementById("email-edit-input").value = data[0]['email_addr'];
}
function clearModal() {
// Remove all values from the editbox modal
document.getElementById("id-edit-input").value = ""
document.getElementById("fname-edit-input").value = "";
document.getElementById("lname-edit-input").value = ""
document.getElementById("email-edit-input").value = "";
}
function clearTable() {
// Remove all rows from tbody
document.getElementById("sql-table-body").innerHTML = '';
}
async function saveChanges() {
const recId = document.getElementById("id-edit-input").value;
const fnameEdit = document.getElementById("fname-edit-input").value;
const lnameEdit = document.getElementById("lname-edit-input").value;
const emailEdit = document.getElementById("email-edit-input").value;
let saveUrl = "http://127.0.0.1:8082/update" + "?id=" + recId + "&fname=" + fnameEdit + "&lname=" + lnameEdit + "&email=" + emailEdit
const response = await fetch(saveUrl, {method: "PATCH"})
const data = await response.json();
var myModalEl = document.getElementById('edit-record-modal');
var modal = bootstrap.Modal.getInstance(myModalEl)
modal.hide();
refreshData();
}
function buildSqlTable(jsonData) {
var tbody = document.getElementById("sql-table-body");
for (var a = 0; a < jsonData.length; a++) {
var row = tbody.insertRow(tbody.rows.length);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
cell1.innerHTML = jsonData[a]['id'];
cell2.innerHTML = jsonData[a]['fname'];
cell3.innerHTML = jsonData[a]['lname'];
cell4.innerHTML = jsonData[a]['email_addr'];
cell5.innerHTML = '<button type="button" class="btn btn-danger btn-sm" onClick="deleteRec('+jsonData[a]['id']+')">Delete</button> <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#edit-record-modal" onClick="prepEditRecord('+jsonData[a]['id']+')">Edit</button>'
document.getElementById("sql-table-loading-div").style.display = 'none';
}
}
</script>
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">SQLite Database</a>
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" id="searchbox" aria-label="Search" autocomplete="off">
</header>
<div class="container-fluid">
<div class="row">
<nav id="sidebarMenu" class="col-md-2 col-lg-1 d-md-block bg-light sidebar collapse">
<div class="position-sticky pt-3">
</div>
</nav>
<main class="col-md-10 ms-sm-auto col-lg-11 px-md-4">
<!--<canvas class="my-4 w-100" id="myChart" width="900" height="380"></canvas>-->
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h2>TestTable View</h2>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<button type="button" class="btn btn-sm btn-outline-secondary" onClick="clearTable()">Clear</button>
<button type="button" class="btn btn-sm btn-outline-secondary" onClick="refreshData()">Refresh</button>
</div>
</div>
</div>
<div class="table-responsive" id="sql-table-div">
<table class="table table-striped table-sm" id="sql-table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Email Address</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody id="sql-table-body">
<tr>
<td>1,001</td>
<td>random</td>
<td>data</td>
<td>placeholder</td>
<td><button type="button" class="btn btn-danger btn-sm" onClick="deleteRec()">Delete</button> <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#edit-record-modal" onClick="prepEditRecord()">Edit</button></td>
</tr>
</tbody>
</table>
<div class="spinner-border text-primary" role="status" id="sql-table-loading-div" style="display:none">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Add Record</h1>
</div>
<div class="bd-example">
<form class="row g-3">
<div class="col-md-4">
<label for="validationServer01" class="form-label">First name</label>
<input type="text" class="form-control" id="fname-input" value="" autocomplete="off" required>
</div>
<div class="col-md-4">
<label for="validationServer02" class="form-label">Last name</label>
<input type="text" class="form-control" id="lname-input" value="" autocomplete="off" required>
</div>
<div class="col-md-4">
<label for="validationServerUsername" class="form-label">Email Address</label>
<div class="input-group has-validation">
<input type="text" class="form-control" id="email-input" aria-describedby="inputGroupPrepend3" autocomplete="off" required>
</div>
</div>
<div class="col-12">
<button class="btn btn-primary" type="button" onClick="submitRec()">Submit Record</button>
</div>
</form>
</div>
</main>
</div>
</div>
<script>
document.getElementById("searchbox").addEventListener("keyup", (event) => {
if (event.keyCode == 13) {
searchRecs();
}
});
</script>
<script src="bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
<div class="modal fade" id="edit-record-modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Record</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input type="text" class="form-control" id="id-edit-input" value="" autocomplete="off" hidden>
<div class="col-md-12">
<label for="validationServer01" class="form-label">First name</label>
<input type="text" class="form-control" id="fname-edit-input" value="" autocomplete="off" required>
</div>
<div class="col-md-12">
<label for="validationServer02" class="form-label">Last name</label>
<input type="text" class="form-control" id="lname-edit-input" value="" autocomplete="off" required>
</div>
<div class="col-md-12">
<label for="validationServerUsername" class="form-label">Email Address</label>
<div class="input-group has-validation">
<input type="text" class="form-control" id="email-edit-input" aria-describedby="inputGroupPrepend3" autocomplete="off" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onClick="saveChanges()">Save changes</button>
</div>
</div>
</div>
</div>
</body>
</html>