Skip to content

Commit

Permalink
WIP searchpag redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Jun 7, 2024
1 parent 9bdbd61 commit 701618a
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
10 changes: 10 additions & 0 deletions app/assets/stylesheets/stylesheets/_bootstrap_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@
}

}

.rounded-left-0 {
border-top-left-radius: 0 !important;
border-bottom-left-radius: 0 !important;
}

.rounded-right-0 {
border-top-right-radius: 0 !important;
border-bottom-right-radius: 0 !important;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= helpers.paginate @response, :page_entries_info => helpers.page_entries_info(@response), :theme => :dcv_collapsible %>
<%= helpers.paginate @response, page_entries_info: helpers.page_entries_info(@response), theme: :dcv_collapsible, paginator_class: paginator_class %>
31 changes: 30 additions & 1 deletion app/components/dcv/response/collapsible_pagination_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,40 @@ module Dcv::Response
class CollapsiblePaginationComponent < Blacklight::Response::PaginationComponent
def will_render?(controller:, helpers:)
return false unless controller.has_search_parameters?
@response && helpers.show_pagination? and @response.total_pages > 1
@response && helpers.show_pagination? and @response.total_pages > 0
end

def render?
will_render?(controller: controller, helpers: helpers)
end

def paginator_class
return OnlyPagePaginator if (@response && @response.total_pages < 2)
Kaminari::Helpers::Paginator
end

class OnlyPagePaginator < Kaminari::Helpers::Paginator
def first?
true
end

def current?
true
end

def last?
true
end

def partial_path
"#{@views_prefix}/kaminari/#{@theme}/paginator".gsub('//', '/')
end

# this is an override to render unconditionally, cf Kaminari::Helpers::Paginator#render
def render(&block)
instance_eval(&block)
@output_buffer.presence
end
end
end
end
22 changes: 16 additions & 6 deletions app/components/dcv/search_bar/catalog_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
<%= form_tag @url, method: :get, class: ['d-flex','flex-md-row-reverse','flex-sm-column','w-100'] do %>
<%= render_hash_as_hidden_fields(@params.except(:q, :search_field, :qt, :page, :utf8, :format)) %>

<div class="input-group flex-sm-row flex-md-fill">
<%- rendering_pagination = pagination_will_render? -%>
<div class="input-group flex-sm-row flex-md-fill align-content-end">
<div class="input-group-prepend btn-group btn-group-toggle" data-toggle="buttons">
<label for="show-search-mode" class="btn btn-secondary border-info rounded-left <%= 'active' unless rendering_pagination %>">
<input type="radio" name="searchpag-mode" id="show-search-mode" aria-label="Show search box" aria-controls="collapseQuery collapsePag" <%= 'disabled ' unless rendering_pagination %>data-toggle="collapse" data-target=".collapseSearch" aria-expanded="false">
<i class="previous fa fa-binoculars" title="Show search box" data-toggle="tooltip" data-original-title="Show search box"></i>
</label>
<label for="show-pag-mode" class="btn btn-secondary border-info <%= 'active' if rendering_pagination %>">
<input type="radio" name="searchpag-mode" id="show-pag-mode" aria-label="Navigate results" aria-controls="collapseQuery collapsePag" <%= rendering_pagination ? 'checked ' : ' disabled' %>data-toggle="collapse" data-target=".collapseSearch" aria-expanded="false">
<i class="previous fa fa-book-open-reader" title="Navigate results" data-toggle="tooltip" data-original-title="Navigate results"></i>
</label>
</div>
<%= render pagination_component %>
<div class="input-group-prepend collapseSearch flex-fill p-0<%= ' collapse' if pagination_component.render?%>" id="collapseQuery">
<div class="input-group-prepend collapseSearch flex-fill p-0<%= ' collapse' if rendering_pagination %>" id="collapseQuery">
<% unless search_fields.empty? %>
<span class="input-group-append">
<%= hidden_field_tag(:search_field, h(params[:search_field] || search_fields.first[1]), :title => t('blacklight.search.form.search_field.title')) %>
</span>
<% end %>
<%= text_field_tag :q, params[:q], :placeholder => (!query_has_constraints? ? t(:"dlc.search_placeholder.new.#{controller.controller_name}", default: :'dlc.search_placeholder.new.default').html_safe : t(:"dlc.search_placeholder.modified.#{controller.controller_name}", default: :'dlc.search_placeholder.modifed.default').html_safe), :class => "search_q q flex-fill bg-white", :id => "q", aria: { label: t('blacklight.search.form.search.label')} %>
<%= text_field_tag :q, params[:q], :placeholder => (!query_has_constraints? ? t(:"dlc.search_placeholder.new.#{controller.controller_name}", default: :'dlc.search_placeholder.new.default').html_safe : t(:"dlc.search_placeholder.modified.#{controller.controller_name}", default: :'dlc.search_placeholder.modifed.default').html_safe), :class => "search_q q flex-fill bg-white pl-2 border-info", :id => "q", aria: { label: t('blacklight.search.form.search.label')} %>
<div class="input-group-append">
<%= link_to '<i class="fa fa-remove"></i>'.html_safe, start_over_path, :title => 'Start Over', :class => 'btn btn-secondary reset-btn' if query_has_constraints? %>
<button class="btn btn-splash rounded-right" type="submit" aria-label="Submit">
<%= link_to '<i class="fa fa-remove"></i>'.html_safe, start_over_path, :title => 'Start Over', :class => 'btn btn-secondary reset-btn rounded-0 border-info' if query_has_constraints? %>
<button class="btn btn-splash rounded-left-0 border-info" type="submit" aria-label="Submit">
<span class="hidden-xs"><%= (current_page?(root_url)? t('blacklight.search.form.submit') : '') %></span>
<span class="fa fa-search"></span>
</button>
Expand Down
9 changes: 9 additions & 0 deletions app/components/dcv/search_bar/default_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<%= render_hash_as_hidden_fields(@params.except(:q, :search_field, :qt, :page, :utf8, :format, :slug, :site_slug)) %>
<%= render_hash_as_hidden_fields(search_action_params) %>
<div class="input-group flex-sm-row flex-md-fill">
<div class="input-group-prepend">
<button class="btn btn-secondary border-info rounded-left" type="button" data-toggle="collapse" data-target=".collapseSearch" aria-expanded="false" aria-controls="collapsePag collapseQuery" aria-pressed="false">
<i class="previous fa fa-search" title="Start a quick search" data-toggle="tooltip" data-original-title="Start a quick search"></i>
</button>
<button class="btn btn-secondary border-info rounded-left" type="button" data-toggle="collapse" data-target=".collapseSearch" aria-expanded="false" aria-controls="collapsePag collapseQuery" aria-pressed="false">
<i class="previous fa fa-book-open-reader" title="Navigate search results" data-toggle="tooltip" data-original-title="Navigate search results"></i>
</button>
</div>

<%= render pagination_component %>
<div class="input-group-prepend collapseSearch flex-fill p-0<%= ' collapse' if pagination_component.render?%>" id="collapseQuery">
<% unless search_fields.empty? %>
Expand Down
12 changes: 11 additions & 1 deletion app/components/dcv/search_bar/default_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def pagination_component
response: helpers.instance_variable_get(:@response), theme: 'dcv_collapsible',
outer_window: 1, window: 1
)
unless _comp.will_render?(controller: controller, helpers: helpers)

if _comp.will_render?(controller: controller, helpers: helpers)
@pagination_will_render = true
else
_comp = Dcv::SearchContext::CollapsiblePaginationComponent.new(
search_context: helpers.instance_variable_get(:@search_context),
search_session: helpers.instance_variable_get(:@search_session)
Expand All @@ -37,5 +40,12 @@ def pagination_component
_comp
end
end

def pagination_will_render?
if @pagination_will_render.nil?
@pagination_will_render = pagination_component.will_render?(controller: controller, helpers: helpers)
end
@pagination_will_render
end
end
end
23 changes: 6 additions & 17 deletions app/views/kaminari/dcv_collapsible/_paginator.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,12 @@
As of Kaminari 0.15, this paginator doesn't have access to the original collection/scope, so it can't render the page entries info directly.
-%>
<div class="input-group-prepend">
<button class="btn btn-secondary border-info rounded-left" type="button" data-toggle="collapse" data-target=".collapseSearch" aria-expanded="false" aria-controls="collapsePag collapseQuery" aria-pressed="false">
<i class="previous fa fa-exchange-alt toggle-unpressed" title="Navigate search results" data-toggle="tooltip" data-original-title="Navigate search results"></i>
<i class="previous fa fa-search toggle-pressed" title="Start a quick search" data-toggle="tooltip" data-original-title="Start a quick search"></i>
</button>
</div>
<div class="collapse show input-group-prepend p-0 flex-fill collapseSearch" id="collapsePag">
<% if total_pages > 1 -%>
<%# #render checks if total_pages > 1, so we can't put our fallback
in here .. -%>
<%= paginator.render do -%>
<%= first_page_tag %>
<span class="btn bg-body btn-outline-info rounded-0" style="pointer-events:none;"><%= page_entries_info %></span>
<%= prev_page_tag %>
<%= next_page_tag %>
<% end -%>
<% else -%>
<span class="btn bg-body btn-outline-info rounded-right" style="pointer-events:none;"><%= page_entries_info %></span>
<%# Kaminari::Paginator#render checks if total_pages > 1, so this requires upstream insertion of paginator override for fallback -%>
<%= paginator.render do -%>
<span class="btn bg-body btn-outline-info rounded-0 flex-fill" style="pointer-events:none;"><%= page_entries_info %></span>
<%= first_page_tag %>
<%= prev_page_tag %>
<%= next_page_tag %>
<% end -%>
</div>

0 comments on commit 701618a

Please sign in to comment.