diff --git a/app/assets/javascripts/legislation.js.coffee b/app/assets/javascripts/legislation.js.coffee index cd4e90bc3..3eb53e6d2 100644 --- a/app/assets/javascripts/legislation.js.coffee +++ b/app/assets/javascripts/legislation.js.coffee @@ -4,7 +4,7 @@ App.Legislation = $('#js-toggle-debate').on click: -> $('#debate-show').toggle() - + $('#js-toggle-small-debate').on click: -> $('#debate-show').toggle() diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index 6f5069763..c97165e2a 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -1,7 +1,7 @@ class Legislation::AnnotationsController < ApplicationController skip_before_action :verify_authenticity_token - before_action :authenticate_user!, only: [:create] + before_action :authenticate_user!, only: [:create, :new_comment] before_action :convert_ranges_parameters, only: [:create] load_and_authorize_resource :process @@ -43,6 +43,7 @@ class Legislation::AnnotationsController < ApplicationController def comments @annotation = Legislation::Annotation.find(params[:annotation_id]) + @comment = @annotation.comments.new end def new @@ -51,6 +52,19 @@ class Legislation::AnnotationsController < ApplicationController end end + def new_comment + @draft_version = Legislation::DraftVersion.find(params[:draft_version_id]) + @annotation = @draft_version.annotations.find(params[:annotation_id]) + @comment = @annotation.comments.new(body: params[:comment][:body], user: current_user) + if @comment.save + @comment = @annotation.comments.new + end + + respond_to do |format| + format.js { render :comments } + end + end + private def annotation_params diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index ae3dc432d..4d44f14eb 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -20,7 +20,7 @@ module Abilities can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer - can [:search, :comments, :read, :create], Legislation::Annotation + can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation end end end diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index 4f33d45ef..2a543566c 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -1,12 +1,12 @@
-
<%= t('legislation.annotations.comments.comments_count', count: annotation.comments_count) %>
+
<%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> <% end %>
- <% annotation.comments.roots.limit(5).each do |comment| %> + <% annotation.comments.roots.sort_by_newest.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>

<%= truncate comment.body, length: 250 %>

@@ -36,11 +36,39 @@ <% end %>
+ + diff --git a/app/views/legislation/annotations/comments.js.erb b/app/views/legislation/annotations/comments.js.erb index 75d8f35a0..c68cfc120 100644 --- a/app/views/legislation/annotations/comments.js.erb +++ b/app/views/legislation/annotations/comments.js.erb @@ -1,2 +1,11 @@ $("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>").show(); +$('a.publish-comment').on({ + click: function(e) { + e.preventDefault(); + $('a.publish-comment').hide(); + $('#js-comment-form-annotation').toggle(); + return; + } +}); + diff --git a/config/routes.rb b/config/routes.rb index 774efb37c..f5b65420e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -114,6 +114,7 @@ Rails.application.routes.draw do resources :annotations do get :search, on: :collection get :comments + post :new_comment end end end