adds proposal show
This commit is contained in:
@@ -78,6 +78,10 @@ class ApplicationController < ActionController::Base
|
||||
@debate_votes = current_user ? current_user.debate_votes(debates) : {}
|
||||
end
|
||||
|
||||
def set_proposal_votes(proposals)
|
||||
@proposal_votes = current_user ? current_user.proposal_votes(proposals) : {}
|
||||
end
|
||||
|
||||
def set_comment_flags(comments)
|
||||
@comment_flags = current_user ? current_user.comment_flags(comments) : {}
|
||||
end
|
||||
|
||||
@@ -5,7 +5,13 @@ class ProposalsController < ApplicationController
|
||||
respond_to :html, :js
|
||||
|
||||
def show
|
||||
render text: ""
|
||||
set_proposal_votes(@proposal)
|
||||
@commentable = @proposal
|
||||
@root_comments = @proposal.comments.roots.recent.page(params[:page]).per(10).for_render
|
||||
@comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render}
|
||||
|
||||
@all_visible_comments = @root_comments + @comments
|
||||
set_comment_flags(@all_visible_comments)
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
@@ -11,4 +11,13 @@ module VotesHelper
|
||||
end
|
||||
end
|
||||
|
||||
def css_classes_for_proposal_vote(proposal_votes, proposal)
|
||||
case proposal_votes[proposal.id]
|
||||
when true
|
||||
{in_favor: "voted"}
|
||||
else
|
||||
{in_favor: ""}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
class Proposal < ActiveRecord::Base
|
||||
apply_simple_captcha
|
||||
acts_as_votable
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
has_many :comments, as: :commentable
|
||||
has_many :flags, as: :flaggable
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
validates :title, presence: true
|
||||
validates :question, presence: true
|
||||
validates :description, presence: true
|
||||
@@ -21,6 +21,28 @@ class Proposal < ActiveRecord::Base
|
||||
before_validation :sanitize_description
|
||||
before_validation :sanitize_tag_list
|
||||
|
||||
def total_votes
|
||||
cached_votes_up
|
||||
end
|
||||
|
||||
def conflictive?
|
||||
return false unless flags_count > 0 && cached_votes_up > 0
|
||||
cached_votes_up/flags_count.to_f < 5
|
||||
end
|
||||
|
||||
def tag_list_with_limit(limit = nil)
|
||||
return tags if limit.blank?
|
||||
|
||||
tags.sort{|a,b| b.taggings_count <=> a.taggings_count}[0, limit]
|
||||
end
|
||||
|
||||
def tags_count_out_of_limit(limit = nil)
|
||||
return 0 unless limit
|
||||
|
||||
count = tags.size - limit
|
||||
count < 0 ? 0 : count
|
||||
end
|
||||
|
||||
def self.title_max_length
|
||||
@@title_max_length ||= self.columns.find { |c| c.name == 'title' }.limit || 80
|
||||
end
|
||||
@@ -33,6 +55,18 @@ class Proposal < ActiveRecord::Base
|
||||
6000
|
||||
end
|
||||
|
||||
def editable?
|
||||
total_votes <= 1000
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
editable? && author == user
|
||||
end
|
||||
|
||||
def votable_by?(user)
|
||||
user.level_two_verified? || !user.voted_for?(self)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def sanitize_description
|
||||
|
||||
@@ -86,6 +86,11 @@ class User < ActiveRecord::Base
|
||||
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
|
||||
end
|
||||
|
||||
def proposal_votes(proposals)
|
||||
voted = votes.for_proposals(proposals)
|
||||
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
|
||||
end
|
||||
|
||||
def comment_flags(comments)
|
||||
comment_flags = flags.for_comments(comments)
|
||||
comment_flags.each_with_object({}){ |f, h| h[f.flaggable_id] = true }
|
||||
|
||||
10
app/views/proposals/_actions.html.erb
Normal file
10
app/views/proposals/_actions.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<% if can? :hide, proposal %>
|
||||
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_proposal_path(proposal),
|
||||
method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %>
|
||||
<% end %>
|
||||
|
||||
<% if can? :hide, proposal.author %>
|
||||
|
|
||||
<%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(proposal.author_id),
|
||||
method: :put, data: { confirm: t('admin.actions.confirm') } %>
|
||||
<% end %>
|
||||
27
app/views/proposals/_comments.html.erb
Normal file
27
app/views/proposals/_comments.html.erb
Normal file
@@ -0,0 +1,27 @@
|
||||
<section class="row-full comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
<h2>
|
||||
<%= t("proposals.show.comments_title") %>
|
||||
<span>(<%= @proposal.comments_count %>)</span>
|
||||
</h2>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @proposal, parent_id: nil, toggeable: false} %>
|
||||
<% else %>
|
||||
<br>
|
||||
|
||||
<div class="alert-box radius info">
|
||||
<%= t("proposals.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 %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
21
app/views/proposals/_flag_actions.html.erb
Normal file
21
app/views/proposals/_flag_actions.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<% if show_flag_action? proposal %>
|
||||
<a id="flag-expand-proposal-<%= proposal.id %>" data-dropdown="flag-drop-proposal-<%= proposal.id %>" aria-controls="flag-drop-proposal-<%= proposal.id %>" aria-expanded="false" title="<%= t('shared.flag') %>">
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
</a>
|
||||
<ul id="flag-drop-proposal-<%= proposal.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t('shared.flag'), flag_proposal_path(proposal), method: :put, remote: true, id: "flag-proposal-#{ proposal.id }" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if show_unflag_action? proposal %>
|
||||
<a id="unflag-expand-proposal-<%= proposal.id %>" data-dropdown="unflag-drop-proposal-<%= proposal.id %>" aria-controls="unflag-drop-proposal-<%= proposal.id %>" aria-expanded="false" title="<%= t('shared.unflag') %>">
|
||||
<i class="icon-flag flag-active"></i>
|
||||
</a>
|
||||
<ul id="unflag-drop-proposal-<%= proposal.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t('shared.unflag'), unflag_proposal_path(proposal), method: :put, remote: true, id: "unflag-proposal-#{ proposal.id }" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
37
app/views/proposals/_votes.html.erb
Normal file
37
app/views/proposals/_votes.html.erb
Normal file
@@ -0,0 +1,37 @@
|
||||
<% voted_classes = css_classes_for_proposal_vote(@proposal_votes, proposal) %>
|
||||
<div class="votes">
|
||||
<div class="in-favor inline-block">
|
||||
<%= link_to vote_proposal_path(proposal, value: 'yes'),
|
||||
class: "like #{voted_classes[:in_favor]}", title: t('votes.agree'), method: "post", remote: true do %>
|
||||
<i class="icon-like"></i>
|
||||
<span><%= percentage('likes', proposal) %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<span class="divider"></span>
|
||||
|
||||
<span class="total-votes">
|
||||
<%= t("proposals.proposal.votes", count: proposal.total_votes) %>
|
||||
</span>
|
||||
|
||||
<% if user_signed_in? && current_user.organization? %>
|
||||
<div class="organizations-votes" style='display:none'>
|
||||
<p>
|
||||
<%= t("votes.organizations") %>
|
||||
</p>
|
||||
</div>
|
||||
<% elsif user_signed_in? && !proposal.votable_by?(current_user)%>
|
||||
<div class="anonymous-votes" style='display:none'>
|
||||
<p>
|
||||
<%= t("votes.anonymous",
|
||||
verify_account: link_to(t("votes.verify_account"), verification_path )).html_safe %>
|
||||
</p>
|
||||
</div>
|
||||
<% elsif !user_signed_in? %>
|
||||
<div class="not-logged" style='display:none'>
|
||||
<%= t("votes.unauthenticated",
|
||||
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>
|
||||
83
app/views/proposals/show.html.erb
Normal file
83
app/views/proposals/show.html.erb
Normal file
@@ -0,0 +1,83 @@
|
||||
<section class="proposal-show">
|
||||
<div id="<%= dom_id(@proposal) %>" class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<i class="icon-angle-left left"></i>
|
||||
<%= link_to t("proposals.show.back_link"), proposals_path, class: 'left back' %>
|
||||
|
||||
<% if current_user && @proposal.editable_by?(current_user) %>
|
||||
<%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button success tiny radius right' do %>
|
||||
<i class="icon-edit"></i>
|
||||
<%= t("proposals.show.edit_proposal_link") %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<h1><%= @proposal.title %></h1>
|
||||
<% if @proposal.conflictive? %>
|
||||
<div class="alert-box alert radius margin-top">
|
||||
<strong><%= t("proposals.show.flag") %></strong>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="proposal-info">
|
||||
<%= avatar_image(@proposal.author, seed: @proposal.author_id, size: 32, class: 'author-photo') %>
|
||||
|
||||
<% if @proposal.author.hidden? %>
|
||||
<i class="icon-deleted author-deleted"></i>
|
||||
<span class="author">
|
||||
<%= t("proposals.show.author_deleted") %>
|
||||
</span>
|
||||
<% else %>
|
||||
<span class="author">
|
||||
<%= @proposal.author.name %>
|
||||
</span>
|
||||
<% if @proposal.author.official? %>
|
||||
•
|
||||
<span class="label round level-<%= @proposal.author.official_level %>">
|
||||
<%= @proposal.author.official_position %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @proposal.author.verified_organization? %>
|
||||
•
|
||||
<span class="label round is-association">
|
||||
<%= t("shared.collective") %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<span class="bullet"> • </span>
|
||||
<%= l @proposal.created_at.to_date %>
|
||||
<span class="bullet"> • </span>
|
||||
<i class="icon-comments"></i>
|
||||
<%= link_to t("proposals.show.comments", count: @proposal.comments_count), "#comments" %>
|
||||
<span class="bullet"> • </span>
|
||||
<span class="js-flag-actions">
|
||||
<%= render 'proposals/flag_actions', proposal: @proposal %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<%= @proposal.description %>
|
||||
|
||||
<%= render 'shared/tags', proposal: @proposal %>
|
||||
|
||||
<div class='js-moderator-proposal-actions'>
|
||||
<%= render 'actions', proposal: @proposal %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="small-12 medium-3 column">
|
||||
<div class="sidebar-divider"></div>
|
||||
<h3><%= t("votes.supports") %></h3>
|
||||
<div class="text-center">
|
||||
<div id="<%= dom_id(@proposal) %>_votes">
|
||||
<%= render 'proposals/votes', proposal: @proposal %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h3><%= t("proposals.show.share") %></h3>
|
||||
<%= social_share_button_tag(@proposal.title) %>
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<%= render "comments" %>
|
||||
@@ -1,13 +1,15 @@
|
||||
<%- limit ||= nil %>
|
||||
<%= taggable = defined?(debate) ? debate : proposal %>
|
||||
|
||||
<% if debate.tags.any? %>
|
||||
<% if taggable.tags.any? %>
|
||||
<span class='tags'>
|
||||
<% debate.tag_list_with_limit(limit).each do |tag| %>
|
||||
<%= link_to sanitize(tag.name), debates_path(tag: tag.name) %>
|
||||
<% taggable.tag_list_with_limit(limit).each do |tag| %>
|
||||
<%= link_to sanitize(tag.name), send("#{taggable.class.to_s.downcase}_path", tag: tag.name) %>
|
||||
<% end %>
|
||||
|
||||
<% if debate.tags_count_out_of_limit(limit) > 0 %>
|
||||
<%= link_to "#{debate.tags_count_out_of_limit(limit)}+", debate_path(debate) %>
|
||||
<% if taggable.tags_count_out_of_limit(limit) > 0 %>
|
||||
<%= link_to "#{taggable.tags_count_out_of_limit(limit)}+",
|
||||
send("#{taggable.class.to_s.downcase}_path", taggable) %>
|
||||
<% end %>
|
||||
</span>
|
||||
<% end %>
|
||||
@@ -3,6 +3,10 @@ ActsAsVotable::Vote.class_eval do
|
||||
where(votable_type: 'Debate', votable_id: debates)
|
||||
end
|
||||
|
||||
def self.for_proposals(proposals)
|
||||
where(votable_type: 'Debate', votable_id: proposals)
|
||||
end
|
||||
|
||||
def value
|
||||
vote_flag
|
||||
end
|
||||
|
||||
@@ -45,7 +45,21 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resources :proposals
|
||||
resources :proposals do
|
||||
member do
|
||||
post :vote
|
||||
put :flag
|
||||
put :unflag
|
||||
end
|
||||
|
||||
resources :comments, only: :create, shallow: true do
|
||||
member do
|
||||
post :vote
|
||||
put :flag
|
||||
put :unflag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resource :account, controller: "account", only: [:show, :update]
|
||||
resource :verification, controller: "verification", only: [:show]
|
||||
|
||||
Reference in New Issue
Block a user