Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jc/109/implement sticking 3 #2722

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@
}
}
}

/**
* Add/remove margins
*/
.push--top40 {
margin-top: 40px;
}
24 changes: 24 additions & 0 deletions app/assets/stylesheets/styles/scss/lap_and_up.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
120 changes: 111 additions & 9 deletions app/controllers/search_queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
98 changes: 76 additions & 22 deletions app/models/search_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading