Skip to content

Commit

Permalink
Merge pull request #2694 from jayto581/jc/109/implement-sticking
Browse files Browse the repository at this point in the history
feat: add sticky table header  and column sort  buttons (#109)
  • Loading branch information
jayto581 authored Mar 7, 2024
2 parents 5a3f9b0 + 1eb9e7c commit ab58662
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 78 deletions.
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);
}
117 changes: 109 additions & 8 deletions app/controllers/search_queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def edit
redirect_back(fallback_location: new_search_query_path, notice: message) && return unless proceed
end


def index
redirect_to action: :new
end
Expand Down Expand Up @@ -136,6 +137,7 @@ def reorder
redirect_back(fallback_location: new_search_query_path, notice: 'No such order') && return unless proceed

order_field = params[:order_field]

if order_field == old_query.order_field
# reverse the directions
old_query.order_asc = !old_query.order_asc
Expand All @@ -144,6 +146,7 @@ def reorder
old_query.order_asc = true
end
old_query.save!

# old_query.new_order(old_query)
redirect_to search_query_path(old_query)
end
Expand Down Expand Up @@ -210,22 +213,48 @@ def selection

def show
@search_query, proceed, message = SearchQuery.check_and_return_query(params[:id])

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

@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
@save_search_id = params[:saved_search] if params[:saved_search].present?

if appname_downcase == 'freebmd'
@max_result = FreeregOptionsConstants::MAXIMUM_NUMBER_OF_BMD_RESULTS
else
@max_result = FreeregOptionsConstants::MAXIMUM_NUMBER_OF_RESULTS
end

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

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

check_sort_by

check_filter_by

create_paginatable_array(query: @search_query, results: @search_results)

end

def show_print_version
Expand All @@ -247,6 +276,8 @@ def show_print_version
flash[:notice] = 'Your search results are not available. Please repeat your search'
redirect_to(new_search_query_path(search_id: @search_query)) && return
end

create_paginatable_array(query: @search_query, results: @search_results) if appname_downcase == 'freereg'
end
render 'show', layout: false
end
Expand All @@ -266,9 +297,79 @@ def update
redirect_to search_query_path(@search_query)
end


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 check_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 check_sort_by
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
sort_objects(condition: order_field, query: @search_query)
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 sort_objects(condition:, query:)
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
67 changes: 40 additions & 27 deletions app/views/search_queries/_desktop_freereg.html.erb
Original file line number Diff line number Diff line change
@@ -1,55 +1,68 @@
<% print_friendly = (defined?(@printable_format) && @printable_format) ? true : false %>

<table class="table--bordered table--striped table--data ">
<thead>
<tr>
<% unless print_friendly %>
<th >Details</th>
<th class='sticky-header-freereg'>Details</th>
<% end %>
<th>
<% unless print_friendly %><%= link_to('Person or persons',
reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::NAME)) %>
<% else%> Person or persons<% end%>
<th class='sticky-header-freereg'>
Person or persons
</th>
<th>
<% unless print_friendly %><%= link_to('Record type',
reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::TYPE)) %>
<% else%> Record type<% end%>
<th class='sticky-header-freereg'>
Record type
</th>
<th>
<% unless print_friendly %><%= link_to('Event date',
reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::DATE)) %>
<% else%> Event date<% end%>
<th class='sticky-header-freereg'>
Event date
</th>
<th>
<% unless print_friendly %><%= link_to('County',
reorder_search_query_path(@search_query, :order_field => SearchQuery::SearchOrder::COUNTY)) %>
<% else%> County<% end%>
<th class='sticky-header-freereg'>
County
</th>
<th>
<% 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%>
<th class='sticky-header-freereg'>
Place : Church : Register type
</th>
</tr>
</thead>

<tbody>
<% n = 0 %>
<% search_results.each do |search_record| %>
<% n = n + 1 %>
<tr id="<%=search_record.id%>">
<%= render partial: 'display_freereg_search_record_desktop', :locals => {:search_record => search_record, :print_friendly => print_friendly, :n => n}%>

<tr id="<%= search_record.id %>">
<%= render partial: "display_freereg_search_record_desktop",
locals: {
search_record: search_record,
print_friendly: print_friendly,
n: n
} %>
</tr>
<% end %>

<% if ucf_results && ucf_results.length > 0 %>
<tr>
<td colspan="6"> Additional possible matches with records containing Uncertain Character Formatting </td>
<td colspan="6">
Additional possible matches with records containing Uncertain Character Formatting
</td>
</tr>

<% ucf_results.each do |search_record| %>
<% n = n + 1 %>
<tr id="<%=search_record.id%>">
<%= render partial: 'display_freereg_search_record_desktop', :locals => {:search_record => search_record, :print_friendly => print_friendly, :n => n}%>
<tr id="<%= search_record.id %>">
<%= render partial: "display_freereg_search_record_desktop",
locals: {
search_record: search_record,
print_friendly: print_friendly,
n: n
} %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</table>

<% unless print_friendly %>
<div class='text--center inline-block'>
<%= paginate @paginatable_array if @paginatable_array.present? %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
<% unless print_friendly %>
<td>
<%= 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"
) %>
<i><br>
<%= viewed(@search_query,search_record) %></i>
<%= viewed(@search_query, search_record) %></i>
</td>
<% end %>
<td >
<td>
<% search_record[:transcript_names].uniq.each_with_index do |name, i| %>
<% if name['type'] == 'primary' %>
<% if i > 0 %>
<br />
<% end%>
<% end %>
<%= "#{name['first_name']} #{name['last_name']} " %>
<% end %>
<% end%>
<% end %>
</td>
<td >
<td>
<%= RecordType::display_name(search_record.record_type) %>
</td>
<td >
<td>
<%= transcript_date(search_record) %>
</td>
<td >
<td>
<%= county(search_record) %>
</td>
<td >
<td>
<%= format_location(search_record) %>
</td>
</td>
Loading

0 comments on commit ab58662

Please sign in to comment.