displays the top 3 proposals for every category
This commit is contained in:
@@ -8,7 +8,7 @@ class ProposalsController < ApplicationController
|
||||
before_action :set_search_order, only: :index
|
||||
before_action :load_categories, only: [:index, :new, :edit, :map]
|
||||
before_action :load_geozones, only: [:edit, :map]
|
||||
before_action :authenticate_user!, except: [:index, :show, :map]
|
||||
before_action :authenticate_user!, except: [:index, :show, :map, :summary]
|
||||
|
||||
has_orders %w{hot_score confidence_score created_at relevance}, only: :index
|
||||
has_orders %w{most_voted newest oldest}, only: :show
|
||||
@@ -35,6 +35,10 @@ class ProposalsController < ApplicationController
|
||||
set_featured_proposal_votes(@proposal)
|
||||
end
|
||||
|
||||
def summary
|
||||
@proposals = Proposal.grouped_by_categories(Proposal.category_names)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def proposal_params
|
||||
|
||||
@@ -4,7 +4,7 @@ module Abilities
|
||||
|
||||
def initialize(user)
|
||||
can [:read, :map], Debate
|
||||
can [:read, :map], Proposal
|
||||
can [:read, :map, :summary], Proposal
|
||||
can :read, Comment
|
||||
can :read, SpendingProposal
|
||||
can :read, Legislation
|
||||
|
||||
@@ -41,7 +41,11 @@ class Proposal < ActiveRecord::Base
|
||||
scope :sort_by_random, -> { reorder("RANDOM()") }
|
||||
scope :sort_by_relevance , -> { all }
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
|
||||
scope :grouped_by_categories, -> (categories) { where("lower(tags.name) IN (?)", categories).
|
||||
joins(:tags).select('proposals.*, tags.name').
|
||||
group_by(&:name) }
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
@@ -60,13 +64,21 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.search_by_code(terms)
|
||||
if code_match = /\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms)
|
||||
results = where(id: code_match[1])
|
||||
if code = self.match_code(terms)
|
||||
results = where(id: code[1])
|
||||
end
|
||||
|
||||
return results if (results.present? && results.first.code == terms)
|
||||
end
|
||||
|
||||
def self.match_code(terms)
|
||||
/\A#{Setting["proposal_code_prefix"]}-\d\d\d\d-\d\d-(\d*)\z/.match(terms)
|
||||
end
|
||||
|
||||
def self.category_names
|
||||
ActsAsTaggableOn::Tag.where("kind = 'category'").map {|tag| tag.name.downcase }
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
14
app/views/proposals/summary.html.erb
Normal file
14
app/views/proposals/summary.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<section role="main">
|
||||
<div class="wrap row">
|
||||
<div id="proposals" class="proposals-list small-12 medium-9 column">
|
||||
<% @proposals.each do |group_name, proposals| %>
|
||||
<div><strong><%= group_name %></strong></div><br/>
|
||||
|
||||
<% proposals[0..2].each do |proposal| %>
|
||||
<div><strong><%= proposal.title %></strong></div>
|
||||
<div><%= proposal.description %></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -43,9 +43,9 @@ Rails.application.routes.draw do
|
||||
get :suggest
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
get 'debate_links/new' => 'debate_links#new'
|
||||
post 'debate_links' => 'debate_links#create'
|
||||
post 'debate_links' => 'debate_links#create'
|
||||
|
||||
resources :proposals do
|
||||
member do
|
||||
@@ -57,6 +57,7 @@ Rails.application.routes.draw do
|
||||
collection do
|
||||
get :map
|
||||
get :suggest
|
||||
get :summary
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user