diff --git a/app/assets/stylesheets/FreeUKGenealogy-Core-Frontend/styles/scss/generic/_helper.scss b/app/assets/stylesheets/FreeUKGenealogy-Core-Frontend/styles/scss/generic/_helper.scss index 42d82fb74..3ca61d7f6 100644 --- a/app/assets/stylesheets/FreeUKGenealogy-Core-Frontend/styles/scss/generic/_helper.scss +++ b/app/assets/stylesheets/FreeUKGenealogy-Core-Frontend/styles/scss/generic/_helper.scss @@ -63,3 +63,10 @@ } } } + +/** + * Add/remove margins + */ + .push--top40 { + margin-top: 40px; +} diff --git a/app/assets/stylesheets/styles/scss/lap_and_up.scss.erb b/app/assets/stylesheets/styles/scss/lap_and_up.scss.erb index d314b0d61..5a8befc50 100755 --- a/app/assets/stylesheets/styles/scss/lap_and_up.scss.erb +++ b/app/assets/stylesheets/styles/scss/lap_and_up.scss.erb @@ -279,8 +279,32 @@ th.sticky-header { box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.06); } +th.sticky-header-freereg { + position: -webkit-sticky; /* Safari */ + position: sticky; + background-color: white; + top: 0; + z-index: 10; + box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.06); +} + .table--striped{ tbody tr:nth-of-type(odd){ background-color:#f5f5f5;} } + +.table-scroll { + overflow-y: auto; /* make the table scrollable if height is more than 500 px */ + height: 500px; /* gives an initial height of 200px to the table */ +} + +.table-scroll thead th { + position: -webkit-sticky; /* Safari */ + position: sticky; /* make the table heads sticky */ + top: 0px; /* table head will be placed from the top of the table and sticks to it */ + background-color: $navy; + color: white; + z-index: 10; /* move header in forground */ + box-shadow: inset 0 2px 4px 0 rgba(0,0,0,0.06); +} diff --git a/app/controllers/search_queries_controller.rb b/app/controllers/search_queries_controller.rb index a838b4780..03399864a 100644 --- a/app/controllers/search_queries_controller.rb +++ b/app/controllers/search_queries_controller.rb @@ -210,22 +210,43 @@ def selection def show @search_query, proceed, message = SearchQuery.check_and_return_query(params[:id]) + set_sort_by + + @search_results, success, error_type = @search_query.search_records.to_a if params[:saved_search].present? redirect_back(fallback_location: new_search_query_path, notice: message) && return unless proceed - flash[:notice] = 'Your search results are not available. Please repeat your search' if @search_query.result_count.blank? - redirect_back(fallback_location: new_search_query_path) && return if @search_query.result_count.blank? - if @search_query.result_count >= FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS + if @search_query.result_count.blank? + flash[:notice] = 'Your search results are not available. Please repeat your search' + redirect_back(fallback_location: new_search_query_path) && return + end + + if appname_downcase == 'freebmd' + @max_result = FreeregOptionsConstants::MAXIMUM_NUMBER_OF_BMD_RESULTS + else + @max_result = FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS + end + @save_search_id = params[:saved_search] if params[:saved_search].present? + + if @search_query.result_count >= @max_result @result_count = @search_query.result_count @search_results = [] @ucf_results = [] else - response, @search_results, @ucf_results, @result_count = @search_query.get_and_sort_results_for_display - if !response || @search_results.nil? || @search_query.result_count.nil? - logger.warn("#{appname_upcase}:SEARCH_ERROR:search results no longer present for #{@search_query.id}") - flash[:notice] = 'Your search results are not available. Please repeat your search' - redirect_to(new_search_query_path(search_id: @search_query)) && return + if MyopicVicar::Application.config.template_set == 'freebmd' + response, @search_results, @ucf_results, @result_count = @search_query.get_bmd_search_results + else + response, @search_results, @ucf_results, @result_count = @search_query.get_and_sort_results_for_display end end + + set_filter_by + create_paginatable_array(query: @search_query, results: @search_results) + + if !response || @search_results.nil? || @search_query.result_count.nil? + logger.warn("#{appname_upcase}:SEARCH_ERROR:search results no longer present for #{@search_query.id}") + flash[:notice] = 'Your search results are not available. Please repeat your search' + redirect_to(new_search_query_path(search_id: @search_query)) && return + end end def show_print_version @@ -236,17 +257,27 @@ def show_print_version redirect_back(fallback_location: new_search_query_path) && return if @search_query.result_count.blank? @printable_format = true + if @search_query.result_count >= FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS @result_count = @search_query.result_count @search_results = [] @ucf_results = [] else - response, @search_results, @ucf_results, @result_count = @search_query.get_and_sort_results_for_display + + if MyopicVicar::Application.config.template_set == 'freebmd' + response, @search_results, @ucf_results, @result_count = @search_query.get_bmd_search_results + else + response, @search_results, @ucf_results, @result_count = @search_query.get_and_sort_results_for_display + end + + @paginatable_array = @search_results + if !response || @search_results.nil? || @search_query.result_count.nil? logger.warn("#{appname_upcase}:SEARCH_ERROR:search results no longer present for #{@search_query.id}") flash[:notice] = 'Your search results are not available. Please repeat your search' redirect_to(new_search_query_path(search_id: @search_query)) && return end + end render 'show', layout: false end @@ -268,7 +299,78 @@ def update private + + def assign_value(value, default) + value ||= default + value + end + + def create_paginatable_array(query:, results:) + @results_per_page = assign_value(params[:results_per_page], FreeregOptionsConstants::RESULTS_PER_PAGE) + @page = assign_value(params[:page], FreeregOptionsConstants::DEFAULT_PAGE) + @paginatable_array = query.paginate_results(results, @page, @results_per_page) + @paginatable_array + end + + def set_filter_by + if params[:filter_option].present? + if params[:filter_option] == 'Clear Filter' + params[:filter_option] = nil + else + @filter_condition = params[:filter_option] + case appname_downcase + when 'freereg' + freereg_filterby = { 'Baptism' => 'ba', + 'Marriage' => 'ma', + 'Burial' => 'bu'} + @reg_record_type = freereg_filterby[params[:filter_option]] + @search_results = filtered_results_freereg + + if @search_results.blank? + flash[:notice] = 'Your filter request found no records. Please select a different filter' + end + when 'freebmd' + @search_results = filtered_results if RecordType::BMD_RECORD_TYPE_ID.include?(@filter_condition.to_i) + end + end + end + end + + def set_sort_by + @sort_condition ||= 'Event Date' + if params[:sort_option].present? + @sort_condition = params[:sort_option] + case appname_downcase + when 'freereg' + freereg_sortby = { 'Person' => 'transcript_names', + 'Record Type' => 'record_type', + 'Event Date' => 'search_date', + 'County' => 'chapman_code', + 'Place' => 'location'} + order_field = freereg_sortby[params[:sort_option]] + when 'freebmd' + order_field = params[:sort_option] + end + set_sort_field_and_order(query: @search_query, condition: order_field) + end + end + + def filtered_results_freereg + @search_results.select { |r| r['record_type'] == @reg_record_type } + end + def search_params params.require(:search_query).permit! end + + def set_sort_field_and_order(query:, condition:) + if condition == query.order_field + # reverse the directions + query.order_asc = !query.order_asc unless params[:page].present? + else + query.order_field = condition + query.order_asc = true + end + query.save! + end end diff --git a/app/models/search_query.rb b/app/models/search_query.rb index cd5cab1b7..f93dcc900 100644 --- a/app/models/search_query.rb +++ b/app/models/search_query.rb @@ -904,41 +904,87 @@ def sort_results(results) case order_field when *selected_sort_fields order = order_field.to_sym - results.each do |rec| - end - results.sort! do |x, y| - if order_asc - (x[order] || '') <=> (y[order] || '') - else - (y[order] || '') <=> (x[order] || '') - end + # results.each do |rec| + # end + # results.sort! do |x, y| + # if order_asc + # (x[order] || '') <=> (y[order] || '') + # else + # (y[order] || '') <=> (x[order] || '') + # end + # end + + if order_asc + results.sort_by! { |r| [r[order].to_s, r[:search_date].to_s] } + else + results.sort_by! { |r| [r[order].to_s, r[:search_date].to_s] }.reverse! end + when SearchOrder::DATE + # if order_asc + # results.sort! { |x, y| (x[:search_date] || '') <=> (y[:search_date] || '') } + # else + # results.sort! { |x, y| (y[:search_date] || '') <=> (x[:search_date] || '') } + # end + if order_asc - results.sort! { |x, y| (x[:search_date] || '') <=> (y[:search_date] || '') } + results.sort_by! { |r| r[:search_date].to_s } # ascending order else - results.sort! { |x, y| (y[:search_date] || '') <=> (x[:search_date] || '') } + results.sort_by! { |r| [r[:search_date].to_s] }.reverse! # descending order end + when SearchOrder::LOCATION + # if order_asc + # results.sort! do |x, y| + # compare_location(x, y) + # end + # else + # results.sort! do |x, y| + # compare_location(y, x) # note the reverse order + # end + # end + if order_asc - results.sort! do |x, y| - compare_location(x, y) - end + results.sort_by! { |r| + [r[:location_names][0].to_s, + r[:location_names][1].to_s, + r[:location_names][2].to_s, + r[:search_date].to_s] + } else - results.sort! do |x, y| - compare_location(y, x) # note the reverse order - end + results.sort_by! { |r| + [r[:location_names][0].to_s, + r[:location_names][1].to_s, + r[:location_names][2].to_s, + r[:search_date].to_s] + }.reverse! end + when SearchOrder::NAME + # if order_asc + # results.sort! do |x, y| + # compare_name(x, y) + # end + # else + # results.sort! do |x, y| + # compare_name(y, x) # note the reverse order + # end + # end + if order_asc - results.sort! do |x, y| - compare_name(x, y) - end + results.sort_by! { |r| + [r[:transcript_names][0][:last_name].to_s, + r[:transcript_names][0][:first_name].to_s, + r[:search_date].to_s] + } else - results.sort! do |x, y| - compare_name(y, x) # note the reverse order - end + results.sort_by! { |r| + [r[:transcript_names][0][:last_name].to_s, + r[:transcript_names][0][:first_name].to_s, + r[:search_date].to_s] + }.reverse! end + end end results @@ -1044,6 +1090,14 @@ def wildcards_are_valid end end + # new method for new UI 2023-12-28 + def paginate_results(results,page_number,results_per_page) + page_number ||= DEFAULT_PAGE + results_per_page ||= RESULTS_PER_PAGE + total = results.count + Kaminari.paginate_array(results, total_count: total).page(page_number).per(results_per_page) + end + private def selected_sort_fields diff --git a/app/views/search_queries/_desktop_freereg.html.erb b/app/views/search_queries/_desktop_freereg.html.erb index 9ed9ef31c..e7fdeecdb 100644 --- a/app/views/search_queries/_desktop_freereg.html.erb +++ b/app/views/search_queries/_desktop_freereg.html.erb @@ -1,55 +1,68 @@ <% print_friendly = (defined?(@printable_format) && @printable_format) ? true : false %> + <% unless print_friendly %> - + <% end %> - - - - - + <% n = 0 %> <% search_results.each do |search_record| %> <% n = n + 1 %> - - <%= render partial: 'display_freereg_search_record_desktop', :locals => {:search_record => search_record, :print_friendly => print_friendly, :n => n}%> + + + <%= render partial: "display_freereg_search_record_desktop", + locals: { + search_record: search_record, + print_friendly: print_friendly, + n: n + } %> <% end %> + <% if ucf_results && ucf_results.length > 0 %> - + + <% ucf_results.each do |search_record| %> <% n = n + 1 %> - - <%= render partial: 'display_freereg_search_record_desktop', :locals => {:search_record => search_record, :print_friendly => print_friendly, :n => n}%> + + <%= render partial: "display_freereg_search_record_desktop", + locals: { + search_record: search_record, + print_friendly: print_friendly, + n: n + } %> <% end %> <% end %> -
DetailsDetails - <% unless print_friendly %><%= link_to('Person or persons', - reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::NAME)) %> - <% else%> Person or persons<% end%> + + Person or persons - <% unless print_friendly %><%= link_to('Record type', - reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::TYPE)) %> - <% else%> Record type<% end%> + + Record type - <% unless print_friendly %><%= link_to('Event date', - reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::DATE)) %> - <% else%> Event date<% end%> + + Event date - <% unless print_friendly %><%= link_to('County', - reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::COUNTY)) %> - <% else%> County<% end%> + + County - <% unless print_friendly %><%= link_to("Place : Church : Register type", - reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::LOCATION)) %> - <% else%> Place : Church : Register type<% end%> + + Place : Church : Register type
Additional possible matches with records containing Uncertain Character Formatting + Additional possible matches with records containing Uncertain Character Formatting +
\ No newline at end of file + + +<% unless print_friendly %> +
+ <%= paginate @paginatable_array if @paginatable_array.present? %> +
+<% end %> diff --git a/app/views/search_queries/_display_freereg_search_record_desktop.html.erb b/app/views/search_queries/_display_freereg_search_record_desktop.html.erb index 2df92b801..cef0fe349 100644 --- a/app/views/search_queries/_display_freereg_search_record_desktop.html.erb +++ b/app/views/search_queries/_display_freereg_search_record_desktop.html.erb @@ -1,29 +1,34 @@ <% unless print_friendly %> - <%= link_to("View #{n}", friendly_search_record_path(search_record.id, search_record.friendly_url),rel:"nofollow", :class => "btn btn--small" )%> + <%= link_to( + "View #{n}", + friendly_search_record_path(search_record.id, search_record.friendly_url), + rel: "nofollow", + class: "btn btn--small" + ) %>
- <%= viewed(@search_query,search_record) %>
+ <%= viewed(@search_query, search_record) %> <% end %> - + <% search_record[:transcript_names].uniq.each_with_index do |name, i| %> <% if name['type'] == 'primary' %> <% if i > 0 %> -
- <% end%> +
+ <% end %> <%= "#{name['first_name']} #{name['last_name']} " %> <% end %> - <% end%> + <% end %> - + <%= RecordType::display_name(search_record.record_type) %> - + <%= transcript_date(search_record) %> - + <%= county(search_record) %> - + <%= format_location(search_record) %> - \ No newline at end of file + diff --git a/app/views/search_queries/_display_search_criteria.html.erb b/app/views/search_queries/_display_search_criteria.html.erb index b2eb6386a..18e8cd444 100644 --- a/app/views/search_queries/_display_search_criteria.html.erb +++ b/app/views/search_queries/_display_search_criteria.html.erb @@ -47,8 +47,9 @@

We found more than <%= FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS %> Results

<% end%> <% unless defined?(@printable_format) && @printable_format%> - Listed by date. Select a heading to sort by that column; select again to reverse the order. - See individual details by selecting the View button. + Select a Filter or Sort option; + click Update Results; click Update Results again to reverse the order. + See individual details by selecting the View button. <% end %> diff --git a/app/views/search_queries/_search_result_form_freereg.html.erb b/app/views/search_queries/_search_result_form_freereg.html.erb new file mode 100644 index 000000000..df609533b --- /dev/null +++ b/app/views/search_queries/_search_result_form_freereg.html.erb @@ -0,0 +1,98 @@ +
+
+ + <%= form_with(url: search_query_path(@search_query), method: :get, local: true, id: 'filter_form') do |form| %> +
+ <% if @search_query.record_type.blank? %> +
+ <%= form.label :filter_results, 'Filter By' %> + <%= form.select :filter_option, + ['Baptism', 'Marriage', 'Burial', 'Clear Filter'], + selected: @filter_condition, + prompt: 'Filter By', + id: 'filter_results', + tabindex: '0' %> +
+ <% end %> + +
+ <%= form.label 'sort_results', 'Sort By' %> + <%= form.select :sort_option, + ['Person', 'Record Type', 'Event Date', 'County', 'Place'], + selected: @sort_condition, + prompt: 'Sort By', + id: 'sort_results', + tabindex: '0' %> +
+ +
+ <%= form.label 'results_per_page', 'Show' %> + <%= form.select :results_per_page, + [5, 20, 40, 60, 80, 100], + selected: @results_per_page, + prompt: 'Results per Page', + id: 'results_per_page', + tabindex: '0' %> +
+ +
+ <% if @search_query.order_asc %> + <%= form.button " Update Results".html_safe, + type: 'submit', + class: 'spinner-controller ladda-button push--top40 ', + data: { + :style => 'zoom-out', + :color => appname.downcase, + :size => 's', + 'spinner-color' => '#ffffff' + } %> + <% else %> + <%= form.button " Update Results".html_safe, + type: 'submit', + class: 'spinner-controller ladda-button push--top40 ', + data: { + :style => 'zoom-out', + :color => appname.downcase, + :size => 's', + 'spinner-color' => '#ffffff' + } %> + <% end %> +
+
+ <% end %> +
+
diff --git a/app/views/search_queries/_show_freereg.html.erb b/app/views/search_queries/_show_freereg.html.erb new file mode 100644 index 000000000..023b279bb --- /dev/null +++ b/app/views/search_queries/_show_freereg.html.erb @@ -0,0 +1,47 @@ +<% print_friendly = defined?(@printable_format) && @printable_format ? true : false %> +<% unless print_friendly %> + <%= render(partial: app_specific_partial('search_result_form')) %> +<% end %> + +
+
+
+
+ <%= render( + partial: app_specific_partial('desktop'), + locals: { + search_results: @paginatable_array, + inclusive: @search_query.inclusive, + witness: @search_query.witness, + first_name: @search_query.first_name, + last_name: @search_query.last_name, + ucf_results: @ucf_results + } + ) %> +
+ +
+ <% if @result_count > 0 && @result_count < FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS %> + <%= render 'please_donate' %> + +
+ <% end %> +
+
+ + <% unless device_type == :mobile %> +
+ Advertisement
+
+ <%= mh_160_600 %> +
+
+ +
+
+
+ <% end %> +
+
diff --git a/app/views/search_queries/show.html.erb b/app/views/search_queries/show.html.erb index db1a27f23..3a70d61db 100644 --- a/app/views/search_queries/show.html.erb +++ b/app/views/search_queries/show.html.erb @@ -25,39 +25,7 @@ <% if device_type == :desktop || device_type == :tablet %> <% case MyopicVicar::Application.config.template_set%> <% when 'freereg'%> -
-
-
-
- <%= render(:partial => app_specific_partial("desktop"), :locals => {:search_results => @search_results, :inclusive => @search_query.inclusive, :witness =>@search_query.witness, :first_name => @search_query.first_name, :last_name => @search_query.last_name, :ucf_results => @ucf_results}) %> -
-
- <% if @result_count > 0 && @result_count < FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS %> - <%= render 'please_donate' %> - -
-
- - <% end %> -
-
- <% unless device_type == :mobile%> -
- Advertisement
-
- <%= mh_160_600 %> -
-
- -
-
-
- <% end %> -
- + <%= render(partial: 'show_freereg') %> <% when 'freecen'%>
diff --git a/lib/freereg_options_constants.rb b/lib/freereg_options_constants.rb index 84512fc8d..51f19d484 100644 --- a/lib/freereg_options_constants.rb +++ b/lib/freereg_options_constants.rb @@ -156,6 +156,8 @@ module FreeregOptionsConstants DATERANGE_MINIMUM = 1530 + DEFAULT_PAGE = 1 + END_FIELDS = ['transcribed_by', 'credit', 'file_line_number', 'film', 'film_number', 'line_id', 'processed_date'] ENTRY_ORDER_DEFINITION = { 'ba' => { @@ -317,6 +319,8 @@ module FreeregOptionsConstants REGISTER_TYPE_ORDER = ['Parish Register', "Archdeacon's Transcript", "Bishop's Transcript", 'Other Register', 'Extract of a Register', 'Other Document', "Phillimore's Transcript", "Dwelly's Transcript", 'Other Transcript', 'Memorial Inscription', 'Unknown', 'Unspecified'] + RESULTS_PER_PAGE = 20 + SOURCE_NAME = ['Image Server', 'Other Server1', 'Other Server2', 'Other Server3'] ST_PERIOD = /\A[Ss][Tt]\z/