diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 1bf679bb4..225748365 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -1,12 +1,4 @@ module CommentsHelper - def comment_tree_title_text(commentable) - if commentable.class == Legislation::Question - t("legislation.questions.comments.comments_title") - else - t("comments_helper.comments_title") - end - end - def leave_comment_text(commentable) if commentable.class == Legislation::Question t("legislation.questions.comments.form.leave_comment") diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb index 84204c907..8bf774553 100644 --- a/app/views/comments/_comment_tree.html.erb +++ b/app/views/comments/_comment_tree.html.erb @@ -4,25 +4,8 @@
- <% if display_comments_count %> -

- <%= comment_tree_title_text(commentable) %> - (<%= commentable.comments_count %>) -

- <% end %> - <% if user_signed_in? %> - <% if comments_closed_for_commentable?(commentable) %> -
-
- <%= comments_closed_text(commentable) %> -
- <% elsif require_verified_resident_for_commentable?(commentable, current_user) %> -
-
- <%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %> -
- <% elsif !valuation || can?(:comment_valuation, commentable) %> + <% if !valuation || can?(:comment_valuation, commentable) %> <%= render "comments/form", { commentable: commentable, parent_id: nil, valuation: valuation } %> diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 17813cace..2a49d2817 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,35 +1,47 @@ <% valuation = local_assigns.fetch(:valuation, false) %> <% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable), valuation] do %> - <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %> -
- <%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %> - <%= f.text_area :body, - id: "comment-body-#{css_id}", - maxlength: Comment.body_max_length, - label: leave_comment_text(commentable) %> + <% if comments_closed_for_commentable?(commentable) %> +
+
+ <%= comments_closed_text(commentable) %> +
+ <% elsif require_verified_resident_for_commentable?(commentable, current_user) %> +
+
+ <%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %> +
+ <% else %> + <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %> +
+ <%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %> + <%= f.text_area :body, + id: "comment-body-#{css_id}", + maxlength: Comment.body_max_length, + label: leave_comment_text(commentable) %> - <%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %> - <%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %> - <%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %> - <%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %> + <%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %> + <%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %> + <%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %> + <%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %> - <%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %> + <%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %> + + <% if can? :comment_as_moderator, commentable %> +
+ <%= f.check_box :as_moderator, + label: t("comments.form.comment_as_moderator"), + id: "comment-as-moderator-#{css_id}" %> +
+ <% end %> + <% if can? :comment_as_administrator, commentable %> +
+ <%= f.check_box :as_administrator, + label: t("comments.form.comment_as_admin"), + id: "comment-as-administrator-#{css_id}" %> +
+ <% end %> - <% if can? :comment_as_moderator, commentable %> -
- <%= f.check_box :as_moderator, - label: t("comments.form.comment_as_moderator"), - id: "comment-as-moderator-#{css_id}" %> -
<% end %> - <% if can? :comment_as_administrator, commentable %> -
- <%= f.check_box :as_administrator, - label: t("comments.form.comment_as_admin"), - id: "comment-as-administrator-#{css_id}" %> -
- <% end %> - - <% end %> -
+
+ <% end %> <% end %> diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index 3015cdd4c..e5e3eba6a 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -43,8 +43,12 @@
- <%= render "/comments/comment_tree", comment_tree: @comment_tree, - display_comments_count: true %> + <%= render Shared::CommentsComponent.new(@annotation, @comment_tree) do %> +

+ <%= t("comments_helper.comments_title") %> + (<%= @annotation.comments_count %>) +

+ <% end %>
diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 7663fab74..a85a13903 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -41,7 +41,10 @@ <%= render "/shared/social_share", title: @question.title, url: legislation_process_question_url(@question.process, @question) %> - - <%= render "/comments/comment_tree", comment_tree: @comment_tree, - display_comments_count: true %> + <%= render Shared::CommentsComponent.new(@question, @comment_tree) do %> +

+ <%= t("legislation.questions.comments.comments_title") %> + (<%= @question.comments_count %>) +

+ <% end %>
diff --git a/app/views/valuation/budget_investments/_valuation_comments.html.erb b/app/views/valuation/budget_investments/_valuation_comments.html.erb index 713727bb3..397f9af9b 100644 --- a/app/views/valuation/budget_investments/_valuation_comments.html.erb +++ b/app/views/valuation/budget_investments/_valuation_comments.html.erb @@ -1,6 +1,4 @@

<%= t("valuation.budget_investments.valuation_comments") %>

<% unless @comment_tree.nil? %> - <%= render "/comments/comment_tree", comment_tree: @comment_tree, - display_comments_count: false, - valuation: true %> + <%= render "/comments/comment_tree", comment_tree: @comment_tree, valuation: true %> <% end %>