diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index cfec260e1..1ccd7c880 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -355,3 +355,16 @@ body.admin { width: 100%; } } + +.admin-content .select-geozone { + + a { + display: block; + + &.active { + color: $brand; + font-weight: bold; + text-decoration: underline; + } + } +} diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index c5f822b40..77a80b413 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -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' diff --git a/app/views/valuation/spending_proposals/index.html.erb b/app/views/valuation/spending_proposals/index.html.erb index e6c05d6c7..8536ec424 100644 --- a/app/views/valuation/spending_proposals/index.html.erb +++ b/app/views/valuation/spending_proposals/index.html.erb @@ -1,13 +1,14 @@

<%= t("valuation.spending_proposals.index.title") %>

-
- <%= form_tag valuation_spending_proposals_path, method: :get, enforce_utf8: false do %> -
- <%= 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" } %> +
+ <% @geozone_filters.each_slice(8) do |slice| %> +
+ <% slice.each do |filter| %> + <%= link_to valuation_spending_proposals_path(geozone_id: filter[:id]), + class: "#{'active' if params[:geozone_id].to_s == filter[:id].to_s}" do %> + <%= filter[:name] %> (<%= filter[:pending_count] %>) + <% end %> + <% end %>
<% end %>
@@ -38,4 +39,4 @@ <% end %> -<%= paginate @spending_proposals %> \ No newline at end of file +<%= paginate @spending_proposals %> diff --git a/spec/features/valuation/spending_proposals_spec.rb b/spec/features/valuation/spending_proposals_spec.rb index 8af416dc2..6cb1acf1a 100644 --- a/spec/features/valuation/spending_proposals_spec.rb +++ b/spec/features/valuation/spending_proposals_spec.rb @@ -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