Legislation annotations/comments page

This commit is contained in:
Amaia Castro
2017-01-05 22:59:35 +01:00
parent 068c2c9f3d
commit b8f034d896
21 changed files with 743 additions and 21 deletions

View File

@@ -7,9 +7,20 @@ class Legislation::AnnotationsController < ApplicationController
load_and_authorize_resource :draft_version, through: :process
load_and_authorize_resource
has_orders %w{most_voted newest oldest}, only: :show
def index
end
def show
@commentable = @annotation
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
end
def create
@annotation = Legislation::Annotation.new(annotation_params)
@annotation.user = current_user
@annotation.author = current_user
if @annotation.save
render json: @annotation.to_json
end
@@ -23,10 +34,11 @@ class Legislation::AnnotationsController < ApplicationController
private
def annotation_params
params
.require(:annotation)
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset])
.merge(legislation_draft_version_id: params[:legislation_draft_version_id])
end
def annotation_params
params
.require(:annotation)
.permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset])
.merge(legislation_draft_version_id: params[:legislation_draft_version_id])
end
end

View File

@@ -10,4 +10,8 @@ module LegislationHelper
def legislation_question_path(question)
legislation_process_question_path(question.process, question)
end
def legislation_annotation_path(annotation)
legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation)
end
end

View File

@@ -33,7 +33,7 @@ module Abilities
can :mark_featured, Debate
can :unmark_featured, Debate
can :comment_as_administrator, [Debate, Comment, Proposal, Legislation::Question]
can :comment_as_administrator, [Debate, Comment, Proposal, Legislation::Question, Legislation::Annotation]
can [:search, :create, :index, :destroy], ::Moderator
can [:search, :create, :index, :summary], ::Valuator
@@ -49,7 +49,7 @@ module Abilities
can [:manage], ::Legislation::Process
can [:manage], ::Legislation::DraftVersion
can [:manage], ::Legislation::Question
cannot :comment_as_moderator, ::Legislation::Question
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation]
end
end
end

View File

@@ -5,7 +5,7 @@ module Abilities
def initialize(user)
self.merge Abilities::Moderation.new(user)
can :comment_as_moderator, [Debate, Comment, Proposal, Legislation::Question]
can :comment_as_moderator, [Debate, Comment, Proposal, Legislation::Question, Legislation::Annotation]
end
end
end

View File

@@ -10,7 +10,7 @@ class Comment < ActiveRecord::Base
validates :body, presence: true
validates :user, presence: true
validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question"]
validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question", "Legislation::Annotation"]
validate :validate_body_length

View File

@@ -1,6 +1,19 @@
class Legislation::Annotation < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
serialize :ranges, Array
belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id'
belongs_to :user
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
has_many :comments, as: :commentable
validates :text, presence: true
validates :quote, presence: true
validates :draft_version, presence: true
validates :author, presence: true
def title
text[0..50]
end
end

View File

@@ -1,4 +1,7 @@
class Legislation::Answer < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :answers, counter_cache: true
belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', inverse_of: :answers, counter_cache: true
belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers

View File

@@ -5,6 +5,7 @@ class Legislation::DraftVersion < ActiveRecord::Base
include ActsAsParanoidAliases
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id'
validates :title, presence: true
validates :body, presence: true

View File

@@ -0,0 +1,29 @@
<% cache [locale_and_user_status, @current_order, commentable_cache_key(commentable), @comment_tree.comments, @comment_tree.comment_authors, commentable.comments_count, @comment_flags] do %>
<div class="row comments">
<div id="comments" class="small-12 column">
<h3>
<%= t("legislation.annotations.show.comments") %>
<span class="js-comments-count">(<%= commentable.comments_count %>)</span>
</h3>
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
<% if user_signed_in? %>
<%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %>
<% else %>
<br>
<div data-alert class="callout primary">
<%= t("debates.show.login_to_comment",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% @comment_tree.root_comments.each do |comment| %>
<%= render 'comments/comment', comment: comment %>
<% end %>
<%= paginate @comment_tree.root_comments %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,16 @@
<div class="row draft-chooser">
<div class="small-12 medium-9 column">
<h3><%= t('.seeing_version') %></h3>
<div class="select-box">
<%= form_tag go_to_version_legislation_process_draft_versions_path(process), method: :get, id: "draft_version_go_to_version" do %>
<%= select_tag "draft_version_id", options_from_collection_for_select(process.draft_versions.published, 'id', 'display_title', draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %>
<%= hidden_field_tag "redirect_action", "annotations" %>
<%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %>
<% end %>
</div>
<span><%= t('legislation.draft_versions.show.updated_at', date: format_date(@draft_version.updated_at)) %></span>
</div>
<div class="small-12 medium-3 column">
<%= link_to t('.see_text'), legislation_process_draft_version_annotations_path(process, draft_version), title: t('.see_text'), class: "button strong" %>
</div>
</div>

View File

@@ -0,0 +1,35 @@
<% provide :title do %><%= "#{t('.title')} - #{@draft_version.title} - #{@process.title}" %><% end %>
<%= render 'legislation/processes/header', process: @process, header: :small %>
<div class="column row">
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %>
<div class="draft-panels small-12 column row">
<%= render 'version_chooser', process: @process, draft_version: @draft_version %>
<div class="row">
<div class="small-12 medium-8 column legislation-comments">
<% @annotations.each do |annotation| %>
<div class="comment">
<strong><%= t('.comments_about') %></strong>
<span class="pull-right">
<%= link_to legislation_process_draft_version_path(@process, @draft_version, anchor: "annotation-id-#{annotation.id}") do %>
<span><%= t('.see_in_context') %></span> <span class="icon-expand" aria-hidden="true"></span>
<% end %>
</span>
<div class="comment-section">
<%= annotation.quote %>
</div>
<%= link_to legislation_process_draft_version_annotation_path(@process, @draft_version, annotation) do %>
<span class="icon-comments" aria-hidden="true"></span> <span><%= t('.comments_count', count: annotation.comments_count + 1) %></span></a>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,42 @@
<% provide :title do %><%= "#{t('.title')} - #{@draft_version.title} - #{@process.title}" %><% end %>
<%= render 'legislation/processes/header', process: @process, header: :small %>
<div class="column row">
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %>
<div class="draft-panels small-12 column row">
<%= render 'version_chooser', process: @process, draft_version: @draft_version %>
<div class="row">
<div class="small-12 medium-12 column legislation-comment">
<div class="annotation-comment">
<strong><%= t('legislation.annotations.index.comments_about') %></strong>
<div class="comment-section">
<div class="row">
<div class="small-12 medium-10 column legislation-comment">
<%= @annotation.quote %>
</div>
<div class="small-12 medium-2 column legislation-comment">
<span class="pull-right">
<%= link_to legislation_process_draft_version_path(@process, @draft_version, anchor: "annotation-id-#{@annotation.id}") do %>
<span><%= t('legislation.annotations.index.see_in_context') %></span> <span class="icon-expand" aria-hidden="true"></span>
<% end %>
</span>
</div>
</div>
</div>
<div class="row">
<div class="small-12 medium-10 column legislation-comment">
<%= @annotation.text %>
</div>
</div>
<%= render 'comments', commentable: @annotation %>
</div>
</div>
</div>
</div>

View File

@@ -68,7 +68,4 @@
</div>
</div>
</div>
</div>