Manage books page via admin area

This commit is contained in:
2023-12-22 20:37:12 +11:00
parent 6a3409746e
commit 900fdea472
8 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
module Admin
module Actions
module Books
class Index < Admin::Action
def handle(request, response)
end
end
end
end
end

View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
module Admin
module Actions
module Books
class Update < Admin::Action
include Deps["repos.book_repo"]
def handle(req, resp)
book_repo.update(req.params[:id], book_status: req.params[:book_status])
resp.status = 204
end
end
end
end
end

View File

@@ -64,5 +64,8 @@ module Admin
post "/trips/:id", to: Auth.call(action: "trips.update")
get "/apple_music", to: Auth.call(action: "apple_music.index")
get "/books", to: Auth.call(action: "books.index")
patch "/books/:id", to: Auth.call(action: "books.update")
end
end

View File

@@ -0,0 +1,13 @@
module Admin
module Repos
class BookRepo < Adamantium::Repo[:posts]
commands update: :by_pk
def list_all
posts
.where(post_type: "book")
.to_a
end
end
end
end

View File

@@ -0,0 +1,14 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Admin // Books
div class="max-w-prose prose dark:prose-invert mx-auto"
- books.each do |book|
div class="w-full"
span class="px-2"
select class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg" name="book_status" hx-params="book_status" hx-patch="/admin/books/#{book.id}" hx-trigger="change"
option value="read" selected=(book.book_status == "read") Read
option value="to-read" selected=(book.book_status == "to-read") To Read
option value="reading" selected=(book.book_status == "reading") Reading
span
= book.name

View File

@@ -15,6 +15,8 @@ div class="max-w-prose mx-auto prose dark:prose-invert"
a href="/admin/tags/auto_tagging" Auto tagging
li
a href="/admin/tags/merge" Merge tags
li
a href="/admin/books" Books
li
a href="/admin/bookmarks" Bookmarks
li

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
module Admin
module Views
module Books
class Index < Admin::View
include Deps["repos.book_repo"]
expose :books do
book_repo.list_all
end
end
end
end
end

View File

@@ -0,0 +1,10 @@
# frozen_string_literal: true
module Admin
module Views
module Books
class Update < Admin::View
end
end
end
end