adds filtering of tags for spending proposals
This commit is contained in:
@@ -16,7 +16,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
|||||||
def edit
|
def edit
|
||||||
@admins = Administrator.includes(:user).all
|
@admins = Administrator.includes(:user).all
|
||||||
@valuators = Valuator.includes(:user).all.order("users.username ASC")
|
@valuators = Valuator.includes(:user).all.order("users.username ASC")
|
||||||
@tags = ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings)
|
@tags = ActsAsTaggableOn::Tag.spending_proposal_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|||||||
6
app/helpers/spending_proposals_helper.rb
Normal file
6
app/helpers/spending_proposals_helper.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
module SpendingProposalsHelper
|
||||||
|
|
||||||
|
def spending_proposal_tags_select_options
|
||||||
|
ActsAsTaggableOn::Tag.spending_proposal_tags.pluck(:name)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -35,6 +35,7 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
results = self
|
results = self
|
||||||
results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present?
|
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.by_administrator(params[:administrator_id]) if params[:administrator_id].present?
|
||||||
|
results = results.by_tag(params[:tag_name]) if params[:tag_name].present?
|
||||||
results = results.send(current_filter) if current_filter.present?
|
results = results.send(current_filter) if current_filter.present?
|
||||||
results.for_render
|
results.for_render
|
||||||
end
|
end
|
||||||
@@ -51,6 +52,10 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
where(administrator_id: administrator.presence)
|
where(administrator_id: administrator.presence)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.by_tag(tag_name)
|
||||||
|
tagged_with(tag_name)
|
||||||
|
end
|
||||||
|
|
||||||
def feasibility
|
def feasibility
|
||||||
case feasible
|
case feasible
|
||||||
when true
|
when true
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
<div>
|
<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 %>
|
||||||
|
<div class="small-12 medium-4 column float-right">
|
||||||
|
<%= select_tag :tag_name,
|
||||||
|
options_for_select(spending_proposal_tags_select_options, params[:tag_name]),
|
||||||
|
{ prompt: t("admin.spending_proposals.index.tags_filter_all"),
|
||||||
|
label: false,
|
||||||
|
class: "js-submit-on-change" } %>
|
||||||
|
</div>
|
||||||
<div class="small-12 medium-4 column float-right">
|
<div class="small-12 medium-4 column float-right">
|
||||||
<%= select_tag :geozone_id,
|
<%= select_tag :geozone_id,
|
||||||
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]),
|
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]),
|
||||||
@@ -25,7 +32,7 @@
|
|||||||
|
|
||||||
<table>
|
<table>
|
||||||
<% @spending_proposals.each do |spending_proposal| %>
|
<% @spending_proposals.each do |spending_proposal| %>
|
||||||
<tr id="<%= dom_id(spending_proposal) %>">
|
<tr id="<%= dom_id(spending_proposal) %>" class="spending_proposal">
|
||||||
<td>
|
<td>
|
||||||
<strong><%= spending_proposal.id %></strong>
|
<strong><%= spending_proposal.id %></strong>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ module ActsAsTaggableOn
|
|||||||
Tag.where("kind = 'category'").pluck(:name)
|
Tag.where("kind = 'category'").pluck(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.spending_proposal_tags
|
||||||
|
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).uniq
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def custom_counter_field_name_for(taggable_type)
|
def custom_counter_field_name_for(taggable_type)
|
||||||
"#{taggable_type.underscore.pluralize}_count"
|
"#{taggable_type.underscore.pluralize}_count"
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ en:
|
|||||||
index:
|
index:
|
||||||
geozone_filter_all: All zones
|
geozone_filter_all: All zones
|
||||||
administrator_filter_all: All administrators
|
administrator_filter_all: All administrators
|
||||||
|
tags_filter_all: All tags
|
||||||
filters:
|
filters:
|
||||||
valuation_open: Open
|
valuation_open: Open
|
||||||
without_admin: Without assigned admin
|
without_admin: Without assigned admin
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ es:
|
|||||||
index:
|
index:
|
||||||
geozone_filter_all: Todos los ámbitos de actuación
|
geozone_filter_all: Todos los ámbitos de actuación
|
||||||
administrator_filter_all: Todos los administradores
|
administrator_filter_all: Todos los administradores
|
||||||
|
tags_filter_all: Todas las etiquetas
|
||||||
filters:
|
filters:
|
||||||
valuation_open: Abiertas
|
valuation_open: Abiertas
|
||||||
without_admin: Sin administrador asignado
|
without_admin: Sin administrador asignado
|
||||||
|
|||||||
@@ -162,6 +162,26 @@ feature 'Admin spending proposals' do
|
|||||||
expect(page).to have_content("Old idea")
|
expect(page).to have_content("Old idea")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Index filtering by tag" do
|
||||||
|
create(:spending_proposal, title: 'Educate the children', tag_list: 'Education')
|
||||||
|
create(:spending_proposal, title: 'More schools', tag_list: 'Education')
|
||||||
|
create(:spending_proposal, title: 'More hospitals', tag_list: 'Health')
|
||||||
|
|
||||||
|
visit admin_spending_proposals_path
|
||||||
|
|
||||||
|
expect(page).to have_css(".spending_proposal", 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_spending_proposals_path(tag_name: 'Education')
|
||||||
|
|
||||||
|
expect(page).to have_css(".spending_proposal", count: 2)
|
||||||
|
expect(page).to have_content("Educate the children")
|
||||||
|
expect(page).to have_content("More schools")
|
||||||
|
expect(page).to_not have_content("More hospitals")
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Show' do
|
scenario 'Show' do
|
||||||
administrator = create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org'))
|
administrator = create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org'))
|
||||||
valuator = create(:valuator, user: create(:user, username: 'Rachel', email: 'rachel@valuators.org'))
|
valuator = create(:valuator, user: create(:user, username: 'Rachel', email: 'rachel@valuators.org'))
|
||||||
|
|||||||
Reference in New Issue
Block a user