Comments in legislation question page

This commit is contained in:
Amaia Castro
2016-12-22 23:00:37 +01:00
parent b2aa83ae4d
commit 55eb03531c
12 changed files with 59 additions and 14 deletions

View File

@@ -7,6 +7,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll
end
def create
@question.author = current_user
if @question.save
redirect_to admin_legislation_process_questions_path
else

View File

@@ -2,6 +2,11 @@ class Legislation::QuestionsController < Legislation::BaseController
load_and_authorize_resource :process
load_and_authorize_resource :question, through: :process
has_orders %w{most_voted newest oldest}, only: :show
def show
@commentable = @question
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
end
end

View File

@@ -1,8 +1,11 @@
class Legislation::Question < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
has_many :question_options, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
# has_many :answers
has_many :comments, as: :commentable
accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true

View File

@@ -1,7 +1,8 @@
class Legislation::QuestionOption < ActiveRecord::Base
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
# has_many :answers
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
validates :question, presence: true
validates :value, presence: true, uniqueness: { scope: :legislation_question_id }

View File

@@ -0,0 +1,29 @@
<% cache [locale_and_user_status, @current_order, commentable_cache_key(@question), @comment_tree.comments, @comment_tree.comment_authors, @question.comments_count, @comment_flags] do %>
<div class="row comments">
<div id="comments" class="small-12 column">
<h3>
<%= t("legislation.questions.show.comments") %>
<span class="js-comments-count">(<%= @question.comments_count %>)</span>
</h3>
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
<% if user_signed_in? %>
<%= render 'comments/form', {commentable: @question, 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

@@ -49,10 +49,4 @@
</div>
</section>
<hr />
<div class="row">
<div class="small-12 column">
<%= t('.comments') %>
</div>
</div>
<%= render 'comments' %>

View File

@@ -269,7 +269,7 @@ en:
other: "%{count} comments"
debate: Debate
show:
comments: COMMENTS
comments: Comments
next_question: Next question
share: Share
share_twitter: Share on Twitter

View File

@@ -269,7 +269,7 @@ es:
other: "%{count} comentarios"
debate: Debate
show:
comments: COMENTARIOS
comments: Comentarios
next_question: Siguiente pregunta
share: Compartir
share_twitter: Compartir en Twitter

View File

@@ -0,0 +1,5 @@
class AddCommentsCountToLegislationQuestions < ActiveRecord::Migration
def change
add_column :legislation_questions, :comments_count, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class AddAuthorToLegislationQuestions < ActiveRecord::Migration
def change
add_column :legislation_questions, :author_id, :integer
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161220120037) do
ActiveRecord::Schema.define(version: 20161222180927) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -293,6 +293,8 @@ ActiveRecord::Schema.define(version: 20161220120037) do
t.datetime "hidden_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "comments_count", default: 0
t.integer "author_id"
end
add_index "legislation_questions", ["hidden_at"], name: "index_legislation_questions_on_hidden_at", using: :btree