Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 275
London | 26-ITP-May | Edina Kurdi | Sprint 2 | Book Library#552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1e412fd25d43db626dc3d11cc3728da7a71db875d79e96d3ec121439b3ed0a28dd9945276fa65af09d6d4faebe8fe78e54fed45036ded0c0202b520bc7961be3f87fd7509788f325171a61281f96c877907a64a106ea771e93ea32596c6f5624dc39a0034603cf13dab84a871769936a61a0126e997b5e2cade9703993a0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,58 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title> </title> | ||
| <meta | ||
| charset="utf-8" | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0" | ||
| /> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | ||
| /> | ||
| <link rel="stylesheet" type="text/css" href="style.css" /> | ||
| </head> | ||
| <html lang="en"> | ||
| <body> | ||
| <div class="jumbotron text-center"> | ||
| <h1>Library</h1> | ||
| <p>Add books to your virtual library</p> | ||
| </div> | ||
| <head> | ||
| <title>Book Library</title> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" /> | ||
| <link rel="stylesheet" type="text/css" href="style.css" /> | ||
| </head> | ||
| <button data-toggle="collapse" data-target="#demo" class="btn btn-info"> | ||
| Add new book | ||
| </button> | ||
| <body> | ||
| <div class="jumbotron text-center"> | ||
| <h1>Library</h1> | ||
| <p>Add books to your virtual library</p> | ||
| </div> | ||
| <div id="demo" class="collapse"> | ||
| <div class="form-group"> | ||
| <label for="title">Title:</label> | ||
| <input | ||
| type="title" | ||
| class="form-control" | ||
| id="title" | ||
| name="title" | ||
| required | ||
| /> | ||
| <label for="author">Author: </label> | ||
| <input | ||
| type="author" | ||
| class="form-control" | ||
| id="author" | ||
| name="author" | ||
| required | ||
| /> | ||
| <label for="pages">Pages:</label> | ||
| <input | ||
| type="number" | ||
| class="form-control" | ||
| id="pages" | ||
| name="pages" | ||
| required | ||
| /> | ||
| <label class="form-check-label"> | ||
| <input | ||
| type="checkbox" | ||
| class="form-check-input" | ||
| id="check" | ||
| value="" | ||
| />Read | ||
| </label> | ||
| <input | ||
| type="submit" | ||
| value="Submit" | ||
| class="btn btn-primary" | ||
| onclick="submit();" | ||
| /> | ||
| </div> | ||
| </div> | ||
| <button type="button" data-toggle="collapse" data-target="#demo" class="btn btn-info"> | ||
| Add new book | ||
| </button> | ||
| <table class="table" id="display"> | ||
| <thead class="thead-dark"> | ||
| <tr> | ||
| <th>Title</th> | ||
| <th>Author</th> | ||
| <th>Number of Pages</th> | ||
| <th>Read</th> | ||
| <th></th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| <div id="demo" class="collapse"> | ||
| <form id="book-form" class="form-group"> | ||
| <label for="title">Title:</label> | ||
| <input type="text" class="form-control" id="title" name="title" required /> | ||
| <label for="author">Author: </label> | ||
| <input type="text" class="form-control" id="author" name="author" required /> | ||
| <label for="pages">Pages:</label> | ||
| <input type="number" class="form-control" id="pages" name="pages" min="1" step="1" required /> | ||
| <label class="form-check-label"> | ||
| <input type="checkbox" class="form-check-input" id="check" name="check" />Read | ||
| </label> | ||
| <button type="submit" class="btn btn-primary">Submit</button> | ||
| </form> | ||
| </div> | ||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> | ||
| <table class="table" id="display"> | ||
| <thead class="thead-dark"> | ||
| <tr> | ||
| <th>Title</th> | ||
| <th>Author</th> | ||
| <th>Number of Pages</th> | ||
| <th>Read</th> | ||
| <th>Action</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody id="book-table-body"> | ||
| </tbody> | ||
| </table> | ||
| <script src="script.js" type="module"></script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| let myLibrary = []; | ||
| const myLibrary = []; | ||
| window.addEventListener("load", function (e) { | ||
| populateStorage(); | ||
| @@ -7,41 +7,42 @@ window.addEventListener("load", function (e) { | ||
| function populateStorage() { | ||
| if (myLibrary.length == 0) { | ||
| let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); | ||
| let book2 = new Book( | ||
| const book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true); | ||
| const book2 = new Book( | ||
| "The Old Man and the Sea", | ||
| "Ernest Hemingway", | ||
| "127", | ||
| 127, | ||
| true | ||
| ); | ||
| myLibrary.push(book1); | ||
| myLibrary.push(book2); | ||
| render(); | ||
| myLibrary.push(book1, book2); | ||
| } | ||
| } | ||
| const title = document.getElementById("title"); | ||
| const author = document.getElementById("author"); | ||
| const pages = document.getElementById("pages"); | ||
| const check = document.getElementById("check"); | ||
| const bookForm = document.getElementById("book-form"); | ||
| const titleInput = document.getElementById("title"); | ||
| const authorInput = document.getElementById("author"); | ||
| const pagesInput = document.getElementById("pages"); | ||
| const checkInput = document.getElementById("check"); | ||
| //check the right input from forms and if its ok -> add the new book (object in array) | ||
| //via Book function and start render function | ||
| function submit() { | ||
| if ( | ||
| title.value == null || | ||
| title.value == "" || | ||
| pages.value == null || | ||
| pages.value == "" | ||
| ) { | ||
| alert("Please fill all fields!"); | ||
| return false; | ||
| } else { | ||
| let book = new Book(title.value, title.value, pages.value, check.checked); | ||
| library.push(book); | ||
| render(); | ||
| bookForm.addEventListener("submit", function (e) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could consider placing all code that runs once on page load in a single function. For example, you could put it inside the page load callback or create a function named This makes it easier to locate and manage all the code that runs once when the app starts. | ||
| e.preventDefault(); | ||
| const title = titleInput.value.trim(); | ||
| const author = authorInput.value.trim(); | ||
| const pages = Number(pagesInput.value); | ||
| const wasRead = checkInput.checked; | ||
| if (!title || !author || !Number.isInteger(pages) || pages <= 0) { | ||
| alert("Please fill all fields with valid information!"); | ||
| return; | ||
| } | ||
| } | ||
| const book = new Book(title, author, pages, wasRead); | ||
| myLibrary.push(book); | ||
| render(); | ||
| bookForm.reset(); | ||
| }); | ||
| function Book(title, author, pages, check) { | ||
| this.title = title; | ||
| @@ -51,53 +52,47 @@ function Book(title, author, pages, check) { | ||
| } | ||
| function render() { | ||
| let table = document.getElementById("display"); | ||
| let rowsNumber = table.rows.length; | ||
| //delete old table | ||
| for (let n = rowsNumber - 1; n > 0; n-- { | ||
| table.deleteRow(n); | ||
| } | ||
| const bookTableBody = document.getElementById("book-table-body"); | ||
| bookTableBody.innerHTML = ""; | ||
| //insert updated row and cells | ||
| let length = myLibrary.length; | ||
| const length = myLibrary.length; | ||
| for (let i = 0; i < length; i++) { | ||
| let row = table.insertRow(1); | ||
| let titleCell = row.insertCell(0); | ||
| let authorCell = row.insertCell(1); | ||
| let pagesCell = row.insertCell(2); | ||
| let wasReadCell = row.insertCell(3); | ||
| let deleteCell = row.insertCell(4); | ||
| titleCell.innerHTML = myLibrary[i].title; | ||
| authorCell.innerHTML = myLibrary[i].author; | ||
| pagesCell.innerHTML = myLibrary[i].pages; | ||
| const row = bookTableBody.insertRow(); | ||
| const titleCell = row.insertCell(0); | ||
| const authorCell = row.insertCell(1); | ||
| const pagesCell = row.insertCell(2); | ||
| const wasReadCell = row.insertCell(3); | ||
| const deleteCell = row.insertCell(4); | ||
| titleCell.textContent = myLibrary[i].title; | ||
| authorCell.textContent = myLibrary[i].author; | ||
| pagesCell.textContent = myLibrary[i].pages; | ||
| //add and wait for action for read/unread button | ||
| let changeBut = document.createElement("button"); | ||
| changeBut.id = i; | ||
| changeBut.className = "btn btn-success"; | ||
| wasReadCell.appendChild(changeBut); | ||
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
| //read/unread toggle button | ||
| const toggleReadBtn = document.createElement("button"); | ||
| toggleReadBtn.className = "btn btn-success"; | ||
| toggleReadBtn.textContent = myLibrary[i].check ? "yes" : "no"; | ||
| wasReadCell.appendChild(toggleReadBtn); | ||
| changeBut.addEventListener("click", function () { | ||
| toggleReadBtn.addEventListener("click", function () { | ||
| myLibrary[i].check = !myLibrary[i].check; | ||
| render(); | ||
| }); | ||
| //add delete button to every row and render again | ||
| let delButton = document.createElement("button"); | ||
| delBut.id = i + 5; | ||
| deleteCell.appendChild(delBut); | ||
| delBut.className = "btn btn-warning"; | ||
| delBut.innerHTML = "Delete"; | ||
| delBut.addEventListener("clicks", function () { | ||
| alert(`You've deleted title: ${myLibrary[i].title}`); | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
| //delete button with confirmation prompt | ||
| const deleteBtn = document.createElement("button"); | ||
| deleteBtn.className = "btn btn-warning"; | ||
| deleteBtn.textContent = "Delete"; | ||
| deleteCell.appendChild(deleteBtn); | ||
| deleteBtn.addEventListener("click", function () { | ||
| const confirmDel = confirm( | ||
| `Are you sure you want to delete "${myLibrary[i].title}"?` | ||
| ); | ||
| if (confirmDel) { | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
| } | ||
| }); | ||
Comment on lines
+89
to
96
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Informing the user that the book has been deleted is not quite the same as asking whether they want to delete the book though. | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this checkbox is not showing, could you try fixing the issue with the help of AI. The issue is related to Bootstrap 4.4.1. So mentioning "Bootstrap 4.4.1" to AI might help.