add 'childrens' as a field on books
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
David 2023-10-08 15:05:15 -04:00
parent 1069dadd10
commit 77ddc7ec8e
5 changed files with 34 additions and 12 deletions

View File

@ -155,7 +155,7 @@ func (m *MySQL) GetAllBooks(ctx context.Context) ([]media.Book, error) {
allBooksQuery := fmt.Sprintf(`SELECT allBooksQuery := fmt.Sprintf(`SELECT
id, title, authors, sortauthor, isbn10, isbn13, format, id, title, authors, sortauthor, isbn10, isbn13, format,
genre, publisher, series, volume, year, signed, genre, publisher, series, volume, year, signed,
description, notes, coverurl description, notes, coverurl, childrens
FROM %s`, m.tableName) FROM %s`, m.tableName)
books := []media.Book{} books := []media.Book{}
@ -174,7 +174,7 @@ func (m *MySQL) GetAllBooks(ctx context.Context) ([]media.Book, error) {
&b.Format, &b.Genre, &b.Publisher, &b.Format, &b.Genre, &b.Publisher,
&b.Series, &b.Volume, &b.Year, &b.Series, &b.Volume, &b.Year,
&b.Signed, &b.Description, &b.Notes, &b.Signed, &b.Description, &b.Notes,
&b.CoverURL) &b.CoverURL, &b.Childrens)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -193,9 +193,9 @@ func (m *MySQL) AddBook(ctx context.Context, b *media.Book) error {
res, err := m.connection.ExecContext(ctx, ` res, err := m.connection.ExecContext(ctx, `
INSERT INTO `+m.tableName+` INSERT INTO `+m.tableName+`
(title, authors, sortauthor, isbn10, isbn13, format, genre, publisher, series, volume, year, signed, description, notes, coverurl) (title, authors, sortauthor, isbn10, isbn13, format, genre, publisher, series, volume, year, signed, description, notes, coverurl, childrens)
VALUES VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
b.Title, b.Title,
strings.Join(b.Authors, ";"), strings.Join(b.Authors, ";"),
b.SortAuthor, b.SortAuthor,
@ -211,6 +211,7 @@ func (m *MySQL) AddBook(ctx context.Context, b *media.Book) error {
b.Description, b.Description,
b.Notes, b.Notes,
b.CoverURL, b.CoverURL,
b.Childrens,
) )
if err != nil { if err != nil {
return err return err
@ -251,6 +252,7 @@ func (m *MySQL) UpdateBook(ctx context.Context, old, new *media.Book) error {
description=? description=?
notes=? notes=?
coverurl=? coverurl=?
childrens=?
WHERE id=?`, WHERE id=?`,
new.Title, new.Title,
strings.Join(new.Authors, ";"), strings.Join(new.Authors, ";"),
@ -267,6 +269,7 @@ func (m *MySQL) UpdateBook(ctx context.Context, old, new *media.Book) error {
new.Description, new.Description,
new.Notes, new.Notes,
new.CoverURL, new.CoverURL,
new.Childrens,
old.ID) old.ID)
if err != nil { if err != nil {
return err return err

View File

@ -10,9 +10,17 @@ function init() {
// prepare response // prepare response
books.forEach(apiResponseParsing); books.forEach(apiResponseParsing);
document.getElementById("search").addEventListener("input", (e) => { document.getElementById("search").addEventListener("input", (e) => {
renderTable(search(books, e.target.value)); renderTable(
search(
books,
e.target.value,
document.getElementById("childrens").checked
)
);
}); });
renderTable(books); renderTable(
search(books, "", document.getElementById("childrens").checked)
);
}); });
} }
@ -81,12 +89,12 @@ function apiResponseParsing(book) {
return book; return book;
} }
function search(books, searchBy) { function search(books, searchBy, includeChildrensBooks) {
searchBy = searchCleaner(searchBy); searchBy = searchCleaner(searchBy);
if (searchBy !== "") { if (searchBy !== "") {
books = books.filter( books = books.filter(
({ title, authors, genre, publisher, series, year }) => { ({ title, authors, genre, publisher, series, year, childrens }) => {
return Object.values({ var inSearch = Object.values({
title, title,
authors: authors.join(" "), authors: authors.join(" "),
genre, genre,
@ -94,6 +102,10 @@ function search(books, searchBy) {
series, series,
year, year,
}).find((field) => searchCleaner(field).indexOf(searchBy) !== -1); }).find((field) => searchCleaner(field).indexOf(searchBy) !== -1);
if (!includeChildrensBooks) {
return inSearch && !childrens;
}
return inSearch;
} }
); );
} }

View File

@ -13,7 +13,11 @@
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener("DOMContentLoaded", init); window.addEventListener("DOMContentLoaded", init);
</script> </script>
<script defer data-domain="library.yetaga.in" src="https://stats.yetaga.in/js/script.js"></script> <script
defer
data-domain="library.yetaga.in"
src="https://stats.yetaga.in/js/script.js"
></script>
<meta name="description" content="A personal library record." /> <meta name="description" content="A personal library record." />
</head> </head>
<body> <body>
@ -28,6 +32,8 @@
>git</a >git</a
> >
<div id="searchBox"> <div id="searchBox">
<span id="bookCount" class="bookCount">Include Childrens Books?</span>
<input id="childrens" type="checkbox" name="childrens" />
<span id="bookCount" class="bookCount">_ books</span> <span id="bookCount" class="bookCount">_ books</span>
<input <input
id="search" id="search"

View File

@ -157,10 +157,10 @@ body {
right: 10px; right: 10px;
top: 7px; top: 7px;
text-align: right; text-align: right;
width: 400px; width: 800px;
} }
#searchBox input { #searchBox input#search {
width: 300px; width: 300px;
font-size: 16px; font-size: 16px;
background: #f9f8ed; background: #f9f8ed;

View File

@ -17,6 +17,7 @@ type Book struct {
Description string `json:"description"` Description string `json:"description"`
Notes string `json:"notes"` Notes string `json:"notes"`
CoverURL string `json:"coverURL"` CoverURL string `json:"coverURL"`
Childrens bool `json:"childrens"`
} }
type Record struct { type Record struct {