Add SDG target filter to advanced search
This commit is contained in:
@@ -22,10 +22,10 @@
|
|||||||
|
|
||||||
.date-filters {
|
.date-filters {
|
||||||
float: left;
|
float: left;
|
||||||
width: 50%;
|
width: 25%;
|
||||||
|
|
||||||
.filter {
|
.filter {
|
||||||
width: 50%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-date-filters {
|
.custom-date-filters {
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
module SDG::Goals::OptionsForSelect
|
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
def goal_options(selected_code = nil)
|
|
||||||
options_from_collection_for_select(SDG::Goal.order(:code), :code, :code_and_title, selected_code)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
13
app/components/concerns/sdg/options_for_select.rb
Normal file
13
app/components/concerns/sdg/options_for_select.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module SDG::OptionsForSelect
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
def goal_options(selected_code = nil)
|
||||||
|
options_from_collection_for_select(SDG::Goal.order(:code), :code, :code_and_title, selected_code)
|
||||||
|
end
|
||||||
|
|
||||||
|
def target_options(selected_code = nil)
|
||||||
|
targets = SDG::Target.all + SDG::LocalTarget.all
|
||||||
|
|
||||||
|
options_from_collection_for_select(targets.sort, :code, :code, selected_code)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
||||||
include Header
|
include Header
|
||||||
include SDG::Goals::OptionsForSelect
|
include SDG::OptionsForSelect
|
||||||
delegate :valid_filters, :current_filter, to: :helpers
|
delegate :valid_filters, :current_filter, to: :helpers
|
||||||
|
|
||||||
attr_reader :records
|
attr_reader :records
|
||||||
@@ -53,8 +53,6 @@ class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def target_options
|
def target_options
|
||||||
targets = SDG::Target.all + SDG::LocalTarget.all
|
super(params[:target_code])
|
||||||
|
|
||||||
options_from_collection_for_select(targets.sort, :code, :code, params[:target_code])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,6 +26,11 @@
|
|||||||
<%= select_tag("advanced_search[goal]", goal_options,
|
<%= select_tag("advanced_search[goal]", goal_options,
|
||||||
include_blank: t("shared.advanced_search.goal_blank")) %>
|
include_blank: t("shared.advanced_search.goal_blank")) %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="filter">
|
||||||
|
<label for="advanced_search_target"><%= t("shared.advanced_search.target") %></label>
|
||||||
|
<%= select_tag("advanced_search[target]", target_options,
|
||||||
|
include_blank: t("shared.advanced_search.target_blank")) %>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="date-filters">
|
<div class="date-filters">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Shared::AdvancedSearchComponent < ApplicationComponent
|
class Shared::AdvancedSearchComponent < ApplicationComponent
|
||||||
include SDG::Goals::OptionsForSelect
|
include SDG::OptionsForSelect
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@@ -34,6 +34,10 @@ class Shared::AdvancedSearchComponent < ApplicationComponent
|
|||||||
super(advanced_search[:goal])
|
super(advanced_search[:goal])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def target_options
|
||||||
|
super(advanced_search[:target])
|
||||||
|
end
|
||||||
|
|
||||||
def sdg?
|
def sdg?
|
||||||
SDG::ProcessEnabled.new(controller_path).enabled?
|
SDG::ProcessEnabled.new(controller_path).enabled?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module Filterable
|
|||||||
def allowed_filter?(filter, value)
|
def allowed_filter?(filter, value)
|
||||||
return if value.blank?
|
return if value.blank?
|
||||||
|
|
||||||
["official_level", "date_range", "goal"].include?(filter)
|
["official_level", "date_range", "goal", "target"].include?(filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -697,6 +697,8 @@ en:
|
|||||||
goal: "By SDG"
|
goal: "By SDG"
|
||||||
goal_blank: "Select a goal"
|
goal_blank: "Select a goal"
|
||||||
search: "Filter"
|
search: "Filter"
|
||||||
|
target: "By target"
|
||||||
|
target_blank: "Select a target"
|
||||||
title: "Advanced search"
|
title: "Advanced search"
|
||||||
to: "To"
|
to: "To"
|
||||||
author_info:
|
author_info:
|
||||||
|
|||||||
@@ -697,6 +697,8 @@ es:
|
|||||||
goal: "Por ODS"
|
goal: "Por ODS"
|
||||||
goal_blank: "Elige un objetivo"
|
goal_blank: "Elige un objetivo"
|
||||||
search: "Filtrar"
|
search: "Filtrar"
|
||||||
|
target: "Por meta"
|
||||||
|
target_blank: "Elige una meta"
|
||||||
title: "Búsqueda avanzada"
|
title: "Búsqueda avanzada"
|
||||||
to: "Hasta"
|
to: "Hasta"
|
||||||
author_info:
|
author_info:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ describe Shared::AdvancedSearchComponent, type: :component do
|
|||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
||||||
|
expect(page).not_to have_selector "#advanced_search_target", visible: :all
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render when the SDG process feature is disabled" do
|
it "does not render when the SDG process feature is disabled" do
|
||||||
@@ -25,12 +26,14 @@ describe Shared::AdvancedSearchComponent, type: :component do
|
|||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
||||||
|
expect(page).not_to have_selector "#advanced_search_target", visible: :all
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders when both features are enabled" do
|
it "renders when both features are enabled" do
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).to have_selector "#advanced_search_goal", visible: :all
|
expect(page).to have_selector "#advanced_search_goal", visible: :all
|
||||||
|
expect(page).to have_selector "#advanced_search_target", visible: :all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -500,6 +500,27 @@ describe "Budget Investments" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Search by SDG target", :js do
|
||||||
|
Setting["feature.sdg"] = true
|
||||||
|
Setting["sdg.process.budgets"] = true
|
||||||
|
create(:budget_investment, heading: heading, title: "Unrelated")
|
||||||
|
create(:budget_investment, heading: heading, title: "High school", sdg_targets: [SDG::Target["4.1"]])
|
||||||
|
create(:budget_investment, heading: heading, title: "Preschool", sdg_targets: [SDG::Target["4.2"]])
|
||||||
|
|
||||||
|
visit budget_investments_path(budget)
|
||||||
|
click_link "Advanced search"
|
||||||
|
select "4.2", from: "By target"
|
||||||
|
click_button "Filter"
|
||||||
|
|
||||||
|
expect(page).to have_content("There is 1 investment")
|
||||||
|
|
||||||
|
within("#budget-investments") do
|
||||||
|
expect(page).to have_content("Preschool")
|
||||||
|
expect(page).not_to have_content("High school")
|
||||||
|
expect(page).not_to have_content("Unrelated")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context("Filters") do
|
context("Filters") do
|
||||||
|
|||||||
@@ -866,6 +866,27 @@ describe "Debates" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Search by SDG target", :js do
|
||||||
|
Setting["feature.sdg"] = true
|
||||||
|
Setting["sdg.process.debates"] = true
|
||||||
|
create(:debate, title: "Unrelated")
|
||||||
|
create(:debate, title: "High school", sdg_targets: [SDG::Target["4.1"]])
|
||||||
|
create(:debate, title: "Preschool", sdg_targets: [SDG::Target["4.2"]])
|
||||||
|
|
||||||
|
visit debates_path
|
||||||
|
click_link "Advanced search"
|
||||||
|
select "4.2", from: "By target"
|
||||||
|
click_button "Filter"
|
||||||
|
|
||||||
|
expect(page).to have_content("There is 1 debate")
|
||||||
|
|
||||||
|
within("#debates") do
|
||||||
|
expect(page).to have_content("Preschool")
|
||||||
|
expect(page).not_to have_content("High school")
|
||||||
|
expect(page).not_to have_content("Unrelated")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Order by relevance by default", :js do
|
scenario "Order by relevance by default", :js do
|
||||||
|
|||||||
@@ -1482,6 +1482,27 @@ describe "Proposals" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Search by SDG target", :js do
|
||||||
|
Setting["feature.sdg"] = true
|
||||||
|
Setting["sdg.process.proposals"] = true
|
||||||
|
create(:proposal, title: "Unrelated")
|
||||||
|
create(:proposal, title: "High school", sdg_targets: [SDG::Target["4.1"]])
|
||||||
|
create(:proposal, title: "Preschool", sdg_targets: [SDG::Target["4.2"]])
|
||||||
|
|
||||||
|
visit proposals_path
|
||||||
|
click_link "Advanced search"
|
||||||
|
select "4.2", from: "By target"
|
||||||
|
click_button "Filter"
|
||||||
|
|
||||||
|
expect(page).to have_content("There is 1 citizen proposal")
|
||||||
|
|
||||||
|
within("#proposals") do
|
||||||
|
expect(page).to have_content("Preschool")
|
||||||
|
expect(page).not_to have_content("High school")
|
||||||
|
expect(page).not_to have_content("Unrelated")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Order by relevance by default", :js do
|
scenario "Order by relevance by default", :js do
|
||||||
|
|||||||
Reference in New Issue
Block a user