diff --git a/slices/admin/actions/books/index.rb b/slices/admin/actions/books/index.rb new file mode 100644 index 0000000..9f58918 --- /dev/null +++ b/slices/admin/actions/books/index.rb @@ -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 diff --git a/slices/admin/actions/books/update.rb b/slices/admin/actions/books/update.rb new file mode 100644 index 0000000..948a663 --- /dev/null +++ b/slices/admin/actions/books/update.rb @@ -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 diff --git a/slices/admin/config/routes.rb b/slices/admin/config/routes.rb index c4fe9e4..30aae65 100644 --- a/slices/admin/config/routes.rb +++ b/slices/admin/config/routes.rb @@ -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 diff --git a/slices/admin/repos/book_repo.rb b/slices/admin/repos/book_repo.rb new file mode 100644 index 0000000..9d1d177 --- /dev/null +++ b/slices/admin/repos/book_repo.rb @@ -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 diff --git a/slices/admin/templates/books/index.html.slim b/slices/admin/templates/books/index.html.slim new file mode 100644 index 0000000..d59a3f1 --- /dev/null +++ b/slices/admin/templates/books/index.html.slim @@ -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 diff --git a/slices/admin/templates/index.html.slim b/slices/admin/templates/index.html.slim index 5f1c56f..cedcb6b 100644 --- a/slices/admin/templates/index.html.slim +++ b/slices/admin/templates/index.html.slim @@ -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 diff --git a/slices/admin/views/books/index.rb b/slices/admin/views/books/index.rb new file mode 100644 index 0000000..4453e29 --- /dev/null +++ b/slices/admin/views/books/index.rb @@ -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 diff --git a/slices/admin/views/books/update.rb b/slices/admin/views/books/update.rb new file mode 100644 index 0000000..fcee3c6 --- /dev/null +++ b/slices/admin/views/books/update.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Admin + module Views + module Books + class Update < Admin::View + end + end + end +end