-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-book.html
495 lines (471 loc) · 17.2 KB
/
add-book.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
<!--
Bug 0 - 30/11/2021 - Added a close button at the ends of Reportoire.
Bug 1 - 30/11/2021 - Changed data array to Object and Iterating over it. Removing need for ID's to be consecutive
Bug 2 - 30/11/2021 - Added id's to the footer
Bug 6 - 31/11/2021 - Added Footer to Add book page. Provided functionality to fetch data from the database and display it upon click on footer links of Book Ids.
Bug 7 - 31/11/2021 - Removed Scrollbar from Add Book page.
Bug 8 - 31/11/2021 - Added custom Scrollbar
Bug 10 - Added moving background image with books
Bug 11 -04/12/2021 - Make site responsive
Bug 12 - 04/12/2021 - Added Bootstrap and jquery dist files to the project.
Bug 13 - 04/12/2021 - Toastr messages were coming white due to Bootstrap interference. Moved after the Bootstrap files.
Bug 14 - 04/12/2021 - Added Toastr dist files to the project.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<!--Bug 11 above line-->
<title>AddBook</title>
<!-- <link
href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css"
rel="stylesheet"
/> -->
<!-- Bug 12
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/> -->
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"
/>
<!-- <link
href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css"
rel="stylesheet"
/> -->
<link rel="stylesheet" href="assets/bootstrap.min.css" />
<!-- Bug 14 starts-->
<!-- Bug 13 -->
<!-- <link
href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css"
rel="stylesheet"
/> -->
<link rel="stylesheet" href="assets/toastr.min.css" />
<!-- Bug 14 ends-->
<!--Bug 12 above line-->
<!-- Toastr Library Ends -->
<link rel="stylesheet" href="shared.css" />
<link rel="stylesheet" href="add-book.css" />
<!-- <script>
window.myVar = '{{ env(MY_VAR) }}';
</script> -->
</head>
<body class="scrollbar">
<!-- Bug 7 -->
<header id="header">
<div id="page-logo">
<a href="/index.html">Library</a>
</div>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li>
<a href="https://contact-ekansh.herokuapp.com/">Contact Us</a>
</li>
<li><a href="https://github.com/CAPTAINCOBRA">About</a></li>
</ul>
</nav>
</header>
<!-- <form class="row p-5"> -->
<div class="form-container">
<div class="mb-3 col-5 pair form-floating col-sm-5 col-lg-10 col-md-7">
<input
required
placeholder="Title"
class="form-control form-control-sm"
type="text"
id="Titlebox"
/>
<label class="form-label">Title</label>
</div>
<div class="mb-3 col-5 pair form-floating col-sm-5 col-lg-10 col-md-7">
<input
required
placeholder="Author"
class="form-control"
type="text"
id="Authorbox"
/>
<label class="form-label">Author</label>
</div>
<div class="mb-3 col-5 pair form-floating col-sm-5 col-lg-10 col-md-7">
<input
required
placeholder="Image"
class="form-control"
type="url"
id="Imagebox"
/>
<label class="form-label">Image</label>
</div>
<div class="mb-3 col-5 pair form-floating col-sm-5 col-lg-10 col-md-7">
<input
required
placeholder="Id"
class="form-control"
type="number"
id="Idbox"
/>
<label class="form-label">Id</label>
<!-- <div class="invalid-id small"> //Bug 1 - Removed this div
Please don't change the id while adding.
</div> -->
</div>
<div class="mb-3 col-5 pair form-floating col-sm-5 col-lg-10 col-md-7">
<textarea
required
placeholder="Description"
rows="4"
class="form-control"
type="text"
id="Descbox"
style="height: auto"
></textarea>
<label class="form-label">Description</label>
</div>
<div class="buttonTray">
<button id="instBtn" class="btn btn-success col-5 btn-x" type="submit">
Add
</button>
<button id="fetchBtn" class="btn btn-primary col-5 btn-x" type="submit">
Fetch
</button>
<button
id="updateBtn"
class="btn btn-warning col-5 btn-x"
type="submit"
>
Update
</button>
<button id="deleteBtn" class="btn btn-danger col-5 btn-x" type="submit">
Delete
</button>
</div>
<!-- <button id="instBtn" class="btn btn-primary col-2 mx-auto" formaction="/">
Home
</button> -->
</div>
<!-- </form> -->
<!-- Bug 6 starts -->
<footer id="footer">
<ul id="footer-ul">
<li>
<a href="https://www.instagram.com">
<img src="images/icons/insta.png" alt="Instagram logo"
/></a>
</li>
<li>
<a href="https://www.facebook.com">
<img src="images/icons/facebook.png" alt="Facebook logo"
/></a>
</li>
</ul>
</footer>
<!-- Bug 6 ends -->
<!--Bug 12 Below-->
<script src="./assets/jquery-3.5.1.min.js"></script>
<script type="module">
//-----------------Firebase Config---------------------------------
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.5.0/firebase-app.js";
const firebaseConfig = {
apiKey: "AIzaSyAwumkhm8FXf9gqxJamWDfKB2810--fOxk",
authDomain: "library-83403.firebaseapp.com",
databaseURL:
"https://library-83403-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "library-83403",
storageBucket: "library-83403.appspot.com",
messagingSenderId: "801479317930",
appId: "1:801479317930:web:4dcf61be9e2f45d44133d3",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
import {
getDatabase,
ref,
set,
child,
update,
remove,
get,
} from "https://www.gstatic.com/firebasejs/9.5.0/firebase-database.js";
const db = getDatabase();
//------------------References---------------------------------------
var titlebox = document.getElementById("Titlebox");
var authorbox = document.getElementById("Authorbox");
var imagebox = document.getElementById("Imagebox");
var descbox = document.getElementById("Descbox");
var idbox = document.getElementById("Idbox");
var instBtn = document.getElementById("instBtn");
var fetchBtn = document.getElementById("fetchBtn");
var updateBtn = document.getElementById("updateBtn");
var deleteBtn = document.getElementById("deleteBtn");
//-------------------INSERT Data -------------------------------------------------
function InsertData() {
try {
let idValue = idbox.value;
if (idValue == "" || idValue == undefined || idValue == null) {
alert("Please enter the ID 101!");
return;
}
} catch (error) {
console.log(Error);
}
//Check if data exists starts
const dbref = ref(db);
get(child(dbref, "books/" + idbox.value))
.then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
alert(
"Data for this ID already exists! \n Book name is - " +
snapshot.val().name +
". Please use another ID"
);
} else {
// alert("No data found!");
try {
console.log(titlebox.value);
console.log(authorbox.value);
console.log(imagebox.value);
console.log(descbox.value);
set(ref(db, "books/" + idbox.value), {
name: titlebox.value,
author: authorbox.value,
image: imagebox.value,
// id: idbox.value,
description: descbox.value,
})
.then(() => {
alert("Data stored successfully");
authorbox.value = "";
titlebox.value = "";
imagebox.value = "";
descbox.value = "";
// idbox.value = idbox.value + 1; //Bug 1
idbox.value = ""; //Bug 1
party.confetti(instBtn, {
// count: party.variation.range(50000, 40000),
count: party.variation.range(5000, 5000),
});
toastr.success(
"The book has been added successfully!.",
"Success"
);
})
.catch((error) => {
alert("unsuccessful, error. Code 101!");
});
} catch (error) {
console.log(error);
alert(error);
}
}
})
.catch((error) => {
alert("unsuccessful, error. Code102!");
});
//Check if the data already exists ends
}
//-------------------FETCH Data -------------------------------------------------
function fetchData() {
try {
let idValue = idbox.value;
if (idValue == "" || idValue == undefined || idValue == null) {
alert("Please enter the ID 102!");
return;
}
} catch (error) {
console.log(Error);
}
const dbref = ref(db);
get(child(dbref, "books/" + idbox.value))
.then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
titlebox.value = snapshot.val().name;
authorbox.value = snapshot.val().author;
imagebox.value = snapshot.val().image;
descbox.value = snapshot.val().description;
// party.confetti(fetchBtn, {
// // count: party.variation.range(50000, 40000),
// count: party.variation.range(5000, 5000),
// });
toastr.info("Book fetched successfully!", "Fetched!");
} else {
alert("No data found!");
}
})
.catch((error) => {
alert("unsuccessful, error. Code 103!");
});
}
//-------------------UPDATE Data -------------------------------------------------
function updateData() {
try {
let idValue = idbox.value;
if (idValue == "" || idValue == undefined || idValue == null) {
alert("Please enter the ID 103!");
return;
}
} catch (error) {
console.log(Error);
}
try {
console.log(titlebox.value);
console.log(authorbox.value);
console.log(imagebox.value);
console.log(descbox.value);
update(ref(db, "books/" + idbox.value), {
name: titlebox.value,
author: authorbox.value,
image: imagebox.value,
// id: idbox.value,
description: descbox.value,
})
.then(() => {
// toastr.success("Data updated successfully");
// party.confetti(updateBtn, {
// // count: party.variation.range(50000, 40000),
// count: party.variation.range(500, 500),
// });
// alert("Data updated successfully");
toastr.warning("The book has been updated.", "Updated");
})
.catch((error) => {
alert("unsuccessful, error. Code 104!");
});
} catch (error) {
console.log(error);
alert(error);
}
}
//-------------------DELETE Data -------------------------------------------------
function deleteData() {
try {
let idValue = idbox.value;
if (idValue == "" || idValue == undefined || idValue == null) {
alert("Please enter the ID 104!");
return;
}
} catch (error) {
console.log(Error);
}
try {
console.log(titlebox.value);
console.log(authorbox.value);
console.log(imagebox.value);
console.log(descbox.value);
remove(ref(db, "books/" + idbox.value))
.then(() => {
// alert("Data deleted successfully");
toastr.error("Book deleted successfully!", "Deleted!");
})
.catch((error) => {
alert("unsuccessful, error. Code 105!");
});
} catch (error) {
console.log(error);
alert(error);
}
}
//---------------Add Event Listener------------------------------------
instBtn.addEventListener("click", InsertData);
fetchBtn.addEventListener("click", fetchData);
updateBtn.addEventListener("click", updateData);
deleteBtn.addEventListener("click", deleteData);
//----------Test Data-----------------------------------------------------
// var listFoot = [];
$(document).ready(function () {
//Making ID consecutive or deciding ID from our side
const dbref = ref(db);
get(child(dbref, "books/"))
.then((snapshot) => {
if (snapshot.exists()) {
//Bug 6 starts
var data = snapshot.val();
const keys = Object.keys(data);
const values = Object.values(data);
console.log("Halo", data);
console.log("Alpha", values);
const ul_footer = document.createElement("ul");
ul_footer.setAttribute("class", "footer-ul");
ul_footer.setAttribute("class", "list-group");
const footer = document.getElementById("footer");
footer.appendChild(ul_footer);
keys.forEach((key) => {
const ali = document.createElement("a");
// ali.setAttribute("href", "#" + key); //Bug 5
ali.setAttribute("id", key);
ali.setAttribute("class", "lulz");
const li = document.createElement("li");
li.setAttribute("class", "list-group-item");
li.innerHTML = key + ". " + data[key].name;
// li.innerHTML = data[key].name;
ali.appendChild(li);
// ul_footer.appendChild(li);
ul_footer.appendChild(ali);
});
var listFoot = document.getElementsByClassName("lulz");
listFoot = Array.from(listFoot);
listFoot.forEach((item) => {
item.addEventListener("click", () => fetchDataFoot(item));
});
//Bug 6 ends
// //Bug 1
// console.log(snapshot.val());
// var obj = snapshot.val();
// var objLength = Object.keys(obj).length;
// // let idValue = snapshot.val();
// let idValue = objLength;
// // idValue = idValue.length + 1;
// // idValue = idValue.length;
// idbox.value = idValue;
// //Filling the ID here by ourself
// //Bug 1 ends
} else {
alert("No data found!");
}
})
.catch((error) => {
alert(
"unsuccessful, error. Code 106! Unable to fetch data from the database. Either the database is offline or your internet connection is not available. Contact the Administrator"
);
});
//ID part ends
});
// Bug 6 starts
const fetchDataFoot = (item) => {
console.log(item);
console.log(item.innerHTML);
idbox.value = item.id;
fetchData();
//navigate to header
window.location.href = "#header";
};
// Bug 6 ends
</script>
<!-- Bug 12 starts -->
<!-- <script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"
></script> -->
<!-- <script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"
></script> -->
<!-- Bug 12 ends -->
<!-- Bug 14 -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script> -->
<script src="/assets/toastr.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/party-js@latest/bundle/party.min.js"></script>
<!--Toastr-->
</body>
</html>