diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 24bbbc41a..bc69d6200 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -11,13 +11,11 @@ class SpendingProposalsController < ApplicationController respond_to :html, :js def index - @spending_proposals = search_terms.present? ? SpendingProposal.search(search_terms) : SpendingProposal.all - @spending_proposals = @spending_proposals.page(params[:page]).for_render + @spending_proposals = apply_filters_and_search(SpendingProposal).page(params[:page]).for_render end def new @spending_proposal = SpendingProposal.new - end def show @@ -53,8 +51,22 @@ class SpendingProposalsController < ApplicationController params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key) end - def search_terms - @search_terms ||= params[:search].presence + def set_geozone_name + if params[:geozone] == 'all' + @geozone_name = t('geozones.none') + else + @geozone_name = Geozone.find(params[:geozone]).name + end + end + + def apply_filters_and_search(target) + target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible + if params[:geozone].present? + target = target.by_geozone(params[:geozone]) + set_geozone_name + end + target = target.search(params[:search]) if params[:search].present? + target end end diff --git a/app/views/spending_proposals/_sidebar.html.erb b/app/views/spending_proposals/_sidebar.html.erb index 7ab1ab525..8fc8693e8 100644 --- a/app/views/spending_proposals/_sidebar.html.erb +++ b/app/views/spending_proposals/_sidebar.html.erb @@ -2,10 +2,14 @@
- <% Geozone.names.each do |geozone| %> - <%= link_to geozone, spending_proposals_path(search: geozone) %> + <%= link_to t('geozones.all'), spending_proposals_path(geozone: nil) %> + <%= link_to t('geozones.none'), spending_proposals_path(geozone: 'all') %> + <% Geozone.all.each do |geozone| %> + <%= link_to geozone.name, spending_proposals_path(geozone: geozone.id) %> <% end %>
+ -
\ No newline at end of file +
+<%= link_to t('spending_proposals.index.sidebar.unfeasible'), spending_proposals_path(unfeasible: '1') %> \ No newline at end of file diff --git a/app/views/spending_proposals/index.html.erb b/app/views/spending_proposals/index.html.erb index 499948691..563b84e23 100644 --- a/app/views/spending_proposals/index.html.erb +++ b/app/views/spending_proposals/index.html.erb @@ -10,10 +10,12 @@
- <% if @search_terms %> + <%= content_tag(:h2, t("spending_proposals.index.unfeasible")) if params[:unfeasible].present? %> + <%= content_tag(:h2, t("spending_proposals.index.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> + <% if params[:search].present? %>

<%= page_entries_info @spending_proposals %> - <%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: @search_terms) %> + <%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: params[:search]) %>

<% end %>
@@ -26,7 +28,7 @@
-
diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 50dd53006..79893cecd 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -38,8 +38,8 @@ es: one: "Propuesta ciudadana" other: "Propuestas ciudadanas" spending_proposal: - one: "Propuesta de gasto" - other: "Propuestas de gasto" + one: "Propuesta de inversión" + other: "Propuestas de inversión" attributes: comment: body: "Comentario" diff --git a/config/locales/en.yml b/config/locales/en.yml index 9b438215a..206f2fb76 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -154,6 +154,7 @@ en: verification/sms: phone geozones: none: All city + all: All scopes layouts: application: chrome: Google Chrome @@ -413,6 +414,8 @@ en: title: Spending proposal title index: title: Participatory budgeting + unfeasible: Unfeasible investment projects + by_geozone: "Investment projects with scope: %{geozone}" search_form: button: Search placeholder: Investment projects... @@ -423,6 +426,7 @@ en: sidebar: geozones: Scope of operation feasibility: Feasibility + unfeasible: Unfeasible start_spending_proposal: Create an investment project new: more_info: How do participatory budgeting works? diff --git a/config/locales/es.yml b/config/locales/es.yml index cf7141933..9e02d6962 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -154,6 +154,7 @@ es: verification/sms: el teléfono geozones: none: Toda la ciudad + all: Todos los ámbitos layouts: application: chrome: Google Chrome @@ -413,6 +414,8 @@ es: title: Título de la propuesta de gasto index: title: Presupuestos participativos + unfeasible: Propuestas de inversión no viables + by_geozone: "Propuestas de inversión con ámbito: %{geozone}" search_form: button: Buscar placeholder: Propuestas de inversión... @@ -423,6 +426,7 @@ es: sidebar: geozones: Ámbitos de actuación feasibility: Viabilidad + unfeasible: No viables start_spending_proposal: Crea una propuesta de inversión new: more_info: "¿Cómo funcionan los presupuestos participativos?" diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index b31eacec8..62dfee01e 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -5,7 +5,8 @@ feature 'Spending proposals' do let(:author) { create(:user, :level_two, username: 'Isabel') } scenario 'Index' do - spending_proposals = [create(:spending_proposal), create(:spending_proposal), create(:spending_proposal)] + spending_proposals = [create(:spending_proposal), create(:spending_proposal), create(:spending_proposal, feasible: true)] + unfeasible_spending_proposal = create(:spending_proposal, feasible: false) visit spending_proposals_path @@ -14,6 +15,7 @@ feature 'Spending proposals' do within('#investment-projects') do expect(page).to have_content spending_proposal.title expect(page).to have_css("a[href='#{spending_proposal_path(spending_proposal)}']", text: spending_proposal.title) + expect(page).to_not have_content(unfeasible_spending_proposal.title) end end end @@ -41,6 +43,52 @@ feature 'Spending proposals' do end end + context("Filters") do + scenario 'by geozone' do + geozone1 = create(:geozone) + spending_proposal1 = create(:spending_proposal, geozone: geozone1) + spending_proposal2 = create(:spending_proposal, geozone: create(:geozone)) + spending_proposal3 = create(:spending_proposal, geozone: geozone1) + spending_proposal4 = create(:spending_proposal) + + visit spending_proposals_path + + within(".geozone") do + click_link geozone1.name + end + + within("#investment-projects") do + expect(page).to have_css('.investment-project', count: 2) + + expect(page).to have_content(spending_proposal1.title) + expect(page).to have_content(spending_proposal3.title) + expect(page).to_not have_content(spending_proposal2.title) + expect(page).to_not have_content(spending_proposal4.title) + end + end + + scenario 'by unfeasibility' do + geozone1 = create(:geozone) + spending_proposal1 = create(:spending_proposal, feasible: false) + spending_proposal2 = create(:spending_proposal, feasible: true) + spending_proposal3 = create(:spending_proposal) + + visit spending_proposals_path + + within("#sidebar") do + click_link "Unfeasible" + end + + within("#investment-projects") do + expect(page).to have_css('.investment-project', count: 1) + + expect(page).to have_content(spending_proposal1.title) + expect(page).to_not have_content(spending_proposal2.title) + expect(page).to_not have_content(spending_proposal3.title) + end + end + end + scenario 'Create' do login_as(author)