+ <.link
+ href={~p"/admin/comments"}
+ class="text-xs font-semibold leading-6 text-gray-900 hover:text-gray-700 dark:text-gray-200"
+ >
+ <.icon name="hero-document-text" class="w-4 h-4" /> Comments
+
<.link
href={~p"/admin/notes"}
class="text-xs font-semibold leading-6 text-gray-900 hover:text-gray-700 dark:text-gray-200"
diff --git a/lib/chiya_web/controllers/comment_controller.ex b/lib/chiya_web/controllers/comment_controller.ex
index 5559a96..0fbbb8b 100644
--- a/lib/chiya_web/controllers/comment_controller.ex
+++ b/lib/chiya_web/controllers/comment_controller.ex
@@ -1,11 +1,19 @@
defmodule ChiyaWeb.CommentController do
use ChiyaWeb, :controller
+ def index(conn, _params) do
+ comments = Chiya.Notes.list_note_comments()
+ render(conn, comments: comments)
+ end
+
+ def show(conn, %{"id" => comment_id}) do
+ comment = Chiya.Notes.get_note_comment!(comment_id)
+ render(conn, comment: comment)
+ end
+
def create(conn, %{"slug" => note_slug, "note_comment" => comment_params}) do
note = Chiya.Notes.get_note_by_slug_preloaded!(note_slug)
- IO.inspect(comment_params)
-
case Chiya.Notes.create_note_comment(comment_params) do
{:ok, _comment} ->
redirect(conn, to: ~p"/#{note_slug}?error=0")
diff --git a/lib/chiya_web/controllers/comment_html/index.html.heex b/lib/chiya_web/controllers/comment_html/index.html.heex
new file mode 100644
index 0000000..01f9447
--- /dev/null
+++ b/lib/chiya_web/controllers/comment_html/index.html.heex
@@ -0,0 +1,25 @@
+<.header>
+ <.icon name="hero-document-text" /> Comments
+ <:subtitle>Comments are attached to notes
+
+
+<.table id="comments" rows={@comments} row_click={&JS.navigate(~p"/admin/comments/#{&1}")}>
+ <:col :let={comment} label="Author"><%= comment.author_name %>
+ <:col :let={comment} label="Inserted at"><%= from_now(comment.inserted_at) %>
+ <:col :let={comment} label="Approved at"><%= from_now(comment.approved_at) %>
+ <:action :let={comment}>
+
+ <.link navigate={~p"/admin/comments/#{comment}"}>Show
+
+
+ <:action :let={comment}>
+ <.link href={~p"/admin/comments/#{comment}"} method="delete" data-confirm="Are you sure?">
+ Delete
+
+
+ <:action :let={comment}>
+
+ <.link navigate={~p"/admin/comments/#{comment}/approve"}>Approve
+
+
+
diff --git a/lib/chiya_web/controllers/comment_html/show.html.heex b/lib/chiya_web/controllers/comment_html/show.html.heex
new file mode 100644
index 0000000..bf98b2b
--- /dev/null
+++ b/lib/chiya_web/controllers/comment_html/show.html.heex
@@ -0,0 +1,20 @@
+<.header>
+ Comment <%= @comment.id %>
+ <:subtitle>This is a comment record from your database.
+ <:actions>
+ <.link href={~p"/admin/notes/#{@comment}/approve"}>
+ <.button>Approve note
+
+
+
+
+<.list>
+ <:item title="Name"><%= @comment.author_name %>
+ <:item title="Content"><%= @comment.content %>
+ <:item title="Inserted at"><%= @comment.inserted_at %>
+ <:item title="Approved at"><%= @comment.approved_at %>
+ <:item title="Kind"><%= @comment.kind %>
+ <:item title="Note">
<%= @comment.note.name %>
+
+
+<.back navigate={~p"/admin/comments"}>Back to comments
diff --git a/lib/chiya_web/router.ex b/lib/chiya_web/router.ex
index 3af5fff..db4038c 100644
--- a/lib/chiya_web/router.ex
+++ b/lib/chiya_web/router.ex
@@ -60,6 +60,7 @@ defmodule ChiyaWeb.Router do
resources "/notes", NoteController, except: [:show]
resources "/settings", SettingController, singleton: true
resources "/identities", IdentityController
+ resources "/comments", CommentController, only: [:index, :show]
get "/notes/import", NoteController, :import_prepare
post "/notes/import", NoteController, :import_run
From a4370735eb291766cb4ad5dd107bbe9f6809e322 Mon Sep 17 00:00:00 2001
From: Inhji
Date: Tue, 9 May 2023 16:24:46 +0200
Subject: [PATCH 6/6] mix format
---
lib/chiya_web/controllers/comment_html/index.html.heex | 2 +-
lib/chiya_web/controllers/comment_html/show.html.heex | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/chiya_web/controllers/comment_html/index.html.heex b/lib/chiya_web/controllers/comment_html/index.html.heex
index 01f9447..f791e13 100644
--- a/lib/chiya_web/controllers/comment_html/index.html.heex
+++ b/lib/chiya_web/controllers/comment_html/index.html.heex
@@ -17,7 +17,7 @@
Delete
- <:action :let={comment}>
+ <:action :let={comment}>
<.link navigate={~p"/admin/comments/#{comment}/approve"}>Approve
diff --git a/lib/chiya_web/controllers/comment_html/show.html.heex b/lib/chiya_web/controllers/comment_html/show.html.heex
index bf98b2b..962d56e 100644
--- a/lib/chiya_web/controllers/comment_html/show.html.heex
+++ b/lib/chiya_web/controllers/comment_html/show.html.heex
@@ -9,12 +9,14 @@
<.list>
- <:item title="Name"><%= @comment.author_name %>
+ <:item title="Name"><%= @comment.author_name %>
<:item title="Content"><%= @comment.content %>
<:item title="Inserted at"><%= @comment.inserted_at %>
<:item title="Approved at"><%= @comment.approved_at %>
<:item title="Kind"><%= @comment.kind %>
- <:item title="Note"><%= @comment.note.name %>
+ <:item title="Note">
+ <%= @comment.note.name %>
+
<.back navigate={~p"/admin/comments"}>Back to comments