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
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@@ -26,17 +26,5 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
|||||||
@spending_proposal.update(params.require(:spending_proposal).permit(valuator_ids: []))
|
@spending_proposal.update(params.require(:spending_proposal).permit(valuator_ids: []))
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ module AdminHelper
|
|||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def admin_select_options
|
||||||
|
Administrator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def namespace
|
def namespace
|
||||||
|
|||||||
@@ -23,10 +23,36 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
scope :valuating, -> { where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
|
scope :valuating, -> { where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
|
||||||
scope :valuation_finished, -> { where(valuation_finished: true) }
|
scope :valuation_finished, -> { where(valuation_finished: true) }
|
||||||
|
|
||||||
|
scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) }
|
||||||
|
|
||||||
def description
|
def description
|
||||||
super.try :html_safe
|
super.try :html_safe
|
||||||
end
|
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
|
def feasibility
|
||||||
case feasible
|
case feasible
|
||||||
when true
|
when true
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
<h2><%= t("admin.spending_proposals.index.title") %></h2>
|
<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 %>
|
<%= 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]),
|
<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"),
|
{ prompt: t("admin.spending_proposals.index.geozone_filter_all"),
|
||||||
label: false,
|
label: false,
|
||||||
class: "js-submit-on-change" } %>
|
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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ en:
|
|||||||
spending_proposals:
|
spending_proposals:
|
||||||
index:
|
index:
|
||||||
geozone_filter_all: All zones
|
geozone_filter_all: All zones
|
||||||
valuator_filter_all: All valuators
|
administrator_filter_all: All administrators
|
||||||
filters:
|
filters:
|
||||||
all: All
|
all: All
|
||||||
without_admin: Without assigned admin
|
without_admin: Without assigned admin
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ es:
|
|||||||
spending_proposals:
|
spending_proposals:
|
||||||
index:
|
index:
|
||||||
geozone_filter_all: Todos los ámbitos de actuación
|
geozone_filter_all: Todos los ámbitos de actuación
|
||||||
valuator_filter_all: Todos los evaluadores
|
administrator_filter_all: Todos los administradores
|
||||||
filters:
|
filters:
|
||||||
all: Todas
|
all: Todas
|
||||||
without_admin: Sin administrador asignado
|
without_admin: Sin administrador asignado
|
||||||
|
|||||||
@@ -74,6 +74,28 @@ feature 'Admin spending proposals' do
|
|||||||
expect(page).to have_link("Destroy the city")
|
expect(page).to have_link("Destroy the city")
|
||||||
end
|
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
|
scenario "Current filter is properly highlighted" do
|
||||||
filters_links = {'all' => 'All',
|
filters_links = {'all' => 'All',
|
||||||
'without_admin' => 'Without assigned admin',
|
'without_admin' => 'Without assigned admin',
|
||||||
|
|||||||
Reference in New Issue
Block a user