diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 71794ffe7..18e967e95 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -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 diff --git a/app/models/comment.rb b/app/models/comment.rb index 1db9809ee..8b68e11ad 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/topic.rb b/app/models/topic.rb index 04411ac91..6961e3f76 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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 diff --git a/app/views/topics/_comments.html.erb b/app/views/topics/_comments.html.erb new file mode 100644 index 000000000..ccab89847 --- /dev/null +++ b/app/views/topics/_comments.html.erb @@ -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 %> +
+
+ <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> + + <% if user_signed_in? %> + <%= render 'comments/form', {commentable: @topic, parent_id: nil, toggeable: false} %> + <% else %> +
+ +
+ <%= 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 %> +
+ <% end %> + + <% @comment_tree.root_comments.each do |comment| %> + <%= render 'comments/comment', comment: comment %> + <% end %> + <%= paginate @comment_tree.root_comments %> +
+
+<% end %> diff --git a/app/views/topics/_topics.html.erb b/app/views/topics/_topics.html.erb index e25897b4d..7c28e0d9a 100644 --- a/app/views/topics/_topics.html.erb +++ b/app/views/topics/_topics.html.erb @@ -6,10 +6,12 @@ <% topics.each do |topic| %>
<%= link_to topic.title, community_topic_path(@community, topic) %> -
- <%= topic.author.name %> -
- <%= I18n.l topic.created_at %> +

+ <%= link_to t("proposals.proposal.comments", count: topic.comments_count), community_topic_path(@community, topic, anchor: "comments") %> + <%= topic.author.name %> + <%= I18n.l topic.created_at %> +

+ <% if topic.author == current_user %> <%= link_to t("topic.edit"), edit_community_topic_path(@community.id, topic), class: 'button expanded' %> <% end %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 333b7b543..b44d3b7cf 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -3,3 +3,12 @@ Comunidad: <%= @community.proposal.title %>
<%= @topic.title %> + +
+ <%#= render "proposals/filter_subnav" %> + <%#= render "proposals/notifications" %> + +
+ <%= render "topics/comments" %> +
+
diff --git a/db/migrate/20170807082243_create_topics.rb b/db/migrate/20170807082243_create_topics.rb index 5c554ee88..047a7507c 100644 --- a/db/migrate/20170807082243_create_topics.rb +++ b/db/migrate/20170807082243_create_topics.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 1dd51131d..09047efe1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -891,14 +891,17 @@ ActiveRecord::Schema.define(version: 20170807082243) do add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree create_table "topics", force: :cascade do |t| - t.string "title", null: false + t.string "title", null: false t.integer "author_id" + t.integer "comments_count", default: 0 t.integer "community_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + 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: ""