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 %> +
Details | +Details | <% end %> -- <% 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 + | ||||||||||