Skip to content

Commit

Permalink
Improve Budget's homepage
Browse files Browse the repository at this point in the history
* Add budget's phases number status
* Add budget's headings and groups list
* Placeholders for future improvements
  • Loading branch information
bertocq committed Jan 17, 2018
1 parent 4d97d34 commit a6b06ca
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 26 deletions.
1 change: 1 addition & 0 deletions app/controllers/budgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def show

def index
@budgets = @budgets.order(:created_at)
@budget = current_budget
end

end
1 change: 1 addition & 0 deletions app/models/budget/phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Phase < ActiveRecord::Base
after_save :adjust_date_ranges

scope :enabled, -> { where(enabled: true) }
scope :published, -> { enabled.where.not(kind: 'drafting') }
scope :drafting, -> { find_by_kind('drafting') }
scope :accepting, -> { find_by_kind('accepting')}
scope :reviewing, -> { find_by_kind('reviewing')}
Expand Down
149 changes: 126 additions & 23 deletions app/views/budgets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,135 @@
<%= render "shared/canonical", href: budgets_url %>
<% end %>

<%= render "shared/section_header", i18n_namespace: "budgets.index.section_header", image: "budgets" %>
<div id="budget_heading" class="expanded budget no-margin-top">
<div class="row" data-equalizer data-equalizer-on="medium">
<div class="small-12 medium-9 column padding" data-equalizer-watch>

<div class="row margin-top">
<div class="small-12 medium-9 column">
<table>
<thead>
<tr>
<th scope="col"><%= Budget.human_attribute_name(:name) %></th>
<th scope="col"><%= Budget.human_attribute_name(:phase) %></th>
</tr>
</thead>
<tbody>
<% @budgets.each do |budget| %>
<% if budget_published?(budget) %>
<tr>
<td>
<%= link_to budget.name, budget %>
</td>
<td>
<%= budget.translated_phase %>
</td>
</tr>
<h1><%= @budget.name %></h1>

<%= safe_html_with_links @budget.description %>
<%= link_to t("budgets.index.section_header.help"), "#section_help" %>
</div>
<div class="small-12 medium-3 column info padding" data-equalizer-watch>
<p>
<% published_phases = @budget.phases.published %>
<% current_phase_number = published_phases.index(@budget.current_phase) + 1 || 0 %>
<% phases_progress_numbers = "(#{current_phase_number}/#{published_phases.count})" %>
<strong><%= t('budgets.show.phase') %> <%= phases_progress_numbers %></strong>
</p>
<h2><%= t("budgets.phase.#{@budget.phase}") %></h2>

<%= link_to t("budgets.index.section_header.all_phases"), "#all_phases" %>
<% if @budget.accepting? %>
<% if current_user %>
<% if current_user.level_two_or_three_verified? %>
<%= link_to t("budgets.investments.index.sidebar.create"),
new_budget_investment_path(@budget),
class: "button margin-top expanded" %>
<% else %>
<div class="callout warning margin-top">
<%= t("budgets.investments.index.sidebar.verified_only",
verify: link_to(t("budgets.investments.index.sidebar.verify_account"),
verification_path)).html_safe %>
</div>
<% end %>
<% else %>
<div class="callout primary margin-top">
<%= t("budgets.investments.index.sidebar.not_logged_in",
sign_in: link_to(t("budgets.investments.index.sidebar.sign_in"),
new_user_session_path),
sign_up: link_to(t("budgets.investments.index.sidebar.sign_up"),
new_user_registration_path)).html_safe %>
</div>
<% end %>
<% end %>
</tbody>
</table>
<% if @budget.finished? || (@budget.balloting? && can?(:read_results, @budget)) %>
<%= link_to t("budgets.show.see_results"),
budget_results_path(@budget, heading_id: @budget.headings.first),
class: "button margin-top expanded" %>
<% end %>
</div>
</div>
</div>

<div id="budget_info" class="row margin-top">
<div class="small-12 medium-9 column">

<div id="groups_and_headings">
<% @budget.groups.each do |group| %>
<h2><%= group.name %></h2>
<div class="row">
<% group.headings.each do |heading| %>
<div class="small-12 medium-6 column">
<%= link_to heading.name,
budget_investments_path(@budget.id, heading_id: heading.id) %>
<%= @budget.formatted_heading_price(heading) %>
</div>
<% end %>
</div>
<% end %>
</div>

<div id="map">
<h3><%= t("budgets.index.map") %></h3>
</div>

<div>
<%= link_to t("budgets.index.investment_proyects"),
budget_investments_path(@budget.id) %><br>
<%= link_to t("budgets.index.unfeasible_investment_proyects"),
budget_investments_path(budget_id: @budget.id, filter: 'unfeasible') %><br>
<%= link_to t("budgets.index.not_selected_investment_proyects"),
budget_investments_path(budget_id: @budget.id, filter: 'unselected') %>
</div>

<div id="all_phases">
<h2><%= t("budgets.index.all_phases") %></h2>
<% @budget.phases.published.pluck(:kind) do |phase_kind| %>
<div class="row">
<div class="small-12 column <%= @budget.phase == phase_kind ? 'active' : '' %>">
<h4><%= t("budgets.phase.#{phase_kind}") %></h4>
<%= @budget.description_for_phase(phase_kind) %>
</div>
</div>
<% end %>
</div>


<div class="tabs-content" data-tabs-content="other_budgets" role="tablist">
<div class="row margin-top">
<div class="small-12 column">
<ul class="tabs" data-tabs id="budget_tabs">
<li class="tabs-title is-active">
<%= link_to "#other_budgets" do %>
<h3>
<%= t("budgets.index.finished_budgets") %>
</h3>
<% end %>
</li>
</ul>
</div>
</div>

<div class="tabs-panel is-active" id="other_budgets">
<% @budgets.each do |b| %>
<% if budget_published?(b) %>
<div class="row">
<div class="small-9 column">
<%= b.name %>
<%= b.description %>
</div>
<div class="small-3 column">
<%= link_to t("budgets.index.see_results"), budget_results_path(b.id) %>
</div>
</div>
<% end %>
<% end %>
</div>
</div>

<div id="section_help" class="margin" data-magellan-target="section_help">
<p class="lead">
Expand Down
8 changes: 8 additions & 0 deletions config/locales/en/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ en:
icon_alt: Participatory budgets icon
title: Participatory budgets
help: Help about participatory budgets
all_phases: See all phases
all_phases: Budget investment's phases
map: Budget investments' proposals located geographically
investment_proyects: List of all investment projects
unfeasible_investment_proyects: List of all unfeasible investment projects
not_selected_investment_proyects: List of all investment projects not selected for balloting
finished_budgets: Finished participatory budgets
see_results: See results
section_footer:
title: Help about participatory budgets
description: With the participatory budgets the citizens decide to which projects presented by the neighbors is destined a part of the municipal budget.
Expand Down
8 changes: 8 additions & 0 deletions config/locales/es/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ es:
icon_alt: Icono de Presupuestos participativos
title: Presupuestos participativos
help: Ayuda sobre presupuestos participativos
all_phases: Ver todas las fases
all_phases: Fases de los presupuestos participativos
map: Propuestas de los presupuestos participativos localizables geográficamente
investment_proyects: Ver lista completa de proyectos de inversión
unfeasible_investment_proyects: Ver lista de proyectos de inversión inviables
not_selected_investment_proyects: Ver lista de proyectos de inversión no seleccionados para la votación final
finished_budgets: Presupuestos participativos terminados
see_results: Ver resultados
section_footer:
title: Ayuda sobre presupuestos participativos
description: Con los presupuestos participativos la ciudadanía decide a qué proyectos presentados por los vecinos y vecinas va destinada una parte del presupuesto municipal.
Expand Down
37 changes: 36 additions & 1 deletion spec/features/budgets/budgets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,42 @@

scenario 'Index' do
budgets = create_list(:budget, 3)
last_budget = budgets.last
group1 = create(:budget_group, budget: last_budget)
group2 = create(:budget_group, budget: last_budget)

heading1 = create(:budget_heading, group: group1)
heading2 = create(:budget_heading, group: group2)

visit budgets_path

within("#budget_heading") do
expect(page).to have_content(last_budget.name)
expect(page).to have_content(last_budget.description)
expect(page).to have_content("Actual phase (1/8)")
expect(page).to have_content("Accepting projects")
expect(page).to have_link 'Help about participatory budgets'
expect(page).to have_link 'See all phases'
end

last_budget.update_attributes(phase: 'publishing_prices')
visit budgets_path
budgets.each {|budget| expect(page).to have_link(budget.name)}

within("#budget_heading") do
expect(page).to have_content("Actual phase (5/8)")
end

within('#budget_info') do
expect(page).to have_content group1.name
expect(page).to have_content group2.name
expect(page).to have_content heading1.name
expect(page).to have_content last_budget.formatted_heading_price(heading1)
expect(page).to have_content heading2.name
expect(page).to have_content last_budget.formatted_heading_price(heading2)

expect(page).to have_content budgets.first.name
expect(page).to have_content budgets[2].name
end
end

context 'Show' do
Expand Down Expand Up @@ -70,6 +104,7 @@
background do
logout
budget.update(phase: 'drafting')
create(:budget)
end

context "Listed" do
Expand Down
3 changes: 1 addition & 2 deletions spec/features/budgets/investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,7 @@ def investments_order
visit root_path

first(:link, "Participatory budgeting").click
click_link budget.name
click_link "Health"
click_link "More hospitals"

within("#budget_investment_#{sp1.id}") do
expect(page).to have_content sp1.title
Expand Down

0 comments on commit a6b06ca

Please sign in to comment.