diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb
new file mode 100644
index 000000000..bf15ee7f6
--- /dev/null
+++ b/app/controllers/admin/budget_investments_controller.rb
@@ -0,0 +1,15 @@
+class Admin::BudgetInvestmentsController < Admin::BaseController
+
+ has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index
+
+ def index
+ @budget = Budget.includes(:groups).find params[:budget_id]
+ @investments = @budget.investments.scoped_filter(params, @current_filter).order(cached_votes_up: :desc, created_at: :desc).page(params[:page])
+ end
+
+ def show
+ @budget = Budget.includes(:groups).find params[:budget_id]
+ @investment = @budget.investments.find params[:id]
+ end
+
+end
\ No newline at end of file
diff --git a/app/helpers/budget_groups_helper.rb b/app/helpers/budget_groups_helper.rb
new file mode 100644
index 000000000..d36a992d9
--- /dev/null
+++ b/app/helpers/budget_groups_helper.rb
@@ -0,0 +1,7 @@
+module BudgetGroupsHelper
+
+ def budget_group_select_options(groups)
+ groups.map {|group| [group.name, group.id]}
+ end
+
+end
\ No newline at end of file
diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb
new file mode 100644
index 000000000..31ad2298a
--- /dev/null
+++ b/app/views/admin/budget_investments/index.html.erb
@@ -0,0 +1,76 @@
+
+ <%= form_tag admin_budget_budget_investments_path(budget: @budget), method: :get, enforce_utf8: false do %>
+
+ <%= select_tag :administrator_id,
+ options_for_select(admin_select_options, params[:administrator_id]),
+ { prompt: t("admin.budget_investments.index.administrator_filter_all"),
+ label: false,
+ class: "js-submit-on-change" } %>
+
+
+
+ <%= select_tag :valuator_id,
+ options_for_select(valuator_select_options, params[:valuator_id]),
+ { prompt: t("admin.budget_investments.index.valuator_filter_all"),
+ label: false,
+ class: "js-submit-on-change" } %>
+
+
+
+ <%= select_tag :group_id,
+ options_for_select(budget_group_select_options(@budget.groups), params[:group_id]),
+ { prompt: t("admin.budget_investments.index.group_filter_all"),
+ label: false,
+ class: "js-submit-on-change" } %>
+
+
+
+ <%= select_tag :tag_name,
+ options_for_select(spending_proposal_tags_select_options, params[:tag_name]),
+ { prompt: t("admin.budget_investments.index.tags_filter_all"),
+ label: false,
+ class: "js-submit-on-change" } %>
+
+ <% end %>
+
+
+<%= render 'shared/filter_subnav', i18n_namespace: "admin.budget_investments.index" %>
+
+
+ <% @investments.each do |investment| %>
+
+ |
+ <%= investment.id %>
+ |
+
+ <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id), Budget::Investment.filter_params(params) %>
+ |
+
+ <% if investment.administrator.present? %>
+ <%= investment.administrator.name %>
+ <% else %>
+ <%= t("admin.budget_investments.index.no_admin_assigned") %>
+ <% end %>
+ |
+
+ <% if investment.valuators.size == 0 %>
+ <%= t("admin.budget_investments.index.no_valuators_assigned") %>
+ <% else %>
+ <%= investment.valuators.collect(&:description_or_name).join(', ') %>
+ <% end %>
+ |
+
+ <%= investment.group.name %>
+ |
+
+ <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %>
+ |
+
+ <% end %>
+
+
+<%= paginate @investments %>
\ No newline at end of file
diff --git a/app/views/admin/budget_investments/show.html.erb b/app/views/admin/budget_investments/show.html.erb
new file mode 100644
index 000000000..a142a388d
--- /dev/null
+++ b/app/views/admin/budget_investments/show.html.erb
@@ -0,0 +1 @@
+<%= @investment.title %>
\ No newline at end of file
diff --git a/app/views/admin/budgets/index.html.erb b/app/views/admin/budgets/index.html.erb
index 193b6a7ef..d4de771db 100644
--- a/app/views/admin/budgets/index.html.erb
+++ b/app/views/admin/budgets/index.html.erb
@@ -13,11 +13,14 @@
<% @budgets.each do |budget| %>
|
- <%= link_to budget.name, admin_budget_path(budget) %>
+ <%= link_to budget.name, admin_budget_budget_investments_path(budget_id: budget.id) %>
|
<%= t("budget.phase.#{budget.phase}") %>
|
+
+ <%= link_to t("admin.budgets.index.info_link"), admin_budget_path(budget) %>
+ |
<% end %>
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
index 7df6f7f9e..161ed6dfd 100644
--- a/config/i18n-tasks.yml
+++ b/config/i18n-tasks.yml
@@ -117,6 +117,7 @@ ignore_unused:
- 'admin.debates.index.filter*'
- 'admin.proposals.index.filter*'
- 'admin.budgets.index.filter*'
+ - 'admin.budget_investments.index.filter*'
- 'admin.spending_proposals.index.filter*'
- 'admin.organizations.index.filter*'
- 'admin.users.index.filter*'
diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml
index ccd0240e8..c7c811801 100644
--- a/config/locales/activerecord.es.yml
+++ b/config/locales/activerecord.es.yml
@@ -7,6 +7,9 @@ es:
budget:
one: "Presupuesto participativo"
other: "Presupuestos participativos"
+ budget/investment:
+ one: "Propuesta de inversión"
+ other: "Propuestas de inversión"
comment:
one: "Comentario"
other: "Comentarios"
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 78a3a6d6c..61845a164 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -62,6 +62,7 @@ en:
index:
title: Participatory budgets
new_link: Create new
+ info_link: Info
filters:
open: Open
finished: Finished
@@ -92,6 +93,27 @@ en:
table_heading: Heading
table_amount: Amount
table_geozone: Scope of operation
+ budget_investments:
+ index:
+ group_filter_all: All voting groups
+ administrator_filter_all: All administrators
+ valuator_filter_all: All valuators
+ tags_filter_all: All tags
+ filters:
+ valuation_open: Open
+ without_admin: Without assigned admin
+ managed: Managed
+ valuating: Under valuation
+ valuation_finished: Valuation finished
+ all: All
+ title: Investment projects
+ assigned_admin: Assigned administrator
+ no_admin_assigned: No admin assigned
+ no_valuators_assigned: No valuators assigned
+ feasibility:
+ feasible: "Feasible (%{price})"
+ not_feasible: "Not feasible"
+ undefined: "Undefined"
comments:
index:
filter: Filter
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 496a0208d..7d2417480 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -62,6 +62,7 @@ es:
index:
title: Presupuestos participativos
new_link: Crear nuevo
+ info_link: Info
filters:
open: Abiertos
finished: Terminados
@@ -92,6 +93,27 @@ es:
table_heading: Partida
table_amount: Cantidad
table_geozone: Ámbito de actuación
+ budget_investments:
+ index:
+ group_filter_all: Todos los grupos
+ administrator_filter_all: Todos los administradores
+ valuator_filter_all: Todos los evaluadores
+ tags_filter_all: Todas las etiquetas
+ filters:
+ valuation_open: Abiertas
+ without_admin: Sin administrador
+ managed: Gestionando
+ valuating: En evaluación
+ valuation_finished: Evaluación finalizada
+ all: Todas
+ title: Propuestas de inversión
+ assigned_admin: Administrador asignado
+ no_admin_assigned: Sin admin asignado
+ no_valuators_assigned: Sin evaluador
+ feasibility:
+ feasible: "Viable (%{price})"
+ not_feasible: "Inviable"
+ undefined: "Sin definir"
comments:
index:
filter: Filtro
diff --git a/config/routes.rb b/config/routes.rb
index 92f3d6c22..278153a19 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -161,6 +161,8 @@ Rails.application.routes.draw do
resources :budget_headings do
end
end
+
+ resources :budget_investments, only: [:index, :show]
end
resources :banners, only: [:index, :new, :create, :edit, :update, :destroy] do
diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb
new file mode 100644
index 000000000..3c5e611c5
--- /dev/null
+++ b/spec/features/admin/budget_investments_spec.rb
@@ -0,0 +1,298 @@
+require 'rails_helper'
+
+feature 'Admin budget investments' do
+
+ background do
+ admin = create(:administrator)
+ login_as(admin.user)
+
+ @budget = create(:budget)
+ end
+
+ context "Index" do
+
+ scenario 'Displaying investmentss' do
+ budget_investment = create(:budget_investment, budget: @budget)
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+ expect(page).to have_content(budget_investment.title)
+ end
+
+ scenario 'Displaying assignments info' do
+ budget_investment1 = create(:budget_investment, budget: @budget)
+ budget_investment2 = create(:budget_investment, budget: @budget)
+ budget_investment3 = create(:budget_investment, budget: @budget)
+
+ valuator1 = create(:valuator, user: create(:user, username: 'Olga'), description: 'Valuator Olga')
+ valuator2 = create(:valuator, user: create(:user, username: 'Miriam'), description: 'Valuator Miriam')
+ admin = create(:administrator, user: create(:user, username: 'Gema'))
+
+ budget_investment1.valuators << valuator1
+ budget_investment2.valuator_ids = [valuator1.id, valuator2.id]
+ budget_investment3.update({administrator_id: admin.id})
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+
+ within("#budget_investment_#{budget_investment1.id}") do
+ expect(page).to have_content("No admin assigned")
+ expect(page).to have_content("Valuator Olga")
+ end
+
+ within("#budget_investment_#{budget_investment2.id}") do
+ expect(page).to have_content("No admin assigned")
+ expect(page).to have_content("Valuator Olga")
+ expect(page).to have_content("Valuator Miriam")
+ end
+
+ within("#budget_investment_#{budget_investment3.id}") do
+ expect(page).to have_content("Gema")
+ expect(page).to have_content("No valuators assigned")
+ end
+ end
+
+ scenario "Filtering by budget group", :js do
+ group1 = create(:budget_group, name: "Street improvments", budget: @budget)
+ group2 = create(:budget_group, name: "Parks", budget: @budget)
+
+ create(:budget_investment, title: "Realocate visitors", budget: @budget, group: group1)
+ create(:budget_investment, title: "Destroy the city", budget: @budget, group: group2)
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+
+ expect(page).to have_link("Realocate visitors")
+ expect(page).to have_link("Destroy the city")
+
+ select "Parks", from: "group_id"
+
+ expect(page).to have_link("Destroy the city")
+ expect(page).to_not have_link("Realocate visitors")
+
+ select "All voting groups", from: "group_id"
+
+ expect(page).to have_link("Realocate visitors")
+ expect(page).to have_link("Destroy the city")
+
+ select "Street improvments", from: "group_id"
+
+ expect(page).to_not have_link("Destroy the city")
+ expect(page).to have_link("Realocate visitors")
+
+ # click_link("Realocate visitors")
+ # click_link("Back")
+
+ # expect(page).to_not have_link("Destroy the city")
+ # expect(page).to have_link("Realocate visitors")
+
+ # click_link("Realocate visitors")
+ # click_link("Edit classification")
+ # expect(page).to have_button("Update")
+ # click_link("Back")
+ # expect(page).to_not have_button("Update")
+ # click_link("Back")
+
+ # expect(page).to_not have_link("Destroy the city")
+ # expect(page).to have_link("Realocate visitors")
+ end
+
+ scenario "Filtering by admin", :js do
+ user = create(:user, username: 'Admin 1')
+ administrator = create(:administrator, user: user)
+
+ create(:budget_investment, title: "Realocate visitors", budget: @budget, administrator: administrator)
+ create(:budget_investment, title: "Destroy the city", budget: @budget)
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+ expect(page).to have_link("Realocate visitors")
+ expect(page).to have_link("Destroy the city")
+
+ select "Admin 1", from: "administrator_id"
+
+ expect(page).to have_content('There is 1 investment')
+ expect(page).to_not have_link("Destroy the city")
+ expect(page).to have_link("Realocate visitors")
+
+ select "All administrators", from: "administrator_id"
+
+ expect(page).to have_content('There are 2 investments')
+ expect(page).to have_link("Destroy the city")
+ expect(page).to have_link("Realocate visitors")
+
+ select "Admin 1", from: "administrator_id"
+ expect(page).to have_content('There is 1 investment')
+
+ # click_link("Realocate visitors")
+ # click_link("Back")
+
+ # expect(page).to have_content('There is 1 investment')
+ # expect(page).to_not have_link("Destroy the city")
+ # expect(page).to have_link("Realocate visitors")
+
+ # click_link("Realocate visitors")
+ # click_link("Edit classification")
+ # expect(page).to have_button("Update")
+ # click_link("Back")
+ # expect(page).to_not have_button("Update")
+ # click_link("Back")
+
+ # expect(page).to have_content('There is 1 investment')
+ # expect(page).to_not have_link("Destroy the city")
+ # expect(page).to have_link("Realocate visitors")
+ end
+
+ scenario "Filtering by valuator", :js do
+ user = create(:user)
+ valuator = create(:valuator, user: user, description: 'Valuator 1')
+
+ budget_investment = create(:budget_investment, title: "Realocate visitors", budget: @budget)
+ budget_investment.valuators << valuator
+
+ create(:budget_investment, title: "Destroy the city", budget: @budget)
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+ expect(page).to have_link("Realocate visitors")
+ expect(page).to have_link("Destroy the city")
+
+ select "Valuator 1", from: "valuator_id"
+
+ expect(page).to have_content('There is 1 investment')
+ expect(page).to_not have_link("Destroy the city")
+ expect(page).to have_link("Realocate visitors")
+
+ select "All valuators", from: "valuator_id"
+
+ expect(page).to have_content('There are 2 investments')
+ expect(page).to have_link("Destroy the city")
+ expect(page).to have_link("Realocate visitors")
+
+ select "Valuator 1", from: "valuator_id"
+ expect(page).to have_content('There is 1 investment')
+ # click_link("Realocate visitors")
+ # click_link("Back")
+
+ # expect(page).to have_content('There is 1 investment')
+ # expect(page).to_not have_link("Destroy the city")
+ # expect(page).to have_link("Realocate visitors")
+
+ # click_link("Realocate visitors")
+ # click_link("Edit classification")
+ # expect(page).to have_button("Update")
+ # click_link("Back")
+ # expect(page).to_not have_button("Update")
+ # click_link("Back")
+
+ # expect(page).to have_content('There is 1 investment')
+ # expect(page).to_not 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',
+ 'without_admin' => 'Without assigned admin',
+ 'managed' => 'Managed',
+ 'valuating' => 'Under valuation',
+ 'valuation_finished' => 'Valuation finished',
+ 'all' => 'All'}
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+
+ 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 admin_budget_budget_investments_path(budget_id: @budget.id, 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 "Filtering by assignment status" do
+ assigned = create(:budget_investment, title: "Assigned idea", budget: @budget, administrator: create(:administrator))
+ valuating = create(:budget_investment, title: "Evaluating...", budget: @budget)
+ valuating.valuators << create(:valuator)
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'valuation_open')
+
+ expect(page).to have_content("Assigned idea")
+ expect(page).to have_content("Evaluating...")
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'without_admin')
+
+ expect(page).to have_content("Evaluating...")
+ expect(page).to_not have_content("Assigned idea")
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'managed')
+
+ expect(page).to have_content("Assigned idea")
+ expect(page).to_not have_content("Evaluating...")
+ end
+
+ scenario "Filtering by valuation status" do
+ valuating = create(:budget_investment, budget: @budget, title: "Ongoing valuation")
+ valuated = create(:budget_investment, budget: @budget, title: "Old idea", valuation_finished: true)
+ valuating.valuators << create(:valuator)
+ valuated.valuators << create(:valuator)
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'valuation_open')
+
+ expect(page).to have_content("Ongoing valuation")
+ expect(page).to_not have_content("Old idea")
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'valuating')
+
+ expect(page).to have_content("Ongoing valuation")
+ expect(page).to_not have_content("Old idea")
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'valuation_finished')
+
+ expect(page).to_not have_content("Ongoing valuation")
+ expect(page).to have_content("Old idea")
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, filter: 'all')
+ expect(page).to have_content("Ongoing valuation")
+ expect(page).to have_content("Old idea")
+ end
+
+ scenario "Filtering by tag" do
+ create(:budget_investment, budget: @budget, title: 'Educate the children', tag_list: 'Education')
+ create(:budget_investment, budget: @budget, title: 'More schools', tag_list: 'Education')
+ create(:budget_investment, budget: @budget, title: 'More hospitals', tag_list: 'Health')
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id)
+
+ expect(page).to have_css(".budget_investment", count: 3)
+ expect(page).to have_content("Educate the children")
+ expect(page).to have_content("More schools")
+ expect(page).to have_content("More hospitals")
+
+ visit admin_budget_budget_investments_path(budget_id: @budget.id, tag_name: 'Education')
+
+ expect(page).to_not have_content("More hospitals")
+ expect(page).to have_css(".budget_investment", count: 2)
+ expect(page).to have_content("Educate the children")
+ expect(page).to have_content("More schools")
+
+ # click_link("Educate the children")
+ # click_link("Back")
+
+ # expect(page).to_not have_content("More hospitals")
+ # expect(page).to have_content("Educate the children")
+ # expect(page).to have_content("More schools")
+
+ # click_link("Educate the children")
+ # click_link("Edit classification")
+ # expect(page).to have_button("Update")
+ # click_link("Back")
+ # expect(page).to_not have_button("Update")
+ # click_link("Back")
+
+ # expect(page).to_not have_content("More hospitals")
+ # expect(page).to have_content("Educate the children")
+ # expect(page).to have_content("More schools")
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb
index 123ca43e8..a87cd741a 100644
--- a/spec/features/admin/budgets_spec.rb
+++ b/spec/features/admin/budgets_spec.rb
@@ -105,10 +105,13 @@ feature 'Admin budgets' do
context 'Manage groups and headings' do
scenario 'Create group', :js do
- create(:budget, name: 'Yearly participatory budget')
+ budget = create(:budget, name: 'Yearly participatory budget')
visit admin_budgets_path
- click_link 'Yearly participatory budget'
+
+ within("#budget_#{budget.id}") do
+ click_link 'Info'
+ end
expect(page).to have_content 'No groups created yet.'