Admin post management
This commit is contained in:
@@ -70,6 +70,10 @@ module Adamantium
|
|||||||
delete "/bookmarks/:id", to: "bookmarks.delete"
|
delete "/bookmarks/:id", to: "bookmarks.delete"
|
||||||
post "/bookmarks/cache/:id", to: "bookmarks.cache"
|
post "/bookmarks/cache/:id", to: "bookmarks.cache"
|
||||||
post "/bookmarks/:id/archive", to: "bookmarks.archive"
|
post "/bookmarks/:id/archive", to: "bookmarks.archive"
|
||||||
|
|
||||||
|
get "/posts", to: "posts.index"
|
||||||
|
delete "/posts/:id", to: "posts.delete"
|
||||||
|
post "/posts/:id/archive", to: "posts.archive"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
16
slices/admin/actions/posts/archive.rb
Normal file
16
slices/admin/actions/posts/archive.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module Admin
|
||||||
|
module Actions
|
||||||
|
module Posts
|
||||||
|
class Archive < Action
|
||||||
|
|
||||||
|
include Deps["repos.post_repo"]
|
||||||
|
|
||||||
|
def handle(req, res)
|
||||||
|
post_id = req.params[:id]
|
||||||
|
|
||||||
|
post_repo.archive(id: post_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
17
slices/admin/actions/posts/delete.rb
Normal file
17
slices/admin/actions/posts/delete.rb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
module Admin
|
||||||
|
module Actions
|
||||||
|
module Posts
|
||||||
|
class Delete < Action
|
||||||
|
|
||||||
|
include Deps["repos.post_repo", "repos.post_tag_repo"]
|
||||||
|
|
||||||
|
def handle(req, res)
|
||||||
|
post_id = req.params[:id]
|
||||||
|
|
||||||
|
post_tag_repo.delete_by_post_id(post_id: post_id)
|
||||||
|
post_repo.delete(id: post_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
14
slices/admin/actions/posts/index.rb
Normal file
14
slices/admin/actions/posts/index.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module Admin
|
||||||
|
module Actions
|
||||||
|
module Posts
|
||||||
|
class Index < Action
|
||||||
|
|
||||||
|
include Deps["views.posts.index"]
|
||||||
|
|
||||||
|
def handle(req, res)
|
||||||
|
res.render index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@@ -32,6 +32,20 @@ module Admin
|
|||||||
.published
|
.published
|
||||||
.where(Sequel.ilike(:content, "%#{body_contains}%")).to_a
|
.where(Sequel.ilike(:content, "%#{body_contains}%")).to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list
|
||||||
|
posts
|
||||||
|
.where(post_type: "post")
|
||||||
|
.to_a
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(id:)
|
||||||
|
posts.where(id: id).delete
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive(id:)
|
||||||
|
posts.where(id: id).update(published_at: nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@@ -3,6 +3,8 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
|
|||||||
|
|
||||||
div class="max-w-prose mx-auto prose dark:prose-invert"
|
div class="max-w-prose mx-auto prose dark:prose-invert"
|
||||||
ul
|
ul
|
||||||
|
li
|
||||||
|
a href="/admin/posts" Posts
|
||||||
li
|
li
|
||||||
a href="/admin/tags" Tags
|
a href="/admin/tags" Tags
|
||||||
li
|
li
|
||||||
|
29
slices/admin/templates/posts/index.html.slim
Normal file
29
slices/admin/templates/posts/index.html.slim
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
|
||||||
|
h1 Admin // Posts
|
||||||
|
|
||||||
|
div class="max-w-prose mx-auto"
|
||||||
|
table class="prose dark:prose-invert table-auto prose-a:text-blue-600 prose-a:no-underline"
|
||||||
|
thead
|
||||||
|
th Details
|
||||||
|
th Date
|
||||||
|
th Actions
|
||||||
|
tbody
|
||||||
|
- posts.each do |post|
|
||||||
|
tr id="post-#{post.id}"
|
||||||
|
td
|
||||||
|
div
|
||||||
|
= post.name
|
||||||
|
a class="no-underline" href=post.slug
|
||||||
|
small class="text-gray-400 dark:text-gray-600" = post.slug
|
||||||
|
td
|
||||||
|
= post.published_at&.strftime("%d %b %Y")
|
||||||
|
td
|
||||||
|
div
|
||||||
|
button hx-delete="/admin/bookmarks/#{post.id}" hx-target="#post-#{post.id}" delete
|
||||||
|
div
|
||||||
|
button hx-post="/admin/bookmarks/#{post.id}/archive" archive
|
||||||
|
|
||||||
|
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"
|
||||||
|
|
||||||
|
|
||||||
|
|
14
slices/admin/views/posts/index.rb
Normal file
14
slices/admin/views/posts/index.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module Admin
|
||||||
|
module Views
|
||||||
|
module Posts
|
||||||
|
class Index < Admin::View
|
||||||
|
|
||||||
|
include Deps["repos.post_repo"]
|
||||||
|
|
||||||
|
expose :posts do
|
||||||
|
post_repo.list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user