adds proposal's index

This commit is contained in:
rgarcia
2015-09-12 12:47:28 +02:00
parent 845ca22152
commit 3fc4cf0c1b
5 changed files with 119 additions and 1 deletions

View File

@@ -1,9 +1,20 @@
class ProposalsController < ApplicationController class ProposalsController < ApplicationController
before_action :parse_order, only: :index
before_action :parse_tag_filter, only: :index
before_action :parse_search_terms, only: :index
before_action :authenticate_user!, except: [:index, :show] before_action :authenticate_user!, except: [:index, :show]
load_and_authorize_resource load_and_authorize_resource
respond_to :html, :js respond_to :html, :js
def index
@proposals = @search_terms.present? ? Proposal.search(@search_terms) : Proposal.all
@proposals = @proposals.tagged_with(@tag_filter) if @tag_filter
@proposals = @proposals.page(params[:page]).for_render.send("sort_by_#{@order}")
@tag_cloud = Proposal.tag_counts.order(taggings_count: :desc, name: :asc).limit(20)
set_proposal_votes(@proposals)
end
def show def show
set_proposal_votes(@proposal) set_proposal_votes(@proposal)
@commentable = @proposal @commentable = @proposal
@@ -55,4 +66,19 @@ class ProposalsController < ApplicationController
def load_featured_tags def load_featured_tags
@featured_tags = ActsAsTaggableOn::Tag.where(featured: true) @featured_tags = ActsAsTaggableOn::Tag.where(featured: true)
end end
def parse_order
@valid_orders = ['confidence_score', 'hot_score', 'created_at', 'most_commented', 'random']
@order = @valid_orders.include?(params[:order]) ? params[:order] : @valid_orders.first
end
def parse_tag_filter
if params[:tag].present?
@tag_filter = params[:tag] if ActsAsTaggableOn::Tag.where(name: params[:tag]).exists?
end
end
def parse_search_terms
@search_terms = params[:search] if params[:search].present?
end
end end

View File

@@ -21,6 +21,13 @@ class Proposal < ActiveRecord::Base
before_validation :sanitize_description before_validation :sanitize_description
before_validation :sanitize_tag_list before_validation :sanitize_tag_list
scope :for_render, -> { includes(:tags) }
scope :sort_by_hot_score , -> { order(hot_score: :desc) }
scope :sort_by_confidence_score , -> { order(confidence_score: :desc) }
scope :sort_by_created_at, -> { order(created_at: :desc) }
scope :sort_by_most_commented, -> { order(comments_count: :desc) }
scope :sort_by_random, -> { order("RANDOM()") }
def total_votes def total_votes
cached_votes_up cached_votes_up
end end

View File

@@ -0,0 +1,30 @@
<div id="<%= dom_id(proposal) %>" class="proposal clear">
<div class="panel">
<div class="row">
<div class="small-12 medium-9 column">
<div class="proposal-content">
<span class="label left"><%= t("proposals.proposal.proposal") %></span>
<i class="icon-proposals"></i>
<h3><%= link_to proposal.title, proposal %></h3>
<p class="proposal-info">
<i class="icon-comments"></i>&nbsp;
<%= link_to t("proposals.proposal.comments", count: proposal.comments_count), proposal_path(proposal, anchor: "comments") %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l proposal.created_at.to_date %>
</p>
<div class="proposal-description">
<%= link_to proposal.description, proposal %>
<div class="truncate"></div>
</div>
<%= render "shared/tags", proposal: proposal, limit: 5 %>
</div>
</div>
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column text-center">
<%= render 'proposals/votes', proposal: proposal %>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,55 @@
<section role="main">
<div class="wrap row">
<div id="Proposals" class="Proposals-list small-12 medium-9 column js-order-<%= @order.dasherize %>">
<div class="filters">
<div class="small-12 medium-7 column">
<% if @search_terms %>
<h2 class="margin-top">
<%= page_entries_info @proposals %>
<%= t("proposals.index.search_results", count: @proposals.size, search_term: @search_terms) %>
</h2>
<% elsif @tag_filter %>
<h2 class="margin-top">
<%= page_entries_info @proposals %>
<%= t("proposals.index.filter_topic", count: @proposals.size, topic: @tag_filter) %>
</h2>
<% end %>
</div>
<% if @tag_filter || @search_terms %>
<div class="small-12 medium-5 margin-top inline-block proposals-order">
<h6 class="inline-block">
<%= t("proposals.index.select_order") %>
</h6>
<% else %>
<div class="small-12 column margin-top inline-block">
<h2 class="inline-block">
<%= t("proposals.index.select_order_long") %>
</h2>
<% end %>
<form class="inline-block">
<select class="js-location-changer" name="order-selector">
<% @valid_orders.each do |order| %>
<option <%= 'selected' if order == @order %>
value='<%= current_path_with_query_params(order: order, page: 1) %>'>
<%= t("proposals.index.orders.#{order}") %>
</option>
<% end %>
</select>
</form>
</div>
</div>
<div class="show-for-small-only">
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %>
</div>
<%= render @proposals %>
<%= paginate @proposals %>
</div>
<div class="small-12 medium-3 column">
<aside class="sidebar" role="complementary">
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %>
<%= render "shared/tag_cloud" %>
</aside>
</div>
</div>
</section>

View File

@@ -4,7 +4,7 @@
<% if taggable.tags.any? %> <% if taggable.tags.any? %>
<span class='tags'> <span class='tags'>
<% taggable.tag_list_with_limit(limit).each do |tag| %> <% taggable.tag_list_with_limit(limit).each do |tag| %>
<%= link_to sanitize(tag.name), send("#{taggable.class.to_s.downcase}_path", tag: tag.name) %> <%= link_to sanitize(tag.name), send("#{taggable.class.to_s.downcase.pluralize}_path", tag: tag.name) %>
<% end %> <% end %>
<% if taggable.tags_count_out_of_limit(limit) > 0 %> <% if taggable.tags_count_out_of_limit(limit) > 0 %>