merges master and fixes conflicts
This commit is contained in:
@@ -13,7 +13,6 @@ class DebatesController < ApplicationController
|
||||
@debates = @debates.page(params[:page]).for_render.send("sort_by_#{@order}")
|
||||
@tag_cloud = Debate.tag_counts.order(taggings_count: :desc, name: :asc).limit(20)
|
||||
set_debate_votes(@debates)
|
||||
ahoy.track_visit
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -24,7 +23,6 @@ class DebatesController < ApplicationController
|
||||
|
||||
@all_visible_comments = @root_comments + @comments
|
||||
set_comment_flags(@all_visible_comments)
|
||||
ahoy.track_visit
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
@@ -4,7 +4,6 @@ class StatsController < ApplicationController
|
||||
|
||||
def show
|
||||
@event_types = Ahoy::Event.select(:name).uniq.pluck(:name)
|
||||
@debates_created_count = Ahoy::Event.where(name: 'debate_created').count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -22,4 +22,9 @@ module CacheKeysHelper
|
||||
user_status
|
||||
end
|
||||
|
||||
# when commentable id and type are used but no need to update cache on updated_at changes
|
||||
def commentable_cache_key(commentable)
|
||||
"#{commentable.class.name}-#{commentable.id}"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
class StatsJob < ActiveJob::Base
|
||||
queue_as :default
|
||||
|
||||
def perform(*args)
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class Comment < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
acts_as_votable
|
||||
has_ancestry
|
||||
has_ancestry touch: true
|
||||
|
||||
attr_accessor :as_moderator, :as_administrator
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ class Debate < ActiveRecord::Base
|
||||
scope :sort_by_most_commented, -> { order(comments_count: :desc) }
|
||||
scope :sort_by_random, -> { order("RANDOM()") }
|
||||
|
||||
# Ahoy setup
|
||||
visitable # Ahoy will automatically assign visit_id on create
|
||||
|
||||
def likes
|
||||
cached_votes_up
|
||||
end
|
||||
|
||||
@@ -1,102 +1,104 @@
|
||||
<div class="row">
|
||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(@commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
|
||||
<div class="row">
|
||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||
|
||||
<% if comment.hidden? || comment.user.hidden? %>
|
||||
<% if select_children(@comments, comment).size > 0 %>
|
||||
<div class="is-deleted">
|
||||
<p><%= t("debates.comment.deleted") %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% if comment.as_administrator? %>
|
||||
<%= image_tag("admin_avatar.png", size: 32, class: "admin-avatar left") %>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar left") %>
|
||||
<% if comment.hidden? || comment.user.hidden? %>
|
||||
<% if select_children(@comments, comment).size > 0 %>
|
||||
<div class="is-deleted">
|
||||
<p><%= t("debates.comment.deleted") %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% if comment.user.organization? %>
|
||||
<%= image_tag("collective_avatar.png", size: 32, class: "avatar left") %>
|
||||
<% if comment.as_administrator? %>
|
||||
<%= image_tag("admin_avatar.png", size: 32, class: "admin-avatar left") %>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<%= image_tag("moderator_avatar.png", size: 32, class: "moderator-avatar left") %>
|
||||
<% else %>
|
||||
<%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "left") %>
|
||||
<% end %>
|
||||
<% if comment.user.hidden? %>
|
||||
<i class="icon-deleted user-deleted"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<div class="comment-body">
|
||||
<div class="comment-info">
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<span class="user-name"><%= t("debates.comment.admin") %> #<%= comment.administrator_id%></span>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<span class="user-name"><%= t("debates.comment.moderator") %> #<%= comment.moderator_id%></span>
|
||||
<% if comment.user.organization? %>
|
||||
<%= image_tag("collective_avatar.png", size: 32, class: "avatar left") %>
|
||||
<% else %>
|
||||
<%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "left") %>
|
||||
<% end %>
|
||||
<% if comment.user.hidden? %>
|
||||
<i class="icon-deleted user-deleted"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if comment.user.hidden? %>
|
||||
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
|
||||
<div class="comment-body">
|
||||
<div class="comment-info">
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<span class="user-name"><%= t("debates.comment.admin") %> #<%= comment.administrator_id%></span>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<span class="user-name"><%= t("debates.comment.moderator") %> #<%= comment.moderator_id%></span>
|
||||
<% else %>
|
||||
<span class="user-name"><%= comment.user.name %></span>
|
||||
<% if comment.user.official? %>
|
||||
|
||||
<% if comment.user.hidden? %>
|
||||
<span class="user-name"><%= t("debates.comment.user_deleted") %></span>
|
||||
<% else %>
|
||||
<span class="user-name"><%= comment.user.name %></span>
|
||||
<% if comment.user.official? %>
|
||||
•
|
||||
<span class="label round level-<%= comment.user.official_level %>">
|
||||
<%= comment.user.official_position %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if comment.user.verified_organization? %>
|
||||
•
|
||||
<span class="label round level-<%= comment.user.official_level %>">
|
||||
<%= comment.user.official_position %>
|
||||
<span class="label round is-association">
|
||||
<%= t("shared.collective") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if comment.user.verified_organization? %>
|
||||
•
|
||||
<span class="label round is-association">
|
||||
<%= t("shared.collective") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% if comment.user_id == @commentable.author_id %>
|
||||
•
|
||||
<span class="label round is-author">
|
||||
<%= t("debates.comment.author") %>
|
||||
</span>
|
||||
<% if comment.user_id == @commentable.author_id %>
|
||||
•
|
||||
<span class="label round is-author">
|
||||
<%= t("debates.comment.author") %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
• <time><%= l comment.created_at.to_datetime, format: :datetime %></time>
|
||||
</div>
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<p class="comment-user is-admin"><%= comment.body %></p>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<p class="comment-user is-moderator"><%= comment.body %></p>
|
||||
<% elsif comment.user.official? && comment.user_id == @commentable.author_id %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %> is-author"><%= comment.body %></p>
|
||||
<% elsif comment.user.official? %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %>"><%= comment.body %></p>
|
||||
<% elsif comment.user_id == @commentable.author_id %>
|
||||
<p class="comment-user is-author"><%= comment.body %></p>
|
||||
<% else %>
|
||||
<p class="comment-user"><%= comment.body %></p>
|
||||
<% end %>
|
||||
<span id="<%= dom_id(comment) %>_votes" class="comment-votes right">
|
||||
<%= render 'comments/votes', comment: comment %>
|
||||
</span>
|
||||
|
||||
• <%= time_ago_in_words(comment.created_at) %>
|
||||
<div class="reply">
|
||||
<%= t("debates.comment.responses", count: select_children(@comments, comment).size) %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<span class="divider"> | </span>
|
||||
<%= link_to(comment_link_text(comment), "",
|
||||
class: "js-add-comment-link", data: {'id': dom_id(comment)}) %>
|
||||
|
||||
<%= render 'comments/actions', comment: comment %>
|
||||
|
||||
<%= render 'comments/form', {commentable: @commentable, parent_id: comment.id, toggeable: true} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<p class="comment-user is-admin"><%= comment.body %></p>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<p class="comment-user is-moderator"><%= comment.body %></p>
|
||||
<% elsif comment.user.official? && comment.user_id == @commentable.author_id %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %> is-author"><%= comment.body %></p>
|
||||
<% elsif comment.user.official? %>
|
||||
<p class="comment-user level-<%= comment.user.official_level %>"><%= comment.body %></p>
|
||||
<% elsif comment.user_id == @commentable.author_id %>
|
||||
<p class="comment-user is-author"><%= comment.body %></p>
|
||||
<% else %>
|
||||
<p class="comment-user"><%= comment.body %></p>
|
||||
<% end %>
|
||||
<div class="comment-children">
|
||||
<% select_children(@comments, comment).each do |child| %>
|
||||
<%= render 'comments/comment', comment: child %>
|
||||
<% end %>
|
||||
<span id="<%= dom_id(comment) %>_votes" class="comment-votes right">
|
||||
<%= render 'comments/votes', comment: comment %>
|
||||
</span>
|
||||
|
||||
<div class="reply">
|
||||
<%= t("debates.comment.responses", count: select_children(@comments, comment).size) %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<span class="divider"> | </span>
|
||||
<%= link_to(comment_link_text(comment), "",
|
||||
class: "js-add-comment-link", data: {'id': dom_id(comment)}) %>
|
||||
|
||||
<%= render 'comments/actions', comment: comment %>
|
||||
|
||||
<%= render 'comments/form', {commentable: @commentable, parent_id: comment.id, toggeable: true} %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="comment-children">
|
||||
<% select_children(@comments, comment).each do |child| %>
|
||||
<%= render 'comments/comment', comment: child %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,26 +1,28 @@
|
||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
|
||||
<%= form_for [commentable, Comment.new], remote: true do |f| %>
|
||||
<%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %>
|
||||
<%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment::BODY_LENGTH[:maximum], label: false %>
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id %>
|
||||
<% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable)] do %>
|
||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
|
||||
<%= form_for [commentable, Comment.new], remote: true do |f| %>
|
||||
<%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %>
|
||||
<%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment::BODY_LENGTH[:maximum], label: false %>
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id %>
|
||||
|
||||
<%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %>
|
||||
<%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %>
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>
|
||||
<div class="right">
|
||||
<%= f.check_box :as_moderator, id: "comment-as-moderator-#{css_id}", label: false %>
|
||||
<%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="right">
|
||||
<%= f.check_box :as_administrator, id: "comment-as-administrator-#{css_id}",label: false %>
|
||||
<%= label_tag "comment-as-administrator-#{css_id}", t("comments.form.comment_as_admin"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>
|
||||
<div class="right">
|
||||
<%= f.check_box :as_moderator, id: "comment-as-moderator-#{css_id}", label: false %>
|
||||
<%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="right">
|
||||
<%= f.check_box :as_administrator, id: "comment-as-administrator-#{css_id}",label: false %>
|
||||
<%= label_tag "comment-as-administrator-#{css_id}", t("comments.form.comment_as_admin"), class: "checkbox" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
<section class="row-full comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
<% cache [locale_and_user_status, commentable_cache_key(@debate), @all_visible_comments, @all_visible_comments.map(&:author), @debate.comments_count, @comment_flags] do %>
|
||||
<section class="row-full comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
<h2>
|
||||
<%= t("debates.show.comments_title") %>
|
||||
<span>(<%= @debate.comments_count %>)</span>
|
||||
</h2>
|
||||
|
||||
<h2>
|
||||
<%= t("debates.show.comments_title") %>
|
||||
<span>(<%= @debate.comments_count %>)</span>
|
||||
</h2>
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %>
|
||||
<% else %>
|
||||
<br>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %>
|
||||
<% else %>
|
||||
<br>
|
||||
<div class="alert-box radius info">
|
||||
<%= 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 %>
|
||||
|
||||
<div class="alert-box radius info">
|
||||
<%= 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 %>
|
||||
|
||||
<% @root_comments.each do |comment| %>
|
||||
<%= render 'comments/comment', comment: comment %>
|
||||
<% end %>
|
||||
<%= paginate @root_comments %>
|
||||
<% @root_comments.each do |comment| %>
|
||||
<%= render 'comments/comment', comment: comment %>
|
||||
<% end %>
|
||||
<%= paginate @root_comments %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
<% end %>
|
||||
@@ -4,7 +4,7 @@
|
||||
<h2>Stats</h2>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<h3>Visits (<%= Visit.count %>) </h3>
|
||||
<h3>Visits</h3>
|
||||
<%= visits_chart_tag id: "visits" %>
|
||||
</div>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<div class="small-12">
|
||||
<% @event_types.each do |event_type| %>
|
||||
<h3><%= event_type.titleize %> (<%= @debates_created_count %>)</h3>
|
||||
<h3><%= event_type.titleize %></h3>
|
||||
<%= events_chart_tag event_type %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user