Manage books page via admin area
This commit is contained in:
12
slices/admin/actions/books/index.rb
Normal file
12
slices/admin/actions/books/index.rb
Normal 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
|
17
slices/admin/actions/books/update.rb
Normal file
17
slices/admin/actions/books/update.rb
Normal 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
|
@@ -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
|
||||
|
13
slices/admin/repos/book_repo.rb
Normal file
13
slices/admin/repos/book_repo.rb
Normal 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
|
14
slices/admin/templates/books/index.html.slim
Normal file
14
slices/admin/templates/books/index.html.slim
Normal 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
|
@@ -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
|
||||
|
16
slices/admin/views/books/index.rb
Normal file
16
slices/admin/views/books/index.rb
Normal 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
|
10
slices/admin/views/books/update.rb
Normal file
10
slices/admin/views/books/update.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Views
|
||||
module Books
|
||||
class Update < Admin::View
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user