Merge pull request #1046 from consul/valuator-extra-links

Valuator extra links
This commit is contained in:
Juanjo Bazán
2016-04-07 11:07:21 +02:00
4 changed files with 47 additions and 12 deletions

View File

@@ -355,3 +355,16 @@ body.admin {
width: 100%; width: 100%;
} }
} }
.admin-content .select-geozone {
a {
display: block;
&.active {
color: $brand;
font-weight: bold;
text-decoration: underline;
}
}
}

View File

@@ -9,6 +9,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController
load_and_authorize_resource load_and_authorize_resource
def index def index
@geozone_filters = geozone_filters
if current_user.valuator? if current_user.valuator?
@spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page]) @spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page])
else else
@@ -31,6 +32,26 @@ class Valuation::SpendingProposalsController < Valuation::BaseController
private 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 def valuation_params
params[:spending_proposal][:feasible] = nil if params[:spending_proposal][:feasible] == 'nil' params[:spending_proposal][:feasible] = nil if params[:spending_proposal][:feasible] == 'nil'

View File

@@ -1,13 +1,14 @@
<h2><%= t("valuation.spending_proposals.index.title") %></h2> <h2><%= t("valuation.spending_proposals.index.title") %></h2>
<div> <div class="row collapse">
<%= form_tag valuation_spending_proposals_path, method: :get, enforce_utf8: false do %> <% @geozone_filters.each_slice(8) do |slice| %>
<div class="small-12 medium-4 column float-right"> <div class="small-12 medium-4 column select-geozone">
<%= select_tag :geozone_id, <% slice.each do |filter| %>
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]), <%= link_to valuation_spending_proposals_path(geozone_id: filter[:id]),
{ prompt: t("valuation.spending_proposals.index.geozone_filter_all"), class: "#{'active' if params[:geozone_id].to_s == filter[:id].to_s}" do %>
label: false, <%= filter[:name] %>&nbsp;(<%= filter[:pending_count] %>)
class: "js-submit-on-change" } %> <% end %>
<% end %>
</div> </div>
<% end %> <% end %>
</div> </div>
@@ -38,4 +39,4 @@
<% end %> <% end %>
</table> </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("Realocate visitors")
expect(page).to have_link("Destroy the city") 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 have_link("Realocate visitors")
expect(page).to_not have_link("Destroy the city") 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 have_link("Destroy the city")
expect(page).to_not have_link("Realocate visitors") 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("Realocate visitors")
expect(page).to have_link("Destroy the city") expect(page).to have_link("Destroy the city")
end end