adds filtering of tags for spending proposals
This commit is contained in:
@@ -16,7 +16,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
||||
def edit
|
||||
@admins = Administrator.includes(:user).all
|
||||
@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
|
||||
|
||||
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 = 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_tag(params[:tag_name]) if params[:tag_name].present?
|
||||
results = results.send(current_filter) if current_filter.present?
|
||||
results.for_render
|
||||
end
|
||||
@@ -51,6 +52,10 @@ class SpendingProposal < ActiveRecord::Base
|
||||
where(administrator_id: administrator.presence)
|
||||
end
|
||||
|
||||
def self.by_tag(tag_name)
|
||||
tagged_with(tag_name)
|
||||
end
|
||||
|
||||
def feasibility
|
||||
case feasible
|
||||
when true
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
<div>
|
||||
<%= 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">
|
||||
<%= select_tag :geozone_id,
|
||||
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]),
|
||||
@@ -25,7 +32,7 @@
|
||||
|
||||
<table>
|
||||
<% @spending_proposals.each do |spending_proposal| %>
|
||||
<tr id="<%= dom_id(spending_proposal) %>">
|
||||
<tr id="<%= dom_id(spending_proposal) %>" class="spending_proposal">
|
||||
<td>
|
||||
<strong><%= spending_proposal.id %></strong>
|
||||
</td>
|
||||
|
||||
@@ -38,6 +38,10 @@ module ActsAsTaggableOn
|
||||
Tag.where("kind = 'category'").pluck(:name)
|
||||
end
|
||||
|
||||
def self.spending_proposal_tags
|
||||
ActsAsTaggableOn::Tag.where('taggings.taggable_type' => 'SpendingProposal').includes(:taggings).uniq
|
||||
end
|
||||
|
||||
private
|
||||
def custom_counter_field_name_for(taggable_type)
|
||||
"#{taggable_type.underscore.pluralize}_count"
|
||||
|
||||
@@ -150,6 +150,7 @@ en:
|
||||
index:
|
||||
geozone_filter_all: All zones
|
||||
administrator_filter_all: All administrators
|
||||
tags_filter_all: All tags
|
||||
filters:
|
||||
valuation_open: Open
|
||||
without_admin: Without assigned admin
|
||||
|
||||
@@ -150,6 +150,7 @@ es:
|
||||
index:
|
||||
geozone_filter_all: Todos los ámbitos de actuación
|
||||
administrator_filter_all: Todos los administradores
|
||||
tags_filter_all: Todas las etiquetas
|
||||
filters:
|
||||
valuation_open: Abiertas
|
||||
without_admin: Sin administrador asignado
|
||||
|
||||
@@ -162,6 +162,26 @@ feature 'Admin spending proposals' do
|
||||
expect(page).to have_content("Old idea")
|
||||
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
|
||||
administrator = create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org'))
|
||||
valuator = create(:valuator, user: create(:user, username: 'Rachel', email: 'rachel@valuators.org'))
|
||||
|
||||
Reference in New Issue
Block a user