adds filtering of spending proposals by admin
This commit is contained in:
@@ -7,7 +7,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@spending_proposals = geozone_filter(params[:geozone_id].presence).includes(:geozone, administrator: :user, valuators: :user).send(@current_filter).order(created_at: :desc).page(params[:page])
|
||||
@spending_proposals = SpendingProposal.search(params, @current_filter).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -26,17 +26,5 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
||||
@spending_proposal.update(params.require(:spending_proposal).permit(valuator_ids: []))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def geozone_filter(geozone)
|
||||
case geozone
|
||||
when nil
|
||||
@spending_proposals
|
||||
when 'all'
|
||||
@spending_proposals.where(geozone_id: nil)
|
||||
else
|
||||
@spending_proposals.where(geozone_id: params[:geozone_id].presence)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -12,6 +12,10 @@ module AdminHelper
|
||||
options
|
||||
end
|
||||
|
||||
def admin_select_options
|
||||
Administrator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def namespace
|
||||
|
||||
@@ -23,10 +23,36 @@ class SpendingProposal < ActiveRecord::Base
|
||||
scope :valuating, -> { where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
|
||||
scope :valuation_finished, -> { where(valuation_finished: true) }
|
||||
|
||||
scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) }
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
def self.search(params, current_filter)
|
||||
results = self
|
||||
results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present?
|
||||
results = results.by_administrator(params[:administrator_id]) if params[:administrator_id].present?
|
||||
results = results.send(current_filter) if current_filter.present?
|
||||
results = results.for_render
|
||||
results
|
||||
end
|
||||
|
||||
def self.by_geozone(geozone)
|
||||
case geozone
|
||||
when nil
|
||||
self
|
||||
when 'all'
|
||||
where(geozone_id: nil)
|
||||
else
|
||||
where(geozone_id: geozone.presence)
|
||||
end
|
||||
end
|
||||
|
||||
def self.by_administrator(administrator)
|
||||
where(administrator_id: administrator.presence)
|
||||
end
|
||||
|
||||
def feasibility
|
||||
case feasible
|
||||
when true
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
<h2><%= t("admin.spending_proposals.index.title") %></h2>
|
||||
|
||||
<div class="small-12 medium-4 column float-right">
|
||||
<div>
|
||||
<%= form_tag admin_spending_proposals_path, method: :get, enforce_utf8: false do %>
|
||||
<%= select_tag :geozone_id, options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]),
|
||||
{ prompt: t("admin.spending_proposals.index.geozone_filter_all"),
|
||||
label: false,
|
||||
class: "js-submit-on-change"} %>
|
||||
<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("admin.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 :administrator_id,
|
||||
options_for_select(admin_select_options, params[:administrator_id]),
|
||||
{ prompt: t("admin.spending_proposals.index.administrator_filter_all"),
|
||||
label: false,
|
||||
class: "js-submit-on-change" } %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ en:
|
||||
spending_proposals:
|
||||
index:
|
||||
geozone_filter_all: All zones
|
||||
valuator_filter_all: All valuators
|
||||
administrator_filter_all: All administrators
|
||||
filters:
|
||||
all: All
|
||||
without_admin: Without assigned admin
|
||||
|
||||
@@ -151,7 +151,7 @@ es:
|
||||
spending_proposals:
|
||||
index:
|
||||
geozone_filter_all: Todos los ámbitos de actuación
|
||||
valuator_filter_all: Todos los evaluadores
|
||||
administrator_filter_all: Todos los administradores
|
||||
filters:
|
||||
all: Todas
|
||||
without_admin: Sin administrador asignado
|
||||
|
||||
@@ -74,6 +74,28 @@ feature 'Admin spending proposals' do
|
||||
expect(page).to have_link("Destroy the city")
|
||||
end
|
||||
|
||||
scenario "Index filtering by admin", :js do
|
||||
user = create(:user, username: 'Admin 1')
|
||||
administrator = create(:administrator, user: user)
|
||||
|
||||
create(:spending_proposal, title: "Realocate visitors", administrator: administrator)
|
||||
create(:spending_proposal, title: "Destroy the city")
|
||||
|
||||
visit admin_spending_proposals_path
|
||||
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_link("Realocate visitors")
|
||||
expect(page).to_not have_link("Destroy the city")
|
||||
|
||||
select "All administrators", from: "administrator_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 = {'all' => 'All',
|
||||
'without_admin' => 'Without assigned admin',
|
||||
|
||||
Reference in New Issue
Block a user