Extract advanced search into a component
This commit is contained in:
30
app/assets/stylesheets/advanced_search.scss
Normal file
30
app/assets/stylesheets/advanced_search.scss
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
.advanced-search {
|
||||||
|
float: left;
|
||||||
|
margin: $line-height 0;
|
||||||
|
position: inherit;
|
||||||
|
|
||||||
|
@include breakpoint(medium) {
|
||||||
|
float: right;
|
||||||
|
margin-bottom: 0;
|
||||||
|
margin-top: $line-height / 4;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-search-form {
|
||||||
|
|
||||||
|
@include breakpoint(medium) {
|
||||||
|
> .column {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
height: $line-height * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.column.end.clear {
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
@import "icons";
|
@import "icons";
|
||||||
@import "mixins";
|
@import "mixins";
|
||||||
@import "admin";
|
@import "admin";
|
||||||
|
@import "advanced_search";
|
||||||
@import "layout";
|
@import "layout";
|
||||||
@import "participation";
|
@import "participation";
|
||||||
@import "milestones";
|
@import "milestones";
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// 06. Forms
|
// 06. Forms
|
||||||
// 07. Callout
|
// 07. Callout
|
||||||
// 08. User account
|
// 08. User account
|
||||||
// 09. Search
|
|
||||||
// 10. Official levels
|
// 10. Official levels
|
||||||
// 11. Tables
|
// 11. Tables
|
||||||
// 12. Social
|
// 12. Social
|
||||||
@@ -1480,40 +1479,6 @@ form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 09. Search
|
|
||||||
// ----------
|
|
||||||
|
|
||||||
.advanced-search {
|
|
||||||
float: left;
|
|
||||||
margin: $line-height 0;
|
|
||||||
position: inherit;
|
|
||||||
|
|
||||||
@include breakpoint(medium) {
|
|
||||||
float: right;
|
|
||||||
margin-bottom: 0;
|
|
||||||
margin-top: $line-height / 4;
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.advanced-search-form {
|
|
||||||
|
|
||||||
@include breakpoint(medium) {
|
|
||||||
> .column {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
height: $line-height * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.column.end.clear {
|
|
||||||
clear: both;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 10. Officials levels
|
// 10. Officials levels
|
||||||
// --------------------
|
// --------------------
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<div class="row advanced-search-form">
|
<div class="row advanced-search-form">
|
||||||
<%= form_tag request.path, id: "advanced_search_form", method: :get do %>
|
<%= form_tag request.path, id: "advanced_search_form", method: :get do %>
|
||||||
<div id="js-advanced-search" data-advanced-search-terms="<%= @advanced_search_terms.present? %>" style="display: none">
|
<div id="js-advanced-search" data-advanced-search-terms="<%= advanced_search.present? %>" style="display: none">
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<label for="search">
|
<label for="search">
|
||||||
31
app/components/shared/advanced_search_component.rb
Normal file
31
app/components/shared/advanced_search_component.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
class Shared::AdvancedSearchComponent < ApplicationComponent
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def advanced_search
|
||||||
|
params[:advanced_search]
|
||||||
|
end
|
||||||
|
|
||||||
|
def official_level_search_options
|
||||||
|
options_for_select((1..5).map { |i| [setting["official_level_#{i}_name"], i] },
|
||||||
|
params[:advanced_search].try(:[], :official_level))
|
||||||
|
end
|
||||||
|
|
||||||
|
def date_range_options
|
||||||
|
options_for_select([
|
||||||
|
[t("shared.advanced_search.date_1"), 1],
|
||||||
|
[t("shared.advanced_search.date_2"), 2],
|
||||||
|
[t("shared.advanced_search.date_3"), 3],
|
||||||
|
[t("shared.advanced_search.date_4"), 4],
|
||||||
|
[t("shared.advanced_search.date_5"), "custom"]],
|
||||||
|
selected_date_range)
|
||||||
|
end
|
||||||
|
|
||||||
|
def selected_date_range
|
||||||
|
custom_date_range? ? "custom" : params[:advanced_search].try(:[], :date_min)
|
||||||
|
end
|
||||||
|
|
||||||
|
def custom_date_range?
|
||||||
|
params[:advanced_search].try(:[], :date_max).present?
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
module SearchHelper
|
|
||||||
def official_level_search_options
|
|
||||||
options_for_select((1..5).map { |i| [setting["official_level_#{i}_name"], i] },
|
|
||||||
params[:advanced_search].try(:[], :official_level))
|
|
||||||
end
|
|
||||||
|
|
||||||
def date_range_options
|
|
||||||
options_for_select([
|
|
||||||
[t("shared.advanced_search.date_1"), 1],
|
|
||||||
[t("shared.advanced_search.date_2"), 2],
|
|
||||||
[t("shared.advanced_search.date_3"), 3],
|
|
||||||
[t("shared.advanced_search.date_4"), 4],
|
|
||||||
[t("shared.advanced_search.date_5"), "custom"]],
|
|
||||||
selected_date_range)
|
|
||||||
end
|
|
||||||
|
|
||||||
def selected_date_range
|
|
||||||
custom_date_range? ? "custom" : params[:advanced_search].try(:[], :date_min)
|
|
||||||
end
|
|
||||||
|
|
||||||
def custom_date_range?
|
|
||||||
params[:advanced_search].try(:[], :date_max).present?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render("shared/advanced_search") %>
|
<%= render Shared::AdvancedSearchComponent.new %>
|
||||||
|
|
||||||
<% if unfeasible_or_unselected_filter %>
|
<% if unfeasible_or_unselected_filter %>
|
||||||
<ul class="no-bullet submenu">
|
<ul class="no-bullet submenu">
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render "shared/advanced_search" %>
|
<%= render Shared::AdvancedSearchComponent.new %>
|
||||||
|
|
||||||
<%= render "shared/order_links", i18n_namespace: "debates.index" %>
|
<%= render "shared/order_links", i18n_namespace: "debates.index" %>
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% unless params[:retired].present? || params[:selected].present? %>
|
<% unless params[:retired].present? || params[:selected].present? %>
|
||||||
<%= render "shared/advanced_search" %>
|
<%= render Shared::AdvancedSearchComponent.new %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% unless params[:selected].present? %>
|
<% unless params[:selected].present? %>
|
||||||
|
|||||||
Reference in New Issue
Block a user