Skip to content

tkhobbes/newbooksdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book Collector Database

Introduction

Set up and configuration

Run 'bundle exec rails bookdb_prep:seed_formats' to seed a default format. Otherwise the app will crash when starting - it expects one book format to be available.

Technical Information

Programming ideas

Quick Search and Search

Quick search code is adapted from the Drifting Ruby Episode 369 https://youtu.be/cVKRSF2Td7E and then augmented from https://thoughtbot.com/blog/hotwire-typeahead-searching (especially the styling and the form invalidations)

Quick search and search use search_cop. Search is scoped for book titles, book original titles.

Flash Messages

Moving away from noty and used turbo - as described in this video: https://youtu.be/gk_qDsKMIrM

View Components

Check out localhost:3000/lookbook for a preview and description of all view components.

Application Flow

Service Objects

There are two main categories of service objects: Book searching and creations, and image searching and creation.

Book Searching and Creation

The logical flow is:

  • user searches for a book - either through a form (IsbnSearchController.new) or by scanning ISBNs (ScanController.new).
  • the search parameters (author, title, isbn) are passed to a controller called IsbnSearch.show which in turn calls x::BookSearch.new().search_isbn, .search_author or .search_title
    • (x is either Google:: or Amazon::) - MORE TO WRITE HERE
  • the IsbnSearch.show view is responsible for rendering a view that shows all results found (with some styling if the book is already present). the results are clickable and will call IsbnCreate.create
  • IsbnCreate.create will call x::BookCreate.new().create_book
  • x::BookCreate.new().create_book wrap the creation of a book, its authors (if not existing) and its publisher in one ActiveRecord transaction. It will then call PictureAttacher.new().attach
  • PictureAttacher.new(picture_url).attach will try to attach the picture found in picture_url. It returns a return object that contains a field for "created" (true or false), a message, and (if successful) "picture" (the picture object or nil)
  • x::BookCreate.new().create_book will then return a return object that contains a field for "created" (true or false), a message and the book object that was created (if successful).
Controller actions
  • scan_queues_controller.rb
    • index: lists a queue
    • new: shows a form to scan ISBN codes
    • create: creates an entry in the queue
    • destroy: destroys an entry in the queue
  • isbn_search_controller.rb
    • new: shows search form
    • show: shows search results
  • isbn_create_controller.rb
    • create: Creates a book from an ISBN code (via service object)
The different views and turbo_streams
  • scan_queues/new.html.erb: Displays a possibility to scan isbn-codes and shows a turbo-frame to the right of the scan area with scanned isbn codes
  • scan_queues/_results.html.erb: Content of the above mentioned turbo-frame.
  • scan_queues/create.turbo_stream.erb: Updates the above mentioned turbo-frame with a new ISBN code
  • scan_queues/destroy.turbo_stream.erb: Updates the above mentioned turbo-frame by removing an ISBN code
  • scan_queues/index.html.erb: Comes after "new" - and shows all scanned isbn codes to click on (which then searches for matches for that ISBN code)
  • isbn_search/new.html.erb: Shows a form to search by manually entering an ISBN code, an author name or a book title
  • isbn_search/show.html.erb: Shows the results of above form
  • isbn_search/show.turbo_stream.erb: Shows results in scan_queues/index.html.erb
  • isbn_search/_resultpreview.html.erb: Partial to display the book cover or a generic SVG in above views
  • isbn_create/create.turbo_stream.erb: Used to update the scan_queues/index.html.erb view - removing the ISBN list entry of the book just created

Params

A lot of views have the possibility to display different things or switch between different modes. This is done by passing parameters to the view. The following parameters are commonly used: :show - This specifies "how to display" something. Three typical values are possible:

  • 'grid': This renders cards with thumbnails and details
  • 'list': This renders items as lists
  • 'settings': This is used for admin views - rendering shorter lists

:list - This specifies WHAT to list out: Mainly used for "tags" which are polymorphic. Examples:

  • 'books': lists books
  • 'authors': lists authors

Stimulus controller for Tab Navigation

There is a stimulus controller to switch between tabs (in tags view), code taken from this youtube video: https://youtu.be/I8Np9GHNMDk

Stimulus controller for chart clicking

This stimulus controller makes sure we can click charts and then a table with data appears. Taken from here: https://psmy.medium.com/rails-7-stimulus-and-chartkick-9d889b32f97c With some help from discord: https://discord.com/channels/629472241427415060/1107953223152713778/1107972491328102451 Every chart has to have the iD of "statChart" and the corresponding value in the div as well.

Models

  • Owners: The "user" field and used for authentication
  • Profiles: More details for owners
  • Books: Main model. Rateable, attachments (cover) and rich text synopsis
  • Publishers: Book Publishers; slug (friendly id) derived from name or combination of name and location
  • Authors: Book Authors. Can contain pictures and are rateable
  • Book Formats: Book Formats (hardcover, softcover, ebook etc). The boolean "fallback" value which should be present on only one format is used if a format is not defined
  • Genres: Genres of books
  • Tags: Free text tags to categorize books. "Per user" - users don't see tags that don't belong to them
  • Shelves: The "store location" of books. "Per user" - users don't see shelves that don't belong to them; shown as tabs on the book index page, with default tabs "all books" and "my books", as well as "books in no shelf" always visible

Ruby Version

This application is setup using Ruby v 3.1.2

Gems

The following Gems are used in this project:

Application

Development

Core Rails / Application

JS Packages

The following packages have to be added via yarn:

Check package.json for all dependencies that were added.

Stimulus Controllers

The controller to add author subforms (another_sub_form) is based on this guide: https://ndrean.medium.com/dynamic-nested-forms-with-rails-aa537a3ee758

Test Suite

Database creation and initialization

Styles and HTML

This project is partially based on normalize.css (https://necolas.github.io/normalize.css/)