replaces the select in the valuators index with a list of links + pending count

This commit is contained in:
kikito
2016-04-06 18:08:00 +02:00
parent 25c9afb14c
commit d03864adb2
3 changed files with 31 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController
load_and_authorize_resource
def index
@geozone_filters = geozone_filters
if current_user.valuator?
@spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page])
else
@@ -31,6 +32,26 @@ class Valuation::SpendingProposalsController < Valuation::BaseController
private
def geozone_filters
spending_proposals = SpendingProposal.by_valuator(current_user.valuator.try(:id)).valuation_open.all.to_a
[ { name: t('valuation.spending_proposals.index.geozone_filter_all'),
id: nil,
pending_count: spending_proposals.size
},
{ name: t('geozones.none'),
id: 'all',
pending_count: spending_proposals.count{|x| x.geozone_id.nil?}
}
] + Geozone.all.order(name: :asc).collect do |g|
{ name: g.name,
id: g.id,
pending_count: spending_proposals.count{|x| x.geozone_id == g.id}
}
end
end
def valuation_params
params[:spending_proposal][:feasible] = nil if params[:spending_proposal][:feasible] == 'nil'

View File

@@ -1,14 +1,12 @@
<h2><%= t("valuation.spending_proposals.index.title") %></h2>
<div>
<%= form_tag valuation_spending_proposals_path, method: :get, enforce_utf8: false do %>
<div class="small-12 medium-4 column float-right">
<%= select_tag :geozone_id,
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]),
{ prompt: t("valuation.spending_proposals.index.geozone_filter_all"),
label: false,
class: "js-submit-on-change" } %>
</div>
<% @geozone_filters.each do |filter| %>
<span class="<%= 'active' if params[:geozone_id].to_s == filter[:id].to_s %>" >
<%= link_to valuation_spending_proposals_path(geozone_id: filter[:id]) do %>
<%= filter[:name] %>(<%= filter[:pending_count] %>)
<% end %>
</span>
<% end %>
</div>
@@ -38,4 +36,4 @@
<% end %>
</table>
<%= paginate @spending_proposals %>
<%= paginate @spending_proposals %>

View File

@@ -76,17 +76,17 @@ feature 'Valuation spending proposals' do
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
select "District 9", from: "geozone_id"
click_link "District 9", exact: false
expect(page).to have_link("Realocate visitors")
expect(page).to_not have_link("Destroy the city")
select "All city", from: "geozone_id"
click_link "All city", exact: false
expect(page).to have_link("Destroy the city")
expect(page).to_not have_link("Realocate visitors")
select "All zones", from: "geozone_id"
click_link "All zones", exact: false
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
end