From 4ddb778bed056127fdc3c7b1d5246711e616d533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 14:12:19 +0200 Subject: [PATCH 1/4] refactors scopes and methods used only in admin --- app/controllers/admin/spending_proposals_controller.rb | 2 +- app/controllers/valuation/spending_proposals_controller.rb | 2 +- app/models/spending_proposal.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index 25707e66e..61f9aa78d 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -7,7 +7,7 @@ class Admin::SpendingProposalsController < Admin::BaseController load_and_authorize_resource def index - @spending_proposals = SpendingProposal.search(params, @current_filter).order(created_at: :desc).page(params[:page]) + @spending_proposals = SpendingProposal.scoped_filter(params, @current_filter).order(created_at: :desc).page(params[:page]) end def show diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index 364671d09..c5f822b40 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -10,7 +10,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def index if current_user.valuator? - @spending_proposals = SpendingProposal.search(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 @spending_proposals = SpendingProposal.none.page(params[:page]) end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 4b3c7d4f7..9e4c4492e 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -32,7 +32,7 @@ class SpendingProposal < ActiveRecord::Base scope :by_tag, -> (tag_name) { tagged_with(tag_name) } scope :by_valuator, -> (valuator) { where("valuation_assignments.valuator_id = ?", valuator.presence).joins(:valuation_assignments) } - scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) } + scope :for_render, -> { includes(:geozone) } def description super.try :html_safe @@ -42,14 +42,14 @@ class SpendingProposal < ActiveRecord::Base params.select{|x,_| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s } end - def self.search(params, current_filter) + def self.scoped_filter(params, current_filter) results = self results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present? results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present? results = results.by_tag(params[:tag_name]) if params[:tag_name].present? results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present? results = results.send(current_filter) if current_filter.present? - results.for_render + results.includes(:geozone, administrator: :user, valuators: :user) end def self.by_geozone(geozone) From 6008244ecfb753ffbf9f16c4b968e83927e0d978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 16:46:24 +0200 Subject: [PATCH 2/4] adds basic spending_proposals index --- .../spending_proposals_controller.rb | 2 + .../spending_proposals/_sidebar.html.erb | 11 ++++ .../_spending_proposal.html.erb | 53 +++++++++++++++++++ app/views/spending_proposals/index.html.erb | 41 ++++++++++---- config/i18n-tasks.yml | 1 + config/locales/en.yml | 14 +++-- config/locales/es.yml | 14 +++-- spec/features/spending_proposals_spec.rb | 16 +++--- 8 files changed, 125 insertions(+), 27 deletions(-) create mode 100644 app/views/spending_proposals/_sidebar.html.erb create mode 100644 app/views/spending_proposals/_spending_proposal.html.erb diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 1c2c83047..28c1862e6 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -11,6 +11,8 @@ class SpendingProposalsController < ApplicationController feature_flag :spending_proposals def index + @spending_proposals = @search_terms.present? ? SpendingProposal.search(@search_terms) : SpendingProposal.all + @spending_proposals = @spending_proposals.page(params[:page]).for_render end def new diff --git a/app/views/spending_proposals/_sidebar.html.erb b/app/views/spending_proposals/_sidebar.html.erb new file mode 100644 index 000000000..7ab1ab525 --- /dev/null +++ b/app/views/spending_proposals/_sidebar.html.erb @@ -0,0 +1,11 @@ + + +
+
+ <% Geozone.names.each do |geozone| %> + <%= link_to geozone, spending_proposals_path(search: geozone) %> + <% end %> +
+ + +
\ No newline at end of file diff --git a/app/views/spending_proposals/_spending_proposal.html.erb b/app/views/spending_proposals/_spending_proposal.html.erb new file mode 100644 index 000000000..4437fba0b --- /dev/null +++ b/app/views/spending_proposals/_spending_proposal.html.erb @@ -0,0 +1,53 @@ +
+
+
+ +
+
+ + <% cache [locale_and_user_status(spending_proposal), 'index', spending_proposal, spending_proposal.author] do %> + <%= t("spending_proposals.spending_proposal.spending_proposal") %> + +

<%= link_to spending_proposal.title, spending_proposal_path(spending_proposal) %>

+

+ + <%= l spending_proposal.created_at.to_date %> + + <% if spending_proposal.author.hidden? || spending_proposal.author.erased? %> +  •  + + <%= t("spending_proposals.show.author_deleted") %> + + <% else %> +  •  + + <%= spending_proposal.author.name %> + + <% if spending_proposal.author.official? %> +  •  + + <%= spending_proposal.author.official_position %> + + <% end %> + <% end %> + + <% if spending_proposal.author.verified_organization? %> +  •  + + <%= t("shared.collective") %> + + <% end %> +

+
+

<%= link_to spending_proposal.description, spending_proposal_path(spending_proposal) %>

+
+
+ <% end %> +
+
+ + + +
+
+
diff --git a/app/views/spending_proposals/index.html.erb b/app/views/spending_proposals/index.html.erb index 00a1b6442..6f3529369 100644 --- a/app/views/spending_proposals/index.html.erb +++ b/app/views/spending_proposals/index.html.erb @@ -1,16 +1,35 @@ <% provide :title do %><%= t('spending_proposals.index.title') %><% end %> -
-
-
-

<%= t('spending_proposals.index.title') %>

+<% content_for :header_addon do %> + <%= render "shared/search_form", + search_path: spending_proposals_path(page: 1), + i18n_namespace: "spending_proposals.index.search_form" %> +<% end %> -

<%= t('spending_proposals.index.text_html') %>

+
+
+
- <% if can? :create, SpendingProposal %> - <%= link_to t('spending_proposals.index.create_link'), new_spending_proposal_path, class: 'button' %> - <% else %> -

<%= t('spending_proposals.index.verified_only', verify_account: link_to(t('spending_proposals.index.verify_account'), verification_path)).html_safe %>

- <% end %> +
+ <% if @search_terms %> +

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

+ <% end %> +
+ +
+ <%= link_to t("spending_proposals.index.start_proposal"), new_spending_proposal_path, class: 'button expanded' %> +
+ <%= render partial: 'spending_proposals/spending_proposal', collection: @spending_proposals %> + <%= paginate @spending_proposals %>
+ +
+ +
+
-
\ No newline at end of file + diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index c5e88d8dd..40086aab9 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -131,6 +131,7 @@ ignore_unused: - 'proposals.index.select_order' - 'proposals.index.orders.*' - 'proposals.index.search_form.*' + - 'spending_proposals.index.search_form.*' - 'notifications.index.comments_on*' - 'notifications.index.replies_to*' - 'helpers.page_entries_info.*' # kaminari diff --git a/config/locales/en.yml b/config/locales/en.yml index 1f752a9f2..158740c47 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -412,11 +412,13 @@ en: new: Create title: Spending proposal title index: - create_link: Create spending proposal - text_html: Here you can send spending proposals to be considered in the frame of the annual participatory budgeting. title: Participatory budgeting - verified_only: Only verified users can create spending proposals, %{verify_account}. - verify_account: verify your account + search_form: + button: Search + placeholder: Investment projects... + title: Search + sidebar: + geozones: Scope of operation new: back_link: Back more_info: How do participatory budgeting works? @@ -425,6 +427,10 @@ en: recommendation_two: Any proposal or comment suggesting illegal action will be deleted. recommendations_title: How to create a spending proposal start_new: Create spending proposal + show: + author_deleted: User deleted + spending_proposal: + spending_proposal: Investment project wrong_price_format: Only integer numbers stats: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 0e7a8b125..8c6ce610c 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -412,11 +412,13 @@ es: new: Crear title: Título de la propuesta de gasto index: - create_link: Enviar propuesta de gasto - text_html: Desde esta sección podrás sugerir propuestas de gasto que irán asociadas a las partidas de presupuestos ciudadanos.
El requisito principal es que sean propuestas presupuestables. title: Presupuestos participativos - verified_only: Sólo los usuarios verificados pueden crear propuestas de gasto, %{verify_account}. - verify_account: verifica tu cuenta + search_form: + button: Buscar + placeholder: Propuestas de inversión... + title: Buscar + sidebar: + geozones: Ámbitos de actuación new: back_link: Volver more_info: "¿Cómo funcionan los presupuestos participativos?" @@ -425,6 +427,10 @@ es: recommendation_two: Cualquier propuesta o comentario que implique acciones ilegales será eliminada. recommendations_title: Cómo crear una propuesta de gasto start_new: Crear una propuesta de gasto + show: + author_deleted: Usuario eliminado + spending_proposal: + spending_proposal: Propuesta de inversión wrong_price_format: Solo puede incluir caracteres numéricos stats: index: diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 0fd31f5f7..df9f041b7 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -5,17 +5,17 @@ feature 'Spending proposals' do let(:author) { create(:user, :level_two, username: 'Isabel') } scenario 'Index' do - visit spending_proposals_path - - expect(page).to_not have_link('Create spending proposal', href: new_spending_proposal_path) - expect(page).to have_link('verify your account') - - login_as(author) + spending_proposals = [create(:spending_proposal), create(:spending_proposal), create(:spending_proposal)] visit spending_proposals_path - expect(page).to have_link('Create spending proposal', href: new_spending_proposal_path) - expect(page).to_not have_link('verify your account') + expect(page).to have_selector('#investment-projects .investment-project', count: 3) + spending_proposals.each do |spending_proposal| + 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) + end + end end scenario 'Create' do From d50700738481ea01e5cff6977be6dca5b8faa1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 17:04:12 +0200 Subject: [PATCH 3/4] adds missing i18n keys --- app/views/spending_proposals/index.html.erb | 2 +- config/locales/en.yml | 5 +++++ config/locales/es.yml | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/spending_proposals/index.html.erb b/app/views/spending_proposals/index.html.erb index 6f3529369..499948691 100644 --- a/app/views/spending_proposals/index.html.erb +++ b/app/views/spending_proposals/index.html.erb @@ -19,7 +19,7 @@
- <%= link_to t("spending_proposals.index.start_proposal"), new_spending_proposal_path, class: 'button expanded' %> + <%= link_to t("spending_proposals.index.start_spending_proposal"), new_spending_proposal_path, class: 'button expanded' %>
<%= render partial: 'spending_proposals/spending_proposal', collection: @spending_proposals %> <%= paginate @spending_proposals %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 158740c47..b37c5568b 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -417,8 +417,13 @@ en: button: Search placeholder: Investment projects... title: Search + search_results: + one: " containing the term '%{search_term}'" + other: " containing the term '%{search_term}'" sidebar: geozones: Scope of operation + feasibility: Feasibility + start_spending_proposal: Create a spending proposal new: back_link: Back more_info: How do participatory budgeting works? diff --git a/config/locales/es.yml b/config/locales/es.yml index 8c6ce610c..fe9ec06cf 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -417,8 +417,13 @@ es: button: Buscar placeholder: Propuestas de inversión... title: Buscar + search_results: + one: " que contiene '%{search_term}'" + other: " que contienen '%{search_term}'" sidebar: geozones: Ámbitos de actuación + feasibility: Viabilidad + start_spending_proposal: Crea una propuesta de inversión new: back_link: Volver more_info: "¿Cómo funcionan los presupuestos participativos?" From bd1c0dfa1993bce9e13de7ee2944bab191bbe795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 17:10:14 +0200 Subject: [PATCH 4/4] changes i18n text --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index b37c5568b..4ae33fe46 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -423,7 +423,7 @@ en: sidebar: geozones: Scope of operation feasibility: Feasibility - start_spending_proposal: Create a spending proposal + start_spending_proposal: Create an investment project new: back_link: Back more_info: How do participatory budgeting works?