Filter by valuator group
This commit is contained in:
@@ -32,8 +32,8 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
def edit
|
||||
load_admins
|
||||
load_valuators
|
||||
load_valuator_groups
|
||||
load_tags
|
||||
@valuator_groups = ValuatorGroup.all
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -113,6 +113,10 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
@valuators = Valuator.includes(:user).all.order(description: :asc).order("users.email ASC")
|
||||
end
|
||||
|
||||
def load_valuator_groups
|
||||
@valuator_groups = ValuatorGroup.all.order(name: :asc)
|
||||
end
|
||||
|
||||
def load_tags
|
||||
@tags = Budget::Investment.tags_on(:valuation).order(:name).uniq
|
||||
end
|
||||
|
||||
@@ -10,6 +10,16 @@ module ValuationHelper
|
||||
end
|
||||
end
|
||||
|
||||
def valuator_group_select_options(group = nil)
|
||||
if group.present?
|
||||
ValuatorGroup.where.not(id: group.id).order("name ASC")
|
||||
.collect { |g| [ g.name, g.id ] }
|
||||
.prepend([valuator.name, valuator.id])
|
||||
else
|
||||
ValuatorGroup.order("name ASC").collect { |g| [ g.name, g.id ] }
|
||||
end
|
||||
end
|
||||
|
||||
def assigned_valuators_info(valuators)
|
||||
case valuators.size
|
||||
when 0
|
||||
|
||||
@@ -79,12 +79,13 @@ class Budget
|
||||
scope :unselected, -> { not_unfeasible.where(selected: false) }
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
|
||||
scope :by_group, ->(group_id) { where(group_id: group_id) }
|
||||
scope :by_heading, ->(heading_id) { where(heading_id: heading_id) }
|
||||
scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) }
|
||||
scope :by_tag, ->(tag_name) { tagged_with(tag_name) }
|
||||
scope :by_valuator, ->(valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) }
|
||||
scope :by_budget, ->(budget) { where(budget: budget) }
|
||||
scope :by_budget, ->(budget) { where(budget: budget) }
|
||||
scope :by_group, ->(group_id) { where(group_id: group_id) }
|
||||
scope :by_heading, ->(heading_id) { where(heading_id: heading_id) }
|
||||
scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) }
|
||||
scope :by_tag, ->(tag_name) { tagged_with(tag_name) }
|
||||
scope :by_valuator, ->(valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) }
|
||||
scope :by_valuator_group, ->(valuator_group_id) { where("budget_valuator_group_assignments.valuator_group_id = ?", valuator_group_id).joins(:valuator_group_assignments) }
|
||||
|
||||
scope :for_render, -> { includes(:heading) }
|
||||
|
||||
@@ -109,13 +110,14 @@ class Budget
|
||||
budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
||||
results = Investment.by_budget(budget)
|
||||
|
||||
results = limit_results(budget, params, results) if params[:max_per_heading].present?
|
||||
results = results.where(group_id: params[:group_id]) if params[:group_id].present?
|
||||
results = results.by_tag(params[:tag_name]) if params[:tag_name].present?
|
||||
results = results.by_heading(params[:heading_id]) if params[:heading_id].present?
|
||||
results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present?
|
||||
results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present?
|
||||
results = advanced_filters(params, results) if params[:advanced_filters].present?
|
||||
results = limit_results(budget, params, results) if params[:max_per_heading].present?
|
||||
results = results.where(group_id: params[:group_id]) if params[:group_id].present?
|
||||
results = results.by_tag(params[:tag_name]) if params[:tag_name].present?
|
||||
results = results.by_heading(params[:heading_id]) if params[:heading_id].present?
|
||||
results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present?
|
||||
results = results.by_valuator_group(params[:valuator_group_id]) if params[:valuator_group_id].present?
|
||||
results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present?
|
||||
results = advanced_filters(params, results) if params[:advanced_filters].present?
|
||||
|
||||
results = results.send(current_filter) if current_filter.present?
|
||||
results.includes(:heading, :group, :budget, administrator: :user, valuators: :user)
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
class: "js-submit-on-change" } %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= select_tag :valuator_group_id,
|
||||
options_for_select(valuator_group_select_options, params[:valuator_group_id]),
|
||||
{ prompt: t("admin.budget_investments.index.valuator_group_filter_all"),
|
||||
label: false,
|
||||
class: "js-submit-on-change" } %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<%= select_tag :heading_id,
|
||||
options_for_select(budget_heading_select_options(@budget), params[:heading_id]),
|
||||
|
||||
@@ -140,6 +140,7 @@ en:
|
||||
heading_filter_all: All headings
|
||||
administrator_filter_all: All administrators
|
||||
valuator_filter_all: All valuators
|
||||
valuator_group_filter_all: All groups
|
||||
tags_filter_all: All tags
|
||||
advanced_filters: Advanced filters
|
||||
placeholder: Search projects
|
||||
@@ -956,6 +957,7 @@ en:
|
||||
geozone_filter_all: All zones
|
||||
administrator_filter_all: All administrators
|
||||
valuator_filter_all: All valuators
|
||||
valuator_group_filter_all: All groups
|
||||
tags_filter_all: All tags
|
||||
filters:
|
||||
valuation_open: Open
|
||||
|
||||
@@ -140,6 +140,7 @@ es:
|
||||
heading_filter_all: Todas las partidas
|
||||
administrator_filter_all: Todos los administradores
|
||||
valuator_filter_all: Todos los evaluadores
|
||||
valuator_group_filter_all: Todos los grupos
|
||||
tags_filter_all: Todas las etiquetas
|
||||
advanced_filters: Filtros avanzados
|
||||
placeholder: Buscar proyectos
|
||||
@@ -956,6 +957,7 @@ es:
|
||||
geozone_filter_all: Todos los ámbitos de actuación
|
||||
administrator_filter_all: Todos los administradores
|
||||
valuator_filter_all: Todos los evaluadores
|
||||
valuator_group_filter_all: Todos los grupos
|
||||
tags_filter_all: Todas las etiquetas
|
||||
filters:
|
||||
valuation_open: Abiertas
|
||||
|
||||
@@ -189,6 +189,39 @@ feature 'Admin budget investments' do
|
||||
expect(page).to have_link("Realocate visitors")
|
||||
end
|
||||
|
||||
scenario "Filtering by valuator group", :js, :focus do
|
||||
user = create(:user)
|
||||
health_group = create(:valuator_group, name: "Health")
|
||||
culture_group = create(:valuator_group, name: "Culture")
|
||||
|
||||
budget_investment1 = create(:budget_investment, title: "Build a hospital", budget: @budget)
|
||||
budget_investment1.valuator_groups << health_group
|
||||
|
||||
budget_investment2 = create(:budget_investment, title: "Build a theatre", budget: @budget)
|
||||
budget_investment2.valuator_groups << culture_group
|
||||
|
||||
visit admin_budget_budget_investments_path(budget_id: @budget.id)
|
||||
expect(page).to have_link("Build a hospital")
|
||||
expect(page).to have_link("Build a theatre")
|
||||
|
||||
select "Health", from: "valuator_group_id"
|
||||
|
||||
expect(page).to have_content('There is 1 investment')
|
||||
expect(page).to have_link("Build a hospital")
|
||||
expect(page).not_to have_link("Build a theatre")
|
||||
|
||||
select "All groups", from: "valuator_group_id"
|
||||
|
||||
expect(page).to have_content('There are 2 investments')
|
||||
expect(page).to have_link("Build a hospital")
|
||||
expect(page).to have_link("Build a theatre")
|
||||
|
||||
select "Culture", from: "valuator_group_id"
|
||||
expect(page).to have_content('There is 1 investment')
|
||||
expect(page).to have_link("Build a theatre")
|
||||
expect(page).not_to have_link("Build a hospital")
|
||||
end
|
||||
|
||||
scenario "Current filter is properly highlighted" do
|
||||
filters_links = { 'all' => 'All',
|
||||
'without_admin' => 'Without assigned admin',
|
||||
|
||||
Reference in New Issue
Block a user