adds spending proposals index to valuation
filters included: valuation_open, valuating, valuation_finished search by geozone & by valuator
This commit is contained in:
committed by
Juanjo Bazán
parent
0160ed816c
commit
ac9eaec9d9
12
app/controllers/valuation/spending_proposals_controller.rb
Normal file
12
app/controllers/valuation/spending_proposals_controller.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Valuation::SpendingProposalsController < Valuation::BaseController
|
||||||
|
include FeatureFlags
|
||||||
|
feature_flag :spending_proposals
|
||||||
|
|
||||||
|
has_filters %w{valuation_open valuating valuation_finished}, only: :index
|
||||||
|
|
||||||
|
load_resource
|
||||||
|
|
||||||
|
def index
|
||||||
|
@spending_proposals = SpendingProposal.search(params, @current_filter).order(created_at: :desc).page(params[:page])
|
||||||
|
end
|
||||||
|
end
|
||||||
11
app/helpers/valuation_helper.rb
Normal file
11
app/helpers/valuation_helper.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
module ValuationHelper
|
||||||
|
|
||||||
|
def valuator_select_options(valuator=nil)
|
||||||
|
if valuator.present?
|
||||||
|
Valuator.where.not(id: valuator.id).order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }.prepend([valuator.name, valuator.id])
|
||||||
|
else
|
||||||
|
Valuator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
17
app/views/valuation/_menu.html.erb
Normal file
17
app/views/valuation/_menu.html.erb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<nav class="admin-sidebar">
|
||||||
|
<ul id="valuation_menu">
|
||||||
|
<li>
|
||||||
|
<%= link_to t("valuation.menu.title"), valuation_root_path %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<% if feature?(:spending_proposals) %>
|
||||||
|
<li <%= "class=active" if controller_name == "spending_proposals" %>>
|
||||||
|
<%= link_to valuation_spending_proposals_path do %>
|
||||||
|
<i class="icon-budget"></i>
|
||||||
|
<%= t("valuation.menu.spending_proposals") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
63
app/views/valuation/spending_proposals/index.html.erb
Normal file
63
app/views/valuation/spending_proposals/index.html.erb
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<h2><%= t("valuation.spending_proposals.index.title") %></h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form_tag valuation_spending_proposals_path, method: :get, enforce_utf8: false do %>
|
||||||
|
<div class="small-12 medium-4 column float-right">
|
||||||
|
<%= 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" } %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-4 column float-right">
|
||||||
|
<%= select_tag :valuator_id,
|
||||||
|
options_for_select(valuator_select_options(current_user.valuator), params[:valuator_id]),
|
||||||
|
{ prompt: t("valuation.spending_proposals.index.valuator_filter_all"),
|
||||||
|
label: false,
|
||||||
|
class: "js-submit-on-change" } %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render 'shared/filter_subnav', i18n_namespace: "valuation.spending_proposals.index" %>
|
||||||
|
|
||||||
|
<h3><%= page_entries_info @spending_proposals %></h3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<% @spending_proposals.each do |spending_proposal| %>
|
||||||
|
<tr id="<%= dom_id(spending_proposal) %>">
|
||||||
|
<td>
|
||||||
|
<strong><%= spending_proposal.id %></strong>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= link_to spending_proposal.title, spending_proposal_path(spending_proposal) %>
|
||||||
|
</td>
|
||||||
|
<td class="small">
|
||||||
|
<% if spending_proposal.administrator.present? %>
|
||||||
|
<span title="<%= t('valuation.spending_proposals.index.admin_assigned') %>"><%= spending_proposal.administrator.name %></span>
|
||||||
|
<% else %>
|
||||||
|
<%= t("valuation.spending_proposals.index.no_admin_assigned") %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td class="small">
|
||||||
|
<% case spending_proposal.valuators.size %>
|
||||||
|
<% when 0 %>
|
||||||
|
<%= t("valuation.spending_proposals.index.no_valuators_assigned") %>
|
||||||
|
<% when 1 %>
|
||||||
|
<span title="<%= t('valuation.spending_proposals.index.valuators_assigned', count: 1) %>">
|
||||||
|
<%= spending_proposal.valuators.first.name %>
|
||||||
|
</span>
|
||||||
|
<% else %>
|
||||||
|
<span title="<%= spending_proposal.valuators.map(&:name).join(', ') %>">
|
||||||
|
<%= t('valuation.spending_proposals.index.valuators_assigned', count: spending_proposal.valuators.size) %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td class="small">
|
||||||
|
<%= geozone_name(spending_proposal) %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @spending_proposals %>
|
||||||
21
config/locales/valuation.en.yml
Normal file
21
config/locales/valuation.en.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
en:
|
||||||
|
valuation:
|
||||||
|
menu:
|
||||||
|
title: Valuation
|
||||||
|
spending_proposals: Spending proposals
|
||||||
|
spending_proposals:
|
||||||
|
index:
|
||||||
|
geozone_filter_all: All zones
|
||||||
|
valuator_filter_all: All valuators
|
||||||
|
filters:
|
||||||
|
valuation_open: Open
|
||||||
|
valuating: Under valuation
|
||||||
|
valuation_finished: Valuation finished
|
||||||
|
title: Investment projects for participatory budgeting
|
||||||
|
admin_assigned: Assigned administrator
|
||||||
|
no_admin_assigned: No admin assigned
|
||||||
|
valuators_assigned:
|
||||||
|
one: Assigned valuator
|
||||||
|
other: "%{count} valuators assigned"
|
||||||
|
no_valuators_assigned: No valuators assigned
|
||||||
21
config/locales/valuation.es.yml
Normal file
21
config/locales/valuation.es.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
es:
|
||||||
|
valuation:
|
||||||
|
menu:
|
||||||
|
title: Evaluación
|
||||||
|
spending_proposals: Propuestas de inversión
|
||||||
|
spending_proposals:
|
||||||
|
index:
|
||||||
|
geozone_filter_all: Todos los ámbitos de actuación
|
||||||
|
valuator_filter_all: Todos los evaluadores
|
||||||
|
filters:
|
||||||
|
valuation_open: Abiertas
|
||||||
|
valuating: En evaluación
|
||||||
|
valuation_finished: Evaluación finalizada
|
||||||
|
title: Propuestas de inversión para presupuestos participativos
|
||||||
|
admin_assigned: Administrador asignado
|
||||||
|
no_admin_assigned: Sin admin asignado
|
||||||
|
valuators_assigned:
|
||||||
|
one: Evaluador asignado
|
||||||
|
other: "%{count} evaluadores asignados"
|
||||||
|
no_valuators_assigned: Sin evaluador
|
||||||
143
spec/features/valuation/spending_proposals_spec.rb
Normal file
143
spec/features/valuation/spending_proposals_spec.rb
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Valuation spending proposals' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
valuator = create(:valuator)
|
||||||
|
login_as(valuator.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Disabled with a feature flag' do
|
||||||
|
Setting['feature.spending_proposals'] = nil
|
||||||
|
expect{ visit valuation_spending_proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Index shows spending proposals' do
|
||||||
|
spending_proposal = create(:spending_proposal)
|
||||||
|
visit valuation_spending_proposals_path
|
||||||
|
|
||||||
|
expect(page).to have_content(spending_proposal.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Index shows assignments info' do
|
||||||
|
spending_proposal1 = create(:spending_proposal)
|
||||||
|
spending_proposal2 = create(:spending_proposal)
|
||||||
|
spending_proposal3 = create(:spending_proposal)
|
||||||
|
|
||||||
|
valuator1 = create(:valuator, user: create(:user, username: 'Olga'))
|
||||||
|
valuator2 = create(:valuator, user: create(:user, username: 'Miriam'))
|
||||||
|
admin = create(:administrator, user: create(:user, username: 'Gema'))
|
||||||
|
|
||||||
|
spending_proposal1.valuators << valuator1
|
||||||
|
spending_proposal2.valuator_ids = [valuator1.id, valuator2.id]
|
||||||
|
spending_proposal3.update({administrator_id: admin.id})
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path
|
||||||
|
|
||||||
|
within("#spending_proposal_#{spending_proposal1.id}") do
|
||||||
|
expect(page).to have_content("No admin assigned")
|
||||||
|
expect(page).to have_content("Olga")
|
||||||
|
end
|
||||||
|
|
||||||
|
within("#spending_proposal_#{spending_proposal2.id}") do
|
||||||
|
expect(page).to have_content("No admin assigned")
|
||||||
|
expect(page).to have_content("2 valuators assigned")
|
||||||
|
end
|
||||||
|
|
||||||
|
within("#spending_proposal_#{spending_proposal3.id}") do
|
||||||
|
expect(page).to have_content("Gema")
|
||||||
|
expect(page).to have_content("No valuators assigned")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Index filtering by geozone", :js do
|
||||||
|
geozone = create(:geozone, name: "District 9")
|
||||||
|
create(:spending_proposal, title: "Realocate visitors", geozone: geozone)
|
||||||
|
create(:spending_proposal, title: "Destroy the city")
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path
|
||||||
|
expect(page).to have_link("Realocate visitors")
|
||||||
|
expect(page).to have_link("Destroy the city")
|
||||||
|
|
||||||
|
select "District 9", from: "geozone_id"
|
||||||
|
|
||||||
|
expect(page).to have_link("Realocate visitors")
|
||||||
|
expect(page).to_not have_link("Destroy the city")
|
||||||
|
|
||||||
|
select "All city", from: "geozone_id"
|
||||||
|
|
||||||
|
expect(page).to have_link("Destroy the city")
|
||||||
|
expect(page).to_not have_link("Realocate visitors")
|
||||||
|
|
||||||
|
select "All zones", from: "geozone_id"
|
||||||
|
expect(page).to have_link("Realocate visitors")
|
||||||
|
expect(page).to have_link("Destroy the city")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Index filtering by valuator", :js do
|
||||||
|
user = create(:user, username: 'Karnak')
|
||||||
|
valuator = create(:valuator, user: user)
|
||||||
|
|
||||||
|
spending = create(:spending_proposal, title: "Realocate visitors")
|
||||||
|
spending.valuators << valuator
|
||||||
|
create(:spending_proposal, title: "Destroy the city")
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path
|
||||||
|
expect(page).to have_link("Realocate visitors")
|
||||||
|
expect(page).to have_link("Destroy the city")
|
||||||
|
|
||||||
|
select "Karnak", from: "valuator_id"
|
||||||
|
|
||||||
|
expect(page).to have_link("Realocate visitors")
|
||||||
|
expect(page).to_not have_link("Destroy the city")
|
||||||
|
|
||||||
|
select "All valuators", from: "valuator_id"
|
||||||
|
|
||||||
|
expect(page).to have_link("Destroy the city")
|
||||||
|
expect(page).to have_link("Realocate visitors")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Current filter is properly highlighted" do
|
||||||
|
filters_links = {'valuation_open' => 'Open',
|
||||||
|
'valuating' => 'Under valuation',
|
||||||
|
'valuation_finished' => 'Valuation finished'}
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path
|
||||||
|
|
||||||
|
expect(page).to_not have_link(filters_links.values.first)
|
||||||
|
filters_links.keys.drop(1).each { |filter| expect(page).to have_link(filters_links[filter]) }
|
||||||
|
|
||||||
|
filters_links.each_pair do |current_filter, link|
|
||||||
|
visit valuation_spending_proposals_path(filter: current_filter)
|
||||||
|
|
||||||
|
expect(page).to_not have_link(link)
|
||||||
|
|
||||||
|
(filters_links.keys - [current_filter]).each do |filter|
|
||||||
|
expect(page).to have_link(filters_links[filter])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Index filtering by valuation status" do
|
||||||
|
valuating = create(:spending_proposal, title: "Ongoing valuation")
|
||||||
|
valuated = create(:spending_proposal, title: "Old idea", valuation_finished: true)
|
||||||
|
valuating.valuators << create(:valuator)
|
||||||
|
valuated.valuators << create(:valuator)
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path(filter: 'valuation_open')
|
||||||
|
|
||||||
|
expect(page).to have_content("Ongoing valuation")
|
||||||
|
expect(page).to_not have_content("Old idea")
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path(filter: 'valuating')
|
||||||
|
|
||||||
|
expect(page).to have_content("Ongoing valuation")
|
||||||
|
expect(page).to_not have_content("Old idea")
|
||||||
|
|
||||||
|
visit valuation_spending_proposals_path(filter: 'valuation_finished')
|
||||||
|
|
||||||
|
expect(page).to_not have_content("Ongoing valuation")
|
||||||
|
expect(page).to have_content("Old idea")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user