adds print page to management/spending_proposals
includes search and filtering by geozone
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class Management::SpendingProposalsController < Management::BaseController
|
class Management::SpendingProposalsController < Management::BaseController
|
||||||
|
|
||||||
before_action :check_verified_user
|
before_action :check_verified_user, except: :print
|
||||||
before_action :set_spending_proposal, only: [:vote, :show]
|
before_action :set_spending_proposal, only: [:vote, :show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@@ -32,6 +32,12 @@ class Management::SpendingProposalsController < Management::BaseController
|
|||||||
set_spending_proposal_votes(@spending_proposal)
|
set_spending_proposal_votes(@spending_proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def print
|
||||||
|
params[:geozone] ||= 'all'
|
||||||
|
@spending_proposals = apply_filters_and_search(SpendingProposal).order(cached_votes_up: :desc).for_render.limit(15)
|
||||||
|
set_spending_proposal_votes(@spending_proposals)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_spending_proposal
|
def set_spending_proposal
|
||||||
@@ -57,6 +63,14 @@ class Management::SpendingProposalsController < Management::BaseController
|
|||||||
@spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {}
|
@spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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)
|
def apply_filters_and_search(target)
|
||||||
target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible
|
target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible
|
||||||
if params[:geozone].present?
|
if params[:geozone].present?
|
||||||
|
|||||||
@@ -47,5 +47,12 @@
|
|||||||
<%= t("management.menu.print_proposals") %>
|
<%= t("management.menu.print_proposals") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "spending_proposals" and action_name == "print" %>>
|
||||||
|
<%= link_to print_management_spending_proposals_path do %>
|
||||||
|
<span class="icon-print"></span>
|
||||||
|
<%= t("management.menu.print_spending_proposals") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
<%= render @proposals %>
|
<%= render @proposals %>
|
||||||
|
|
||||||
<div class="for-print-only">
|
<div class="for-print-only">
|
||||||
<p><strong><%= t("management.print.info") %></strong><br>
|
<p><strong><%= t("management.print.proposals_info") %></strong><br>
|
||||||
<%= t("management.print.note") %></p>
|
<%= t("management.print.proposals_note") %></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="small-12 search-results">
|
<div class="small-12 search-results">
|
||||||
<%= content_tag(:h2, t("spending_proposals.index.unfeasible")) if params[:unfeasible].present? %>
|
<%= content_tag(:h2, t("management.spending_proposals.filters.unfeasible")) if params[:unfeasible].present? %>
|
||||||
<%= content_tag(:h2, t("spending_proposals.index.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %>
|
<%= content_tag(:h2, t("management.spending_proposals.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %>
|
||||||
<% if params[:search].present? %>
|
<% if params[:search].present? %>
|
||||||
<h2>
|
<h2>
|
||||||
<%= page_entries_info @spending_proposals %>
|
<%= page_entries_info @spending_proposals %>
|
||||||
<%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: params[:search]) %>
|
<%= t("management.spending_proposals.search_results", count: @spending_proposals.size, search_term: params[:search]) %>
|
||||||
</h2>
|
</h2>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
34
app/views/management/spending_proposals/print.html.erb
Normal file
34
app/views/management/spending_proposals/print.html.erb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<main>
|
||||||
|
<div class="row">
|
||||||
|
<div id="investment-projects" class="investment-projects-list small-12 column">
|
||||||
|
|
||||||
|
<div class="not-print">
|
||||||
|
<%= form_tag print_management_spending_proposals_path, method: :get, enforce_utf8: false do %>
|
||||||
|
<div class="small-12 medium-4 column float-left">
|
||||||
|
<%= select_tag :geozone,
|
||||||
|
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]),
|
||||||
|
{ label: false,
|
||||||
|
class: "js-submit-on-change" } %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<a id="print_link" href="javascript:window.print();" class="button warning float-right">
|
||||||
|
<%= t('management.spending_proposals.print.print_button') %>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 search-results">
|
||||||
|
<%= content_tag(:h2, t("management.spending_proposals.filters.unfeasible"), class: "inline-block") if params[:unfeasible].present? %>
|
||||||
|
<%= content_tag(:h2, t("management.spending_proposals.filters.by_geozone", geozone: @geozone_name), class: "inline-block") if @geozone_name.present? %>
|
||||||
|
<%= content_tag(:h2, t("management.spending_proposals.search_results", count: @spending_proposals.size, search_term: params[:search]), class: "inline-block") if params[:search].present? %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render @spending_proposals %>
|
||||||
|
|
||||||
|
<div class="for-print-only">
|
||||||
|
<p><strong><%= t("management.print.spending_proposals_info") %></strong><br>
|
||||||
|
<%= t("management.print.spending_proposals_note") %></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
@@ -41,6 +41,7 @@ en:
|
|||||||
print_proposals: Print proposals
|
print_proposals: Print proposals
|
||||||
support_proposals: Support proposals
|
support_proposals: Support proposals
|
||||||
create_spending_proposal: Create spending proposal
|
create_spending_proposal: Create spending proposal
|
||||||
|
print_spending_proposals: Print spending proposals
|
||||||
support_spending_proposals: Support spending proposals
|
support_spending_proposals: Support spending proposals
|
||||||
title: Management
|
title: Management
|
||||||
users: Users
|
users: Users
|
||||||
@@ -50,9 +51,11 @@ en:
|
|||||||
support_proposals: Support proposals
|
support_proposals: Support proposals
|
||||||
vote_proposals: Vote proposals
|
vote_proposals: Vote proposals
|
||||||
print:
|
print:
|
||||||
info: Create yor proposal on http://decide.madrid.es
|
proposals_info: Create yor proposal on http://decide.madrid.es
|
||||||
note: The proposals more supported will be voted. If are accepted by a majority, the city Council shall be carried out.
|
proposals_note: The proposals more supported will be voted. If are accepted by a majority, the city Council shall be carried out.
|
||||||
proposals_title: 'Proposals:'
|
proposals_title: 'Proposals:'
|
||||||
|
spending_proposals_info: Participate at http://decide.madrid.es
|
||||||
|
spending_proposals_note: Participatory budget will be assigned to the most votes spending proposals.
|
||||||
print_info: Print this info
|
print_info: Print this info
|
||||||
proposals:
|
proposals:
|
||||||
alert:
|
alert:
|
||||||
@@ -64,6 +67,14 @@ en:
|
|||||||
alert:
|
alert:
|
||||||
unverified_user: User is not verified
|
unverified_user: User is not verified
|
||||||
create: Create spending proposal
|
create: Create spending proposal
|
||||||
|
filters:
|
||||||
|
unfeasible: Unfeasible investment projects
|
||||||
|
by_geozone: "Investment projects with scope: %{geozone}"
|
||||||
|
print:
|
||||||
|
print_button: Print
|
||||||
|
search_results:
|
||||||
|
one: " containing the term '%{search_term}'"
|
||||||
|
other: " containing the term '%{search_term}'"
|
||||||
sessions:
|
sessions:
|
||||||
signed_out: Signed out successfully.
|
signed_out: Signed out successfully.
|
||||||
signed_out_managed_user: User session signed out successfully.
|
signed_out_managed_user: User session signed out successfully.
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ es:
|
|||||||
print_proposals: Imprimir propuestas
|
print_proposals: Imprimir propuestas
|
||||||
support_proposals: Apoyar propuestas
|
support_proposals: Apoyar propuestas
|
||||||
create_spending_proposal: Crear propuesta de inversión
|
create_spending_proposal: Crear propuesta de inversión
|
||||||
support_spending_proposals: Apoyar propuestas de inversión
|
print_spending_proposals: Imprimir propts. de inversión
|
||||||
|
support_spending_proposals: Apoyar propts. de inversión
|
||||||
title: Gestión
|
title: Gestión
|
||||||
users: Usuarios
|
users: Usuarios
|
||||||
permissions:
|
permissions:
|
||||||
@@ -50,9 +51,11 @@ es:
|
|||||||
support_proposals: Apoyar propuestas
|
support_proposals: Apoyar propuestas
|
||||||
vote_proposals: Participar en las votaciones finales
|
vote_proposals: Participar en las votaciones finales
|
||||||
print:
|
print:
|
||||||
info: Haz tu propuesta en http://decide.madrid.es
|
proposals_info: Haz tu propuesta en http://decide.madrid.es
|
||||||
note: Las propuestas más apoyadas serán llevadas a votación. Y si las acepta una mayoría, el Ayuntamiento las llevará a cabo.
|
proposals_note: Las propuestas más apoyadas serán llevadas a votación. Y si las acepta una mayoría, el Ayuntamiento las llevará a cabo.
|
||||||
proposals_title: 'Propuestas:'
|
proposals_title: 'Propuestas:'
|
||||||
|
spending_proposals_info: Participa en http://decide.madrid.es
|
||||||
|
spending_proposals_note: Los presupuestos participativos se invertirán en las propuestas de inversión más apoyadas.
|
||||||
print_info: Imprimir esta información
|
print_info: Imprimir esta información
|
||||||
proposals:
|
proposals:
|
||||||
alert:
|
alert:
|
||||||
@@ -64,6 +67,14 @@ es:
|
|||||||
alert:
|
alert:
|
||||||
unverified_user: Este usuario no está verificado
|
unverified_user: Este usuario no está verificado
|
||||||
create: Crear propuesta de inversión
|
create: Crear propuesta de inversión
|
||||||
|
filters:
|
||||||
|
unfeasible: Propuestas de inversión no viables
|
||||||
|
by_geozone: "Propuestas de inversión con ámbito: %{geozone}"
|
||||||
|
print:
|
||||||
|
print_button: Imprimir
|
||||||
|
search_results:
|
||||||
|
one: " que contiene '%{search_term}'"
|
||||||
|
other: " que contienen '%{search_term}'"
|
||||||
sessions:
|
sessions:
|
||||||
signed_out: Has cerrado la sesión correctamente.
|
signed_out: Has cerrado la sesión correctamente.
|
||||||
signed_out_managed_user: Se ha cerrado correctamente la sesión del usuario.
|
signed_out_managed_user: Se ha cerrado correctamente la sesión del usuario.
|
||||||
|
|||||||
@@ -175,4 +175,50 @@ feature 'Spending Proposals' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "Printing" do
|
||||||
|
|
||||||
|
scenario 'Printing spending proposals' do
|
||||||
|
16.times { create(:spending_proposal, geozone_id: nil) }
|
||||||
|
|
||||||
|
click_link "Print spending proposals"
|
||||||
|
|
||||||
|
expect(page).to have_css('.investment-project', count: 15)
|
||||||
|
expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Filtering spending proposals by geozone to be printed", :js do
|
||||||
|
district_9 = create(:geozone, name: "District Nine")
|
||||||
|
create(:spending_proposal, title: 'Change district 9', geozone: district_9, cached_votes_up: 10)
|
||||||
|
create(:spending_proposal, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100)
|
||||||
|
create(:spending_proposal, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1)
|
||||||
|
create(:spending_proposal, title: 'Add new districts to the city', geozone_id: nil)
|
||||||
|
|
||||||
|
user = create(:user, :level_two)
|
||||||
|
login_managed_user(user)
|
||||||
|
|
||||||
|
click_link "Print spending proposals"
|
||||||
|
|
||||||
|
expect(page).to have_content "Investment projects with scope: All city"
|
||||||
|
|
||||||
|
within '#investment-projects' do
|
||||||
|
expect(page).to have_content('Add new districts to the city')
|
||||||
|
expect(page).to_not have_content('Change district 9')
|
||||||
|
expect(page).to_not have_content('Destroy district 9')
|
||||||
|
expect(page).to_not have_content('Nuke district 9')
|
||||||
|
end
|
||||||
|
|
||||||
|
select 'District Nine', from: 'geozone'
|
||||||
|
|
||||||
|
expect(page).to have_content "Investment projects with scope: District Nine"
|
||||||
|
expect(current_url).to include("geozone=#{district_9.id}")
|
||||||
|
|
||||||
|
within '#investment-projects' do
|
||||||
|
expect(page).to_not have_content('Add new districts to the city')
|
||||||
|
expect('Destroy district 9').to appear_before('Change district 9')
|
||||||
|
expect('Change district 9').to appear_before('Nuke district 9')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user