remove more cruft
This commit is contained in:
parent
3e20c3a51e
commit
b3ccda7885
@ -23,33 +23,29 @@
|
|||||||
function init() {
|
function init() {
|
||||||
fetch("/api")
|
fetch("/api")
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then(showInfo);
|
.then((books) => {
|
||||||
}
|
// prepare response
|
||||||
|
|
||||||
function showInfo(books) {
|
|
||||||
books.forEach((book) => {
|
books.forEach((book) => {
|
||||||
book.sortTitle = titleCleaner(book.title);
|
book.sortTitle = titleCleaner(book.title);
|
||||||
if (!book["isbn-10"] && book["isbn-13"]) {
|
if (!book["isbn-10"] && book["isbn-13"]) {
|
||||||
book["isbn-10"] = ISBNfromEAN(book["isbn-13"]);
|
book["isbn-10"] = ISBNfromEAN(book["isbn-13"]);
|
||||||
}
|
}
|
||||||
if (!book.coverurl && book["isbn-10"]) {
|
if (!book.coverurl && book["isbn-10"]) {
|
||||||
book.coverurl = amazonCoverUrl(book["isbn-10"]);
|
book.coverurl =
|
||||||
|
`https://images-na.ssl-images-amazon.com/images/P/` +
|
||||||
|
book["isbn-10"] +
|
||||||
|
`.01.LZZ.jpg`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return books;
|
||||||
$("#search")
|
})
|
||||||
.unbind("input")
|
.then((books) => {
|
||||||
.on("input", (e) => {
|
document.getElementById("search").addEventListener("input", (e) => {
|
||||||
search(books, e.target.value);
|
search(books, e.target.value);
|
||||||
});
|
});
|
||||||
|
return books;
|
||||||
$("#reloadLink")
|
})
|
||||||
.unbind("click")
|
.then(renderTable);
|
||||||
.on("click", () => {
|
|
||||||
init();
|
|
||||||
});
|
|
||||||
|
|
||||||
renderTable(books);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(books, searchBy) {
|
function search(books, searchBy) {
|
||||||
@ -88,15 +84,19 @@
|
|||||||
if (sortState.sortOrder === "desc") {
|
if (sortState.sortOrder === "desc") {
|
||||||
books.reverse();
|
books.reverse();
|
||||||
}
|
}
|
||||||
books.forEach((e, i) => (e.rowNumber = i)); // re-key for new sort
|
books.forEach((e, i) => (e.rowNumber = i)); // re-key
|
||||||
|
|
||||||
$("#books").html(TableTemplate(books));
|
// rendering
|
||||||
|
document.getElementById("books").innerHTML = TableTemplate(books);
|
||||||
$("#books tbody tr")
|
$("#books tbody tr")
|
||||||
.not(":first") // ignore the headers
|
.not(":first") // ignore the headers
|
||||||
.on("click", function () {
|
.on("click", (e) => {
|
||||||
updateCurrentBook(books[$(this)[0].id]);
|
document.getElementById("current").innerHTML = BookTemplate(
|
||||||
|
books[e.currentTarget.id]
|
||||||
|
);
|
||||||
});
|
});
|
||||||
$("#books tbody tr th[data-sort-by]").on("click", function () {
|
$("#books tbody tr th[data-sort-by]").on("click", function (e) {
|
||||||
|
console.log(e);
|
||||||
renderTable(books, $(this).data("sortBy")); // only add callback when there's a sortBy attribute
|
renderTable(books, $(this).data("sortBy")); // only add callback when there's a sortBy attribute
|
||||||
});
|
});
|
||||||
$("#books tbody tr th[data-sort-by=" + sortState.sortBy + "]").addClass(
|
$("#books tbody tr th[data-sort-by=" + sortState.sortBy + "]").addClass(
|
||||||
@ -104,10 +104,6 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCurrentBook(book) {
|
|
||||||
$("#current").html(BookTemplate(book));
|
|
||||||
}
|
|
||||||
|
|
||||||
function titleCleaner(title) {
|
function titleCleaner(title) {
|
||||||
return title
|
return title
|
||||||
.replace('"', "")
|
.replace('"', "")
|
||||||
@ -124,10 +120,6 @@
|
|||||||
.replace(" ", "");
|
.replace(" ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function amazonCoverUrl(ISBN) {
|
|
||||||
return `https://images-na.ssl-images-amazon.com/images/P/${ISBN}.01.LZZ.jpg`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ISBNfromEAN(EAN) {
|
function ISBNfromEAN(EAN) {
|
||||||
ISBN = EAN.slice(3, 12);
|
ISBN = EAN.slice(3, 12);
|
||||||
var checkdigit =
|
var checkdigit =
|
||||||
@ -209,7 +201,9 @@
|
|||||||
}, "")} </table>`;
|
}, "")} </table>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
|
init();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -219,7 +213,6 @@
|
|||||||
<a target="_blank" href="https://git.yetaga.in/alazyreader/library"
|
<a target="_blank" href="https://git.yetaga.in/alazyreader/library"
|
||||||
>git</a
|
>git</a
|
||||||
>
|
>
|
||||||
<a id="reloadLink" href="#">reload</a>
|
|
||||||
<div id="searchBox">
|
<div id="searchBox">
|
||||||
<input
|
<input
|
||||||
id="search"
|
id="search"
|
||||||
|
Loading…
Reference in New Issue
Block a user