adds heading filter to index

This commit is contained in:
Juanjo Bazán
2016-09-06 17:03:35 +02:00
parent b0358e4867
commit 31ef3f4c98
7 changed files with 69 additions and 53 deletions

View File

@@ -1,7 +0,0 @@
module BudgetGroupsHelper
def budget_group_select_options(groups)
groups.map {|group| [group.name, group.id]}
end
end

View File

@@ -0,0 +1,7 @@
module BudgetHeadingsHelper
def budget_heading_select_options(budget)
budget.headings.map {|heading| [heading.name, heading.id]}
end
end

View File

@@ -56,7 +56,7 @@ class Budget
before_validation :set_responsible_name before_validation :set_responsible_name
def self.filter_params(params) def self.filter_params(params)
params.select{|x,_| %w{heading_id administrator_id tag_name valuator_id}.include? x.to_s } params.select{|x,_| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s }
end end
def self.scoped_filter(params, current_filter) def self.scoped_filter(params, current_filter)

View File

@@ -19,9 +19,9 @@
</div> </div>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<%= select_tag :group_id, <%= select_tag :heading_id,
options_for_select(budget_group_select_options(@budget.groups), params[:group_id]), options_for_select(budget_heading_select_options(@budget), params[:heading_id]),
{ prompt: t("admin.budget_investments.index.group_filter_all"), { prompt: t("admin.budget_investments.index.heading_filter_all"),
label: false, label: false,
class: "js-submit-on-change" } %> class: "js-submit-on-change" } %>
</div> </div>
@@ -47,7 +47,7 @@
<strong><%= investment.id %></strong> <strong><%= investment.id %></strong>
</td> </td>
<td> <td>
<%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id), Budget::Investment.filter_params(params) %> <%= link_to investment.title, admin_budget_budget_investment_path(budget_id: @budget.id, id: investment.id, params: Budget::Investment.filter_params(params)) %>
</td> </td>
<td class="small"> <td class="small">
<% if investment.administrator.present? %> <% if investment.administrator.present? %>
@@ -64,7 +64,7 @@
<% end %> <% end %>
</td> </td>
<td class="small"> <td class="small">
<%= investment.group.name %> <%= investment.heading.name %>
</td> </td>
<td class="small"> <td class="small">
<%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %> <%= t("admin.budget_investments.index.feasibility.#{investment.feasibility}", price: investment.price) %>

View File

@@ -95,7 +95,7 @@ en:
table_geozone: Scope of operation table_geozone: Scope of operation
budget_investments: budget_investments:
index: index:
group_filter_all: All voting groups heading_filter_all: All headings
administrator_filter_all: All administrators administrator_filter_all: All administrators
valuator_filter_all: All valuators valuator_filter_all: All valuators
tags_filter_all: All tags tags_filter_all: All tags

View File

@@ -95,7 +95,7 @@ es:
table_geozone: Ámbito de actuación table_geozone: Ámbito de actuación
budget_investments: budget_investments:
index: index:
group_filter_all: Todos los grupos heading_filter_all: Todas las partidas
administrator_filter_all: Todos los administradores administrator_filter_all: Todos los administradores
valuator_filter_all: Todos los evaluadores valuator_filter_all: Todos los evaluadores
tags_filter_all: Todas las etiquetas tags_filter_all: Todas las etiquetas

View File

@@ -49,45 +49,61 @@ feature 'Admin budget investments' do
end end
end end
scenario "Filtering by budget group", :js do scenario "Filtering by budget heading", :js do
group1 = create(:budget_group, name: "Street improvments", budget: @budget) group1 = create(:budget_group, name: "Streets", budget: @budget)
group2 = create(:budget_group, name: "Parks", budget: @budget) group2 = create(:budget_group, name: "Parks", budget: @budget)
create(:budget_investment, title: "Realocate visitors", budget: @budget, group: group1) group1_heading1 = create(:budget_heading, group: group1, name: "Main Avenue")
create(:budget_investment, title: "Destroy the city", budget: @budget, group: group2) group1_heading2 = create(:budget_heading, group: group1, name: "Mercy Street")
group2_heading1 = create(:budget_heading, group: group2, name: "Central Park")
create(:budget_investment, title: "Realocate visitors", budget: @budget, group: group1, heading: group1_heading1)
create(:budget_investment, title: "Change name", budget: @budget, group: group1, heading: group1_heading2)
create(:budget_investment, title: "Plant trees", budget: @budget, group: group2, heading: group2_heading1)
visit admin_budget_budget_investments_path(budget_id: @budget.id) visit admin_budget_budget_investments_path(budget_id: @budget.id)
expect(page).to have_link("Realocate visitors") expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city") expect(page).to have_link("Change name")
expect(page).to have_link("Plant trees")
select "Parks", from: "group_id" select "Central Park", from: "heading_id"
expect(page).to have_link("Destroy the city")
expect(page).to_not have_link("Realocate visitors") expect(page).to_not have_link("Realocate visitors")
expect(page).to_not have_link("Change name")
expect(page).to have_link("Plant trees")
select "All voting groups", from: "group_id" select "All headings", from: "heading_id"
expect(page).to have_link("Realocate visitors") expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city") expect(page).to have_link("Change name")
expect(page).to have_link("Plant trees")
select "Street improvments", from: "group_id" select "Main Avenue", from: "heading_id"
expect(page).to_not have_link("Destroy the city")
expect(page).to have_link("Realocate visitors") expect(page).to have_link("Realocate visitors")
expect(page).to_not have_link("Change name")
expect(page).to_not have_link("Plant trees")
# click_link("Realocate visitors") select "Mercy Street", from: "heading_id"
# click_link("Back")
# expect(page).to_not have_link("Destroy the city") expect(page).to_not have_link("Realocate visitors")
# expect(page).to have_link("Realocate visitors") expect(page).to have_link("Change name")
expect(page).to_not have_link("Plant trees")
click_link("Change name")
click_link("Go back")
expect(page).to_not have_link("Realocate visitors")
expect(page).to have_link("Change name")
expect(page).to_not have_link("Plant trees")
# click_link("Realocate visitors") # click_link("Realocate visitors")
# click_link("Edit classification") # click_link("Edit classification")
# expect(page).to have_button("Update") # expect(page).to have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to_not have_button("Update") # expect(page).to_not have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to_not have_link("Destroy the city") # expect(page).to_not have_link("Destroy the city")
# expect(page).to have_link("Realocate visitors") # expect(page).to have_link("Realocate visitors")
@@ -119,19 +135,19 @@ feature 'Admin budget investments' do
select "Admin 1", from: "administrator_id" select "Admin 1", from: "administrator_id"
expect(page).to have_content('There is 1 investment') expect(page).to have_content('There is 1 investment')
# click_link("Realocate visitors") click_link("Realocate visitors")
# click_link("Back") click_link("Go back")
# expect(page).to have_content('There is 1 investment') expect(page).to have_content('There is 1 investment')
# expect(page).to_not have_link("Destroy the city") expect(page).to_not have_link("Destroy the city")
# expect(page).to have_link("Realocate visitors") expect(page).to have_link("Realocate visitors")
# click_link("Realocate visitors") # click_link("Realocate visitors")
# click_link("Edit classification") # click_link("Edit classification")
# expect(page).to have_button("Update") # expect(page).to have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to_not have_button("Update") # expect(page).to_not have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to have_content('There is 1 investment') # expect(page).to have_content('There is 1 investment')
# expect(page).to_not have_link("Destroy the city") # expect(page).to_not have_link("Destroy the city")
@@ -165,19 +181,19 @@ feature 'Admin budget investments' do
select "Valuator 1", from: "valuator_id" select "Valuator 1", from: "valuator_id"
expect(page).to have_content('There is 1 investment') expect(page).to have_content('There is 1 investment')
# click_link("Realocate visitors") click_link("Realocate visitors")
# click_link("Back") click_link("Go back")
# expect(page).to have_content('There is 1 investment') expect(page).to have_content('There is 1 investment')
# expect(page).to_not have_link("Destroy the city") expect(page).to_not have_link("Destroy the city")
# expect(page).to have_link("Realocate visitors") expect(page).to have_link("Realocate visitors")
# click_link("Realocate visitors") # click_link("Realocate visitors")
# click_link("Edit classification") # click_link("Edit classification")
# expect(page).to have_button("Update") # expect(page).to have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to_not have_button("Update") # expect(page).to_not have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to have_content('There is 1 investment') # expect(page).to have_content('There is 1 investment')
# expect(page).to_not have_link("Destroy the city") # expect(page).to_not have_link("Destroy the city")
@@ -274,19 +290,19 @@ feature 'Admin budget investments' do
expect(page).to have_content("Educate the children") expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools") expect(page).to have_content("More schools")
# click_link("Educate the children") click_link("Educate the children")
# click_link("Back") click_link("Go back")
# expect(page).to_not have_content("More hospitals") expect(page).to_not have_content("More hospitals")
# expect(page).to have_content("Educate the children") expect(page).to have_content("Educate the children")
# expect(page).to have_content("More schools") expect(page).to have_content("More schools")
# click_link("Educate the children") # click_link("Educate the children")
# click_link("Edit classification") # click_link("Edit classification")
# expect(page).to have_button("Update") # expect(page).to have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to_not have_button("Update") # expect(page).to_not have_button("Update")
# click_link("Back") # click_link("Go back")
# expect(page).to_not have_content("More hospitals") # expect(page).to_not have_content("More hospitals")
# expect(page).to have_content("Educate the children") # expect(page).to have_content("Educate the children")