Add comments to topics
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
class TopicsController < ApplicationController
|
||||
# include CommentableActions
|
||||
include CommentableActions
|
||||
|
||||
before_action :set_community
|
||||
|
||||
has_orders %w{most_voted newest oldest}, only: :show
|
||||
|
||||
skip_authorization_check
|
||||
|
||||
def new
|
||||
@@ -21,6 +23,9 @@ class TopicsController < ApplicationController
|
||||
|
||||
def show
|
||||
@topic = Topic.find(params[:id])
|
||||
@commentable = @topic
|
||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||
set_comment_flags(@comment_tree.comments)
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
@@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base
|
||||
include HasPublicAuthor
|
||||
include Graphqlable
|
||||
|
||||
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation).freeze
|
||||
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Annotation Topic).freeze
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
class Topic < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
belongs_to :community
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
|
||||
has_many :comments, as: :commentable
|
||||
end
|
||||
|
||||
24
app/views/topics/_comments.html.erb
Normal file
24
app/views/topics/_comments.html.erb
Normal file
@@ -0,0 +1,24 @@
|
||||
<% cache [locale_and_user_status, @current_order, commentable_cache_key(@topic), @comment_tree.comments, @comment_tree.comment_authors, @topic.comments_count, @comment_flags] do %>
|
||||
<div class="row comments">
|
||||
<div id="comments" class="small-12 column">
|
||||
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @topic, parent_id: nil, toggeable: false} %>
|
||||
<% else %>
|
||||
<br>
|
||||
|
||||
<div data-alert class="callout primary">
|
||||
<%= t("topics.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 %>
|
||||
@@ -6,10 +6,12 @@
|
||||
<% topics.each do |topic| %>
|
||||
<div id="<%= dom_id(topic) %>">
|
||||
<%= link_to topic.title, community_topic_path(@community, topic) %>
|
||||
<br>
|
||||
<p class="topic-info">
|
||||
<%= link_to t("proposals.proposal.comments", count: topic.comments_count), community_topic_path(@community, topic, anchor: "comments") %>
|
||||
<%= topic.author.name %>
|
||||
<br>
|
||||
<%= I18n.l topic.created_at %>
|
||||
</p>
|
||||
|
||||
<% if topic.author == current_user %>
|
||||
<%= link_to t("topic.edit"), edit_community_topic_path(@community.id, topic), class: 'button expanded' %>
|
||||
<% end %>
|
||||
|
||||
@@ -3,3 +3,12 @@
|
||||
Comunidad: <%= @community.proposal.title %>
|
||||
<br>
|
||||
<%= @topic.title %>
|
||||
|
||||
<div class="tabs-content" data-tabs-content="proposals-tabs" role="tablist">
|
||||
<%#= render "proposals/filter_subnav" %>
|
||||
<%#= render "proposals/notifications" %>
|
||||
|
||||
<div class="tabs-panel is-active" id="tab-comments">
|
||||
<%= render "topics/comments" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,9 @@ class CreateTopics < ActiveRecord::Migration
|
||||
create_table :topics do |t|
|
||||
t.string :title, null: false
|
||||
t.integer :author_id
|
||||
t.integer "comments_count", default: 0
|
||||
t.references :community, index: true
|
||||
t.datetime :hidden_at, index: true
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -893,12 +893,15 @@ ActiveRecord::Schema.define(version: 20170807082243) do
|
||||
create_table "topics", force: :cascade do |t|
|
||||
t.string "title", null: false
|
||||
t.integer "author_id"
|
||||
t.integer "comments_count", default: 0
|
||||
t.integer "community_id"
|
||||
t.datetime "hidden_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "topics", ["community_id"], name: "index_topics_on_community_id", using: :btree
|
||||
add_index "topics", ["hidden_at"], name: "index_topics_on_hidden_at", using: :btree
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: ""
|
||||
|
||||
Reference in New Issue
Block a user