diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..afb34b3 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,13 @@ +class BooksController < MetaController + def component_name + 'Books' + end + + def component_class + 'Book'.constantize + end + + def component_params + params.require(@computer_name.to_sym).permit(:title, :writing_style_id) + end +end diff --git a/app/frontend/stylesheets/admin.sass b/app/frontend/stylesheets/admin.sass index 9d5b5ab..15c5114 100644 --- a/app/frontend/stylesheets/admin.sass +++ b/app/frontend/stylesheets/admin.sass @@ -12,7 +12,16 @@ label font-size: 1.1em input[type="text"] + font-family: $body-font-family !important @apply border-4 focus:border-blue-400 !important + select + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important + background-position: right 0.5rem center !important + background-repeat: no-repeat !important + background-size: 1.5em 1.5em !important + appearance: none !important + padding: 0.5em 0.9em !important + @apply h-12 border-4 focus:border-blue-400 !important @layer .btn-primary diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000..4b9311e --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000..a236b2e --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,15 @@ +# == Schema Information +# +# Table name: books +# +# id :bigint not null, primary key +# title :text +# writing_style_id :bigint not null +# created_at :datetime not null +# updated_at :datetime not null +# +class Book < ApplicationRecord + belongs_to :writing_style + + validates :title, presence: true +end diff --git a/app/models/writing_style.rb b/app/models/writing_style.rb index 795636a..c4df1d9 100644 --- a/app/models/writing_style.rb +++ b/app/models/writing_style.rb @@ -13,6 +13,8 @@ class WritingStyle < ApplicationRecord serialize :prompt, coder: JSON has_many :texts, dependent: :destroy + has_many :books, dependent: :nullify + validates :name, presence: true has_paper_trail ignore: [:name, :pending], versions: { diff --git a/app/views/books/_form.html.slim b/app/views/books/_form.html.slim new file mode 100644 index 0000000..d0aed5e --- /dev/null +++ b/app/views/books/_form.html.slim @@ -0,0 +1,15 @@ +- if @component.errors.any? + =render 'partials/form_errors' + +=r ux.component_segment + = form_with model: @component, class: 'ui form', local: true do |form| + =r ux.component_field + = form.label :title + = form.text_field :title, value: @component.title + + = r ux.component_field + = form.label :writing_style_id, "Writing Style" + = form.collection_select :writing_style_id, WritingStyle.all, :id, :name, { prompt: "Select a Writing Style" }, class: "ui dropdown" + + =r ux.component_submit_field + = form.submit class: 'btn-primary' diff --git a/app/views/books/edit.html.slim b/app/views/books/edit.html.slim new file mode 100644 index 0000000..0c8d365 --- /dev/null +++ b/app/views/books/edit.html.slim @@ -0,0 +1,9 @@ +=r ux.container + =r ux.row + =r ux.column width: 16 + = turbo_frame_tag 'crud_frame' + =r ux.component_container + =r ux.component_header text: "Edit #{@component_name.singularize}" + =r ux.component_return_action text: '< Back', url: send(@component_list_path) + =r ux.component_divider + =render 'form' diff --git a/app/views/books/index.html.slim b/app/views/books/index.html.slim new file mode 100644 index 0000000..7f133d2 --- /dev/null +++ b/app/views/books/index.html.slim @@ -0,0 +1,31 @@ +=r ux.container + =r ux.row + =r ux.column width: 16 + = turbo_frame_tag 'crud_frame' + =r ux.component_container + =r ux.component_header + =@component_name.pluralize + =r ux.component_action text: "New #{@component_name}", url: send(@component_new_path) + =r ux.component_divider + + =r ux.div 'text-center' + = paginate @component_list + + =r ux.table class: 'relaxed celled striped structured' + =r ux.thead + =r ux.tr + =r ux.th text: 'Book Name' + th.center.aligned colspan="2" Actions + - @component_list.each do |component| + =r ux.tr + =r ux.td + =link_to component.title, book_path(component), class: 'item text-sm', data: {'turbo-action': 'replace'} + = r ux.td 'collapsing' + = link_to 'Edit', send(@component_edit_path, component), class: 'btn-list-edit' + = r ux.td 'collapsing' + = button_to 'Delete', send(@component_delete_path, id: component.id), method: :delete, + data: { turbo_confirm: "Are you sure you want to delete this #{@component_name.downcase}?" }, + class: 'btn-list-delete' + + =r ux.div 'text-center' + = paginate @component_list diff --git a/app/views/books/new.html.slim b/app/views/books/new.html.slim new file mode 100644 index 0000000..cd5eea5 --- /dev/null +++ b/app/views/books/new.html.slim @@ -0,0 +1,9 @@ +=r ux.container + =r ux.row + =r ux.column width: 16 + = turbo_frame_tag 'crud_frame' + =r ux.component_container + =r ux.component_header text: "New #{@component_name.singularize}" + =r ux.component_return_action text: '< Back', url: send(@component_list_path) + =r ux.component_divider + =render 'form' diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 791ea87..660278b 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -36,10 +36,15 @@ html lang="en" =r ux.item url: root_path, class: "logo-item #{menu_active?(root_path)}}" =r ux.header text: 'Book Rhino', class: 'inverted logo !font-mono' - = link_to writing_styles_path, class: "item #{menu_active?(writing_styles_path)}" + = link_to books_path, class: "item #{menu_active?(books_path)}" =r ux.icon 'book' + | Books + + = link_to writing_styles_path, class: "item #{menu_active?(writing_styles_path)}" + =r ux.icon 'vest patches' | Writing Styles + / / / =r ux.item class: "dropdown #{dropdown_active?(stories_path)}", ui: :on diff --git a/config/routes.rb b/config/routes.rb index 06fa8e3..65513dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,10 @@ devise_for :users root "page#index" + resources :writing_styles do resources :texts + member do post :iterate end @@ -24,6 +26,10 @@ end end + resources :books do + + end + resources :unauthorized, only: %i[index] resources :settings, only: [:index, :edit] resource :settings, only: [:update] diff --git a/db/migrate/20240921193059_create_books.rb b/db/migrate/20240921193059_create_books.rb new file mode 100644 index 0000000..b19ff62 --- /dev/null +++ b/db/migrate/20240921193059_create_books.rb @@ -0,0 +1,10 @@ +class CreateBooks < ActiveRecord::Migration[7.2] + def change + create_table :books do |t| + t.text :title + t.references :writing_style, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8c1cb14..24e60eb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_09_17_002639) do +ActiveRecord::Schema[7.2].define(version: 2024_09_21_193059) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" enable_extension "vector" + create_table "books", force: :cascade do |t| + t.text "title" + t.bigint "writing_style_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["writing_style_id"], name: "index_books_on_writing_style_id" + end + create_table "locks", force: :cascade do |t| t.string "name", null: false t.boolean "locked", default: false @@ -85,5 +93,6 @@ t.boolean "pending", default: false end + add_foreign_key "books", "writing_styles" add_foreign_key "texts", "writing_styles" end