mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
add recent comments
This commit is contained in:
parent
5b35b75b1d
commit
0f6e94d1a9
4 changed files with 51 additions and 1 deletions
35
lib/philomena_web/controllers/comment_controller.ex
Normal file
35
lib/philomena_web/controllers/comment_controller.ex
Normal file
|
@ -0,0 +1,35 @@
|
|||
defmodule PhilomenaWeb.CommentController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.{Images.Image, Comments.Comment, Textile.Renderer}
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
def index(conn, _params) do
|
||||
comments =
|
||||
Comment.search_records(
|
||||
%{
|
||||
query: %{
|
||||
bool: %{
|
||||
must: [
|
||||
%{range: %{posted_at: %{gt: "now-1w"}}},
|
||||
%{term: %{hidden_from_users: false}}
|
||||
]
|
||||
}
|
||||
},
|
||||
sort: %{posted_at: :desc}
|
||||
},
|
||||
conn.assigns.pagination,
|
||||
Comment |> preload([:image, user: [awards: :badge]])
|
||||
)
|
||||
|
||||
rendered =
|
||||
comments.entries
|
||||
|> Renderer.render_collection()
|
||||
|
||||
comments =
|
||||
%{comments | entries: Enum.zip(comments.entries, rendered)}
|
||||
|
||||
render(conn, "index.html", comments: comments)
|
||||
end
|
||||
end
|
|
@ -36,6 +36,7 @@ defmodule PhilomenaWeb.Router do
|
|||
resources "/forums", ForumController, only: [:index, :show] do
|
||||
resources "/topics", TopicController, only: [:show]
|
||||
end
|
||||
resources "/comments", CommentController, only: [:index]
|
||||
|
||||
scope "/filters", Filter, as: :filter do
|
||||
resources "/current", CurrentController, only: [:update], singular: true
|
||||
|
|
14
lib/philomena_web/templates/comment/index.html.slime
Normal file
14
lib/philomena_web/templates/comment/index.html.slime
Normal file
|
@ -0,0 +1,14 @@
|
|||
elixir:
|
||||
route = fn p -> Routes.comment_path(@conn, :index, p) end
|
||||
pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @comments, route: route
|
||||
|
||||
.block
|
||||
.block__header
|
||||
= pagination
|
||||
|
||||
= for {comment, body} <- @comments do
|
||||
= render PhilomenaWeb.CommentView, "_comment.html", comment: comment, body: body, conn: @conn
|
||||
|
||||
.block
|
||||
.block__header.block__header--light
|
||||
= pagination
|
|
@ -7,7 +7,7 @@
|
|||
span data-click-preventdefault="true"
|
||||
i.fa.fa-caret-down<
|
||||
.dropdown__content
|
||||
a.header__link href="/lists/recent_comments"
|
||||
a.header__link href="/comments"
|
||||
| Comments
|
||||
.dropdown.header__dropdown
|
||||
a.header__link href="/forums"
|
||||
|
|
Loading…
Reference in a new issue