From 77ddc7ec8ebfb0014f6866637b5ae76d9d2bc0b9 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 8 Oct 2023 15:05:15 -0400 Subject: [PATCH] add 'childrens' as a field on books --- database/mysql.go | 11 +++++++---- frontend/files/app.js | 22 +++++++++++++++++----- frontend/files/index.html | 8 +++++++- frontend/files/style.css | 4 ++-- media/media.go | 1 + 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/database/mysql.go b/database/mysql.go index 703def0..93df8fd 100644 --- a/database/mysql.go +++ b/database/mysql.go @@ -155,7 +155,7 @@ func (m *MySQL) GetAllBooks(ctx context.Context) ([]media.Book, error) { allBooksQuery := fmt.Sprintf(`SELECT id, title, authors, sortauthor, isbn10, isbn13, format, genre, publisher, series, volume, year, signed, - description, notes, coverurl + description, notes, coverurl, childrens FROM %s`, m.tableName) books := []media.Book{} @@ -174,7 +174,7 @@ func (m *MySQL) GetAllBooks(ctx context.Context) ([]media.Book, error) { &b.Format, &b.Genre, &b.Publisher, &b.Series, &b.Volume, &b.Year, &b.Signed, &b.Description, &b.Notes, - &b.CoverURL) + &b.CoverURL, &b.Childrens) if err != nil { return nil, err } @@ -193,9 +193,9 @@ func (m *MySQL) AddBook(ctx context.Context, b *media.Book) error { res, err := m.connection.ExecContext(ctx, ` 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 - (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, b.Title, strings.Join(b.Authors, ";"), b.SortAuthor, @@ -211,6 +211,7 @@ func (m *MySQL) AddBook(ctx context.Context, b *media.Book) error { b.Description, b.Notes, b.CoverURL, + b.Childrens, ) if err != nil { return err @@ -251,6 +252,7 @@ func (m *MySQL) UpdateBook(ctx context.Context, old, new *media.Book) error { description=? notes=? coverurl=? + childrens=? WHERE id=?`, new.Title, strings.Join(new.Authors, ";"), @@ -267,6 +269,7 @@ func (m *MySQL) UpdateBook(ctx context.Context, old, new *media.Book) error { new.Description, new.Notes, new.CoverURL, + new.Childrens, old.ID) if err != nil { return err diff --git a/frontend/files/app.js b/frontend/files/app.js index 8da56fb..c16e710 100644 --- a/frontend/files/app.js +++ b/frontend/files/app.js @@ -10,9 +10,17 @@ function init() { // prepare response books.forEach(apiResponseParsing); 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; } -function search(books, searchBy) { +function search(books, searchBy, includeChildrensBooks) { searchBy = searchCleaner(searchBy); if (searchBy !== "") { books = books.filter( - ({ title, authors, genre, publisher, series, year }) => { - return Object.values({ + ({ title, authors, genre, publisher, series, year, childrens }) => { + var inSearch = Object.values({ title, authors: authors.join(" "), genre, @@ -94,6 +102,10 @@ function search(books, searchBy) { series, year, }).find((field) => searchCleaner(field).indexOf(searchBy) !== -1); + if (!includeChildrensBooks) { + return inSearch && !childrens; + } + return inSearch; } ); } diff --git a/frontend/files/index.html b/frontend/files/index.html index ba3040f..02ed4e6 100644 --- a/frontend/files/index.html +++ b/frontend/files/index.html @@ -13,7 +13,11 @@ - + @@ -28,6 +32,8 @@ >git