maintains search criteria

This commit is contained in:
rgarcia
2016-01-13 18:56:53 +01:00
parent afca5c2b90
commit c68c2b9f1d
7 changed files with 125 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ App.AdvancedSearch =
initialize: ->
if App.AdvancedSearch.advanced_search_terms()
$('#advanced-search').show()
App.AdvancedSearch.toggle_date_options()
$('.advanced-search-title').on
click: ->

View File

@@ -91,8 +91,8 @@ module CommentableActions
def parse_search_date
return unless search_by_date?
start = params[:advanced_search][:date_min].to_time
finish = params[:advanced_search][:date_max].try(:to_time) || Time.now
start = eval(params[:advanced_search][:date_min].inspect).to_time
finish = params[:advanced_search][:date_max].try(:to_time) || Date.today
params[:advanced_search][:date_range] = start.beginning_of_day..finish.end_of_day
end

View File

@@ -7,17 +7,25 @@ module SearchHelper
[t("shared.advanced_search.author_type_3"), 3],
[t("shared.advanced_search.author_type_4"), 4],
[t("shared.advanced_search.author_type_5"), 5]],
params[:official_level])
params[:advanced_search].try(:[], :official_level))
end
def date_range_options
options_for_select([
[t("shared.advanced_search.date_1"), 24.hours.ago],
[t("shared.advanced_search.date_2"), 7.days.ago],
[t("shared.advanced_search.date_3"), 30.days.ago],
[t("shared.advanced_search.date_4"), 365.days.ago],
[t("shared.advanced_search.date_1"), "24.hours.ago"],
[t("shared.advanced_search.date_2"), "1.week.ago"],
[t("shared.advanced_search.date_3"), "1.month.ago"],
[t("shared.advanced_search.date_4"), "1.year.ago"],
[t("shared.advanced_search.date_5"), 'custom']],
params[:date_range])
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

View File

@@ -9,13 +9,13 @@
<div class="small-12 medium-12 advanced-search columns">
<h5 class='search-option inline-block'><%= t("shared.advanced_search.general") %></h5>
<%= text_field_tag "search", @search_terms,
<%= text_field_tag "search", params[:search],
placeholder: t("shared.advanced_search.general_placeholder") %>
</div>
<div class="small-12 medium-6 advanced-search columns">
<h5 class='search-option inline-block'><%= t("shared.advanced_search.author") %></h5>
<%= text_field_tag "advanced_search[author]", @params_author,
<%= text_field_tag "advanced_search[author]", params[:advanced_search].try(:[], :author),
placeholder: t("shared.advanced_search.author_placeholder") %>
</div>
@@ -34,12 +34,14 @@
&nbsp;&nbsp;
<%= t("shared.advanced_search.from") %>:
<div class='inline-block'>
<%= date_field 'advanced_search', 'date_min', max: Date.today, value: @params_date_min %>
<%= date_field 'advanced_search', 'date_min', max: Date.today,
value: params[:advanced_search].try(:[], :date_min) %>
</div>
&nbsp;&nbsp;
<%= t("shared.advanced_search.to") %>:
<div class='inline-block'>
<%= date_field 'advanced_search', 'date_max', max: Date.today, value: @params_date_max %>
<%= date_field 'advanced_search', 'date_max', max: Date.today,
value: params[:advanced_search].try(:[], :date_max) %>
</div>
</div>
</div>

View File

@@ -5,8 +5,8 @@
<div class="small-12 column">
<div class="row collapse">
<div class="small-10 column">
<label for="search-form-header" class="sr-only"><%= t("#{i18n_namespace}.title") %></label>
<input type="text" id="search-form-header" name="search" placeholder="<%= t("#{i18n_namespace}.placeholder") %>" class="search-form">
<label class="sr-only"><%= t("#{i18n_namespace}.title") %></label>
<input type="text" name="search" placeholder="<%= t("#{i18n_namespace}.placeholder") %>" class="search-form" value="<%= params[:search] %>">
</div>
<div class="small-2 column">
<button type="submit" class="button postfix" title="<%= t("#{i18n_namespace}.button") %>">

View File

@@ -452,7 +452,7 @@ feature 'Debates' do
end
end
context "Search", :focus do
context "Search" do
context "Basic search" do
@@ -477,11 +477,22 @@ feature 'Debates' do
end
end
scenario "Maintain search criteria" do
visit debates_path
within "#search_form" do
fill_in "search", with: "Schwifty"
click_button "Search"
end
expect(page).to have_selector("input[name='search'][value='Schwifty']")
end
end
context "Advanced search" do
scenario "Search by text", :js, :focus do
scenario "Search by text", :js do
debate1 = create(:debate, title: "Get Schwifty")
debate2 = create(:debate, title: "Schwifty Hello")
debate3 = create(:debate, title: "Do not show me")
@@ -593,6 +604,43 @@ feature 'Debates' do
end
end
scenario "Maintain advanced search criteria", :js do
visit debates_path
find("h4.advanced-search-title").click
### Pending fix when searching for text and another criteria
#fill_in "Write the text", with: "Schwifty"
###
fill_in "Write the author name", with: "Ana06"
select "Public employee", from: "advanced_search_official_level"
select "Last 24 hours", from: "advanced_search_date_min"
click_button "Filter"
within "#advanced-search" do
###expect(page).to have_selector("input[name='search'][value='Schwifty']")
expect(page).to have_selector("input[name='advanced_search[author]'][value='Ana06']")
expect(page).to have_select('advanced_search[official_level]', selected: 'Public employee')
expect(page).to have_select('advanced_search[date_min]', selected: 'Last 24 hours')
end
end
scenario "Maintain custom date search criteria", :js do
visit debates_path
find("h4.advanced-search-title").click
select "Customized", from: "advanced_search_date_min"
fill_in "advanced_search_date_min", with: 7.days.ago
fill_in "advanced_search_date_max", with: 1.days.ago
click_button "Filter"
within "#advanced-search" do
expect(page).to have_select('advanced_search[date_min]', selected: 'Customized')
expect(page).to have_selector("input[name='advanced_search[date_min]'][value*='#{7.days.ago.strftime('%Y-%m-%d')}']")
expect(page).to have_selector("input[name='advanced_search[date_max]'][value*='#{1.day.ago.strftime('%Y-%m-%d')}']")
end
end
end
end

View File

@@ -515,7 +515,7 @@ feature 'Proposals' do
end
end
context "Search", :focus do
context "Search" do
context "Basic search" do
@@ -540,11 +540,22 @@ feature 'Proposals' do
end
end
scenario "Maintain search criteria" do
visit proposals_path
within "#search_form" do
fill_in "search", with: "Schwifty"
click_button "Search"
end
expect(page).to have_selector("input[name='search'][value='Schwifty']")
end
end
context "Advanced search" do
scenario "Search by text", :js, :focus do
scenario "Search by text", :js do
proposal1 = create(:proposal, title: "Get Schwifty")
proposal2 = create(:proposal, title: "Schwifty Hello")
proposal3 = create(:proposal, title: "Do not show me")
@@ -656,6 +667,43 @@ feature 'Proposals' do
end
end
scenario "Maintain advanced search criteria", :js do
visit proposals_path
find("h4.advanced-search-title").click
### Pending fix when searching for text and another criteria
#fill_in "Write the text", with: "Schwifty"
###
fill_in "Write the author name", with: "Ana06"
select "Public employee", from: "advanced_search_official_level"
select "Last 24 hours", from: "advanced_search_date_min"
click_button "Filter"
within "#advanced-search" do
###expect(page).to have_selector("input[name='search'][value='Schwifty']")
expect(page).to have_selector("input[name='advanced_search[author]'][value='Ana06']")
expect(page).to have_select('advanced_search[official_level]', selected: 'Public employee')
expect(page).to have_select('advanced_search[date_min]', selected: 'Last 24 hours')
end
end
scenario "Maintain custom date search criteria", :js do
visit proposals_path
find("h4.advanced-search-title").click
select "Customized", from: "advanced_search_date_min"
fill_in "advanced_search_date_min", with: 7.days.ago
fill_in "advanced_search_date_max", with: 1.days.ago
click_button "Filter"
within "#advanced-search" do
expect(page).to have_select('advanced_search[date_min]', selected: 'Customized')
expect(page).to have_selector("input[name='advanced_search[date_min]'][value*='#{7.days.ago.strftime('%Y-%m-%d')}']")
expect(page).to have_selector("input[name='advanced_search[date_max]'][value*='#{1.day.ago.strftime('%Y-%m-%d')}']")
end
end
end
end