Create changeset_comments resources for users

This commit is contained in:
Anton Khorev 2025-01-19 04:11:06 +03:00
parent 9fbe52dd21
commit 420d9da1f9
7 changed files with 91 additions and 1 deletions

View file

@ -0,0 +1,14 @@
module Users
class ChangesetCommentsController < CommentsController
def index
@title = t ".title", :user => @user.display_name
comments = ChangesetComment.where(:author => @user)
comments = comments.visible unless current_user&.moderator?
@params = params.permit(:display_name, :before, :after)
@comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:author])
end
end
end

View file

@ -25,6 +25,8 @@ class ChangesetComment < ApplicationRecord
belongs_to :changeset
belongs_to :author, :class_name => "User"
scope :visible, -> { where(:visible => true) }
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :only_integer => true }
validates :changeset, :associated => true

View file

@ -0,0 +1,22 @@
<turbo-frame id="pagination" target="_top" data-turbo="false">
<table class="table table-striped" width="100%">
<thead>
<tr>
<th width="25%"><%= t ".changeset" %></th>
<th width="25%"><%= t ".when" %></th>
<th width="50%"><%= t ".comment" %></th>
</tr>
</thead>
<% @comments.each do |comment| -%>
<tr>
<td width="25%" class="<%= "text-muted" unless comment.visible? %>"><%= link_to comment.changeset.id, changeset_path(comment.changeset) %></td>
<td width="25%" class="<%= "text-muted" unless comment.visible? %>"><span title="<%= l comment.created_at, :format => :friendly %>"><%= time_ago_in_words(comment.created_at, :scope => :"datetime.distance_in_words_ago") %></span></td>
<td width="50%" class="richtext text-break<%= " text-muted" unless comment.visible? %>"><%= comment.body.to_html %></td>
</tr>
<% end -%>
</table>
<%= render "shared/pagination",
:newer_id => @newer_comments_id,
:older_id => @older_comments_id %>
</turbo-frame>

View file

@ -4,7 +4,10 @@
<h1><%= t ".heading_html", :user => link_to(@user.display_name, @user) %></h1>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active"><%= t ".diary_entries" %></a>
<%= link_to t(".diary_entries"), user_diary_comments_path, :class => ["nav-link", { "active" => controller_name == "diary_comments" }] %>
</li>
<li class="nav-item">
<%= link_to t(".changesets"), user_changeset_comments_path, :class => ["nav-link", { "active" => controller_name == "changeset_comments" }] %>
</li>
</ul>
<% end %>