Add goal filter to advanced search
This commit is contained in:
7
app/components/concerns/sdg/goals/options_for_select.rb
Normal file
7
app/components/concerns/sdg/goals/options_for_select.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
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
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
||||||
include Header
|
include Header
|
||||||
|
include SDG::Goals::OptionsForSelect
|
||||||
|
|
||||||
attr_reader :records
|
attr_reader :records
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def goal_options
|
def goal_options
|
||||||
options_from_collection_for_select(SDG::Goal.order(:code), :code, :code_and_title, params[:goal_code])
|
super(params[:goal_code])
|
||||||
end
|
end
|
||||||
|
|
||||||
def target_options
|
def target_options
|
||||||
|
|||||||
@@ -20,6 +20,14 @@
|
|||||||
include_blank: t("shared.advanced_search.author_type_blank")) %>
|
include_blank: t("shared.advanced_search.author_type_blank")) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if sdg? %>
|
||||||
|
<div class="filter">
|
||||||
|
<label for="advanced_search_goal"><%= t("shared.advanced_search.goal") %></label>
|
||||||
|
<%= select_tag("advanced_search[goal]", goal_options,
|
||||||
|
include_blank: t("shared.advanced_search.goal_blank")) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="date-filters">
|
<div class="date-filters">
|
||||||
<div class="filter">
|
<div class="filter">
|
||||||
<label for="js-advanced-search-date-min"><%= t("shared.advanced_search.date") %></label>
|
<label for="js-advanced-search-date-min"><%= t("shared.advanced_search.date") %></label>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class Shared::AdvancedSearchComponent < ApplicationComponent
|
class Shared::AdvancedSearchComponent < ApplicationComponent
|
||||||
|
include SDG::Goals::OptionsForSelect
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@@ -28,4 +29,12 @@ class Shared::AdvancedSearchComponent < ApplicationComponent
|
|||||||
def custom_date_range?
|
def custom_date_range?
|
||||||
advanced_search[:date_max].present?
|
advanced_search[:date_max].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def goal_options
|
||||||
|
super(advanced_search[:goal])
|
||||||
|
end
|
||||||
|
|
||||||
|
def sdg?
|
||||||
|
SDG::ProcessEnabled.new(controller_path).enabled?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,13 +21,21 @@ class SDG::ProcessEnabled
|
|||||||
private
|
private
|
||||||
|
|
||||||
def process_name
|
def process_name
|
||||||
if module_name == "Legislation"
|
if controller_path_name?
|
||||||
"legislation"
|
name.split("/").first
|
||||||
else
|
else
|
||||||
module_name.constantize.table_name
|
if module_name == "Legislation"
|
||||||
|
"legislation"
|
||||||
|
else
|
||||||
|
module_name.constantize.table_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def controller_path_name?
|
||||||
|
name == name.downcase
|
||||||
|
end
|
||||||
|
|
||||||
def module_name
|
def module_name
|
||||||
name.split("::").first
|
name.split("::").first
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -694,6 +694,8 @@ en:
|
|||||||
from: "From"
|
from: "From"
|
||||||
general: "With the text"
|
general: "With the text"
|
||||||
general_placeholder: "Write the text"
|
general_placeholder: "Write the text"
|
||||||
|
goal: "By SDG"
|
||||||
|
goal_blank: "Select a goal"
|
||||||
search: "Filter"
|
search: "Filter"
|
||||||
title: "Advanced search"
|
title: "Advanced search"
|
||||||
to: "To"
|
to: "To"
|
||||||
|
|||||||
@@ -694,6 +694,8 @@ es:
|
|||||||
from: "Desde"
|
from: "Desde"
|
||||||
general: "Con el texto"
|
general: "Con el texto"
|
||||||
general_placeholder: "Escribe el texto"
|
general_placeholder: "Escribe el texto"
|
||||||
|
goal: "Por ODS"
|
||||||
|
goal_blank: "Elige un objetivo"
|
||||||
search: "Filtrar"
|
search: "Filtrar"
|
||||||
title: "Búsqueda avanzada"
|
title: "Búsqueda avanzada"
|
||||||
to: "Hasta"
|
to: "Hasta"
|
||||||
|
|||||||
36
spec/components/shared/advanced_search_component_spec.rb
Normal file
36
spec/components/shared/advanced_search_component_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Shared::AdvancedSearchComponent, type: :component do
|
||||||
|
describe "SDG filter" do
|
||||||
|
let(:component) { Shared::AdvancedSearchComponent.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Setting["feature.sdg"] = true
|
||||||
|
Setting["sdg.process.proposals"] = true
|
||||||
|
|
||||||
|
allow(component).to receive(:controller_path).and_return("proposals")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not render when the feature is disabled" do
|
||||||
|
Setting["feature.sdg"] = false
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not render when the SDG process feature is disabled" do
|
||||||
|
Setting["sdg.process.proposals"] = false
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders when both features are enabled" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_selector "#advanced_search_goal", visible: :all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -3,6 +3,8 @@ require "rails_helper"
|
|||||||
describe "SDG Goals", :js do
|
describe "SDG Goals", :js do
|
||||||
before do
|
before do
|
||||||
Setting["feature.sdg"] = true
|
Setting["feature.sdg"] = true
|
||||||
|
Setting["sdg.process.debates"] = true
|
||||||
|
Setting["sdg.process.proposals"] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "SDG navigation link" do
|
describe "SDG navigation link" do
|
||||||
@@ -75,6 +77,10 @@ describe "SDG Goals", :js do
|
|||||||
expect(page).not_to have_content "Solar panels"
|
expect(page).not_to have_content "Solar panels"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
within "#advanced_search_form" do
|
||||||
|
expect(page).to have_select "By SDG", selected: "15. Life on Land"
|
||||||
|
end
|
||||||
|
|
||||||
go_back
|
go_back
|
||||||
|
|
||||||
click_link "See all proposals"
|
click_link "See all proposals"
|
||||||
@@ -83,6 +89,10 @@ describe "SDG Goals", :js do
|
|||||||
expect(page).to have_content "Animal farm"
|
expect(page).to have_content "Animal farm"
|
||||||
expect(page).not_to have_content "Sea farm"
|
expect(page).not_to have_content "Sea farm"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
within "#advanced_search_form" do
|
||||||
|
expect(page).to have_select "By SDG", selected: "15. Life on Land"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user