Skip to content

Commit 8d71e33

Browse files
committed
WIP refactor pagination and search controls as a toggle
1 parent 5a06b2e commit 8d71e33

11 files changed

+64
-23
lines changed

app/assets/stylesheets/stylesheets/_base_layout.scss

+4-5
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@ a {
267267
padding-bottom: 0;
268268
margin-top: 0;
269269
margin-bottom: 0;
270-
background-color: $primary;
271-
color:map-get($theme-text-colors, 'primary');
272-
border-color: map-get($theme-border-colors, 'primary');
273270
select {
274-
background-color: inherit;
271+
background-color: $primary;
272+
color:map-get($theme-text-colors, 'primary');
273+
border-color: map-get($theme-border-colors, 'primary');
275274
}
276-
.btn {
275+
.btn-left {
277276
border-top-left-radius:0.25rem;
278277
border-bottom-left-radius:0.25rem;
279278
}

app/assets/stylesheets/stylesheets/shared/shared.css

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ body.empty {
1717
#q-filter {
1818
display: none;
1919
}
20+
21+
/** collapse UI heleprs */
22+
.btn[aria-expanded="true"] > .toggle-pressed { display: none }
23+
.btn[aria-expanded="true"] > .toggle-unpressed { display: inline-block; }
24+
25+
.btn[aria-expanded="false"] > .toggle-pressed { display: inline-block }
26+
.btn[aria-expanded="false"] > .toggle-unpressed { display: none; }

app/components/dcv/response/collapsible_pagination_component.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
module Dcv::Response
44
class CollapsiblePaginationComponent < Blacklight::Response::PaginationComponent
5-
def render?
5+
def will_render?(controller:, helpers:)
66
return false unless controller.has_search_parameters?
77
@response && helpers.show_pagination? and @response.total_pages > 1
88
end
9+
10+
def render?
11+
will_render?(controller: controller, helpers: helpers)
12+
end
913
end
1014
end

app/components/dcv/search_bar/catalog_component.html.erb

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
<%= render_hash_as_hidden_fields(@params.except(:q, :search_field, :qt, :page, :utf8, :format)) %>
33

44
<div class="input-group flex-sm-row flex-md-fill">
5-
<%= render Dcv::Response::CollapsiblePaginationComponent.new(response: helpers.instance_variable_get(:@response), theme: 'dcv_collapsible', outer_window: 1, window: 1 ) %>
6-
<%= render Dcv::SearchContext::CollapsiblePaginationComponent.new(search_context: helpers.instance_variable_get(:@search_context), search_session: helpers.instance_variable_get(:@search_session)) %>
5+
<%= render pagination_component %>
6+
<div class="input-group-prepend collapseSearch flex-fill<%= ' p-0 collapse' if pagination_component.render?%>" id="collapseQuery">
77
<% unless search_fields.empty? %>
88
<span class="input-group-append">
99
<%= hidden_field_tag(:search_field, h(params[:search_field] || search_fields.first[1]), :title => t('blacklight.search.form.search_field.title')) %>
1010
</span>
1111
<% end %>
12-
<%= 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 form-control", :id => "q", aria: { label: t('blacklight.search.form.search.label')} %>
12+
<%= 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", :id => "q", aria: { label: t('blacklight.search.form.search.label')} %>
1313
<div class="input-group-append">
1414
<%= 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? %>
1515
<button class="btn btn-primary search-btn" type="submit" aria-label="Submit">
1616
<span class="hidden-xs"><%= (current_page?(root_url)? t('blacklight.search.form.submit') : '') %></span>
1717
<span class="fa fa-search"></span>
1818
</button>
1919
</div>
20+
</div>
2021
</div>
2122

2223
<% end %>

app/components/dcv/search_bar/default_component.html.erb

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22
<%= render_hash_as_hidden_fields(@params.except(:q, :search_field, :qt, :page, :utf8, :format, :slug, :site_slug)) %>
33
<%= render_hash_as_hidden_fields(search_action_params) %>
44
<div class="input-group flex-sm-row flex-md-fill">
5-
<%= render Dcv::Response::CollapsiblePaginationComponent.new(response: helpers.instance_variable_get(:@response), theme: 'dcv_collapsible', outer_window: 1, window: 1 ) %>
6-
<%= render Dcv::SearchContext::CollapsiblePaginationComponent.new(search_context: helpers.instance_variable_get(:@search_context), search_session: helpers.instance_variable_get(:@search_session)) %>
5+
<%= render pagination_component %>
6+
<div class="input-group-prepend collapseSearch flex-fill<%= ' p-0 collapse' if pagination_component.render?%>" id="collapseQuery">
77
<% unless search_fields.empty? %>
8-
<span class="input-group-prepend p-0<%= ' hidden' if search_fields.length == 1 %>">
8+
<span class="input-group-append p-0<%= ' hidden' if search_fields.length == 1 %>">
99
<label for="search_field" class="sr-only"><%= t('blacklight.search.form.search_field.label') %></label>
1010
<%= select_tag(
1111
:search_field,
1212
options_for_select(
1313
search_fields,
1414
h(params[:search_field])
1515
),
16-
title: t('blacklight.search.form.search_field.title'), class: 'btn search-btn btn-primary'
16+
title: t('blacklight.search.form.search_field.title'), class: 'btn search-btn btn-primary rounded-0'
1717
)
1818
%>
1919
<span class="sr-only"><%= t('blacklight.search.form.search_field.post_label') %></span>
2020
</span>
2121
<% end %>
2222
<label for="q" class="sr-only"><%= t('blacklight.search.form.q') %></label>
23-
<%= text_field_tag :q, params[:q], :placeholder => search_placeholder_text, :class => "search_q q form-control", :id => "q" %>
23+
<%= text_field_tag :q, params[:q], :placeholder => search_placeholder_text, :class => "search_q q flex-fill", :id => "q" %>
2424
<div class="input-group-append">
25-
<%= link_to '<i class="fa fa-remove"></i>'.html_safe, start_over_path, :title => 'Start Over', :class => 'btn btn-outline-secondary reset-btn' if query_has_constraints? %>
25+
<%= link_to '<i class="fa fa-remove"></i>'.html_safe, start_over_path, :title => 'Start Over', :class => 'btn btn-outline-secondary reset-btn' if query_has_constraints? %>
2626
<button class="btn btn-primary search-btn" type="submit" aria-label="Submit">
2727
<span class="hidden-xs"><%= (current_page?(root_url)? t('blacklight.search.form.submit') : '') %></span>
2828
<span class="fa fa-search"></span>
2929
</button>
3030
</div>
31+
</div>
3132
</div>
3233

3334
<% end %>

app/components/dcv/search_bar/default_component.rb

+17
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,22 @@ def start_over_path
2020
end
2121
URI::HTTP.build(path: path, query: query.join('&')).request_uri
2222
end
23+
24+
def pagination_component
25+
return @pagination_component unless @pagination_component.nil?
26+
@pagination_component = begin
27+
_comp = Dcv::Response::CollapsiblePaginationComponent.new(
28+
response: helpers.instance_variable_get(:@response), theme: 'dcv_collapsible',
29+
outer_window: 1, window: 1
30+
)
31+
unless _comp.will_render?(controller: controller, helpers: helpers)
32+
_comp = Dcv::SearchContext::CollapsiblePaginationComponent.new(
33+
search_context: helpers.instance_variable_get(:@search_context),
34+
search_session: helpers.instance_variable_get(:@search_session)
35+
)
36+
end
37+
_comp
38+
end
39+
end
2340
end
2441
end

app/components/dcv/search_bar/durst_component.html.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<%= render_hash_as_hidden_fields(params_for_new_search) %>
66

77
<div class="input-group flex-sm-row flex-md-fill">
8+
<%= render pagination_component %>
9+
<div class="input-group-prepend collapseSearch flex-fill<%= ' p-0 collapse' if pagination_component.render?%>" id="collapseQuery">
810
<input type="hidden" name="search_field" value="all_text_teim">
9-
<div class="input-group-prepend">
10-
1111
<button id="format_type_select" type="button" class="btn btn-dark dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Formats
1212
<span class="caret"></span>
1313
<span class="sr-only">Toggle Dropdown</span>
@@ -20,7 +20,7 @@
2020
</ul>
2121
</div>
2222
<label for="q" class="sr-only"><%= t('blacklight.search.form.q') %></label>
23-
<%= text_field_tag :q, params[:q], :placeholder => (!query_has_constraints? ? 'Search Postcards, Maps, Photographs, Books, Etc&hellip;'.html_safe : 'Modify current search&hellip;'.html_safe), :class => "search_q q form-control", :id => "q", :tabindex => "1" %>
23+
<%= text_field_tag :q, params[:q], :placeholder => (!query_has_constraints? ? 'Search Postcards, Maps, Photographs, Books, Etc&hellip;'.html_safe : 'Modify current search&hellip;'.html_safe), :class => "search_q q flex-fill", :id => "q", :tabindex => "1" %>
2424
<div class="input-group-append">
2525
<%= 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? %>
2626
<button class="btn btn-primary search-btn" type="submit">

app/components/dcv/search_bar/repositories_component.html.erb

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<%= render_hash_as_hidden_fields(@params.except(:q, :search_field, :repository_id, :qt, :page, :utf8, :format).tap { |p| p[:'f[content_availability][]'] = @content_availability if @content_availability }) %>
33

44
<div class="input-group flex-fill">
5-
<%= render Dcv::Response::CollapsiblePaginationComponent.new(response: helpers.instance_variable_get(:@response), theme: 'dcv_collapsible', outer_window: 1, window: 1 ) %>
6-
<%= render Dcv::SearchContext::CollapsiblePaginationComponent.new(search_context: helpers.instance_variable_get(:@search_context), search_session: helpers.instance_variable_get(:@search_session)) %>
5+
<%= render pagination_component %>
6+
<div class="input-group-prepend collapseSearch flex-fill<%= ' p-0 collapse' if pagination_component.render?%>" id="collapseQuery">
77
<% unless search_fields.empty? %>
88
<span class="input-group-prepend hidden"> <%# to be removed. might need hidde %>
99
<label for="search_field" class="sr-only"><%= t('blacklight.search.form.search_field.label') %></label>
@@ -12,13 +12,14 @@
1212
</span>
1313
<% end %>
1414
<label for="q" class="sr-only"><%= t('blacklight.search.form.q') %></label>
15-
<%= 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 form-control", :id => "q" %>
15+
<%= 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", :id => "q" %>
1616
<div class="input-group-append">
1717
<%= 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? %>
1818
<button class="btn btn-primary search-btn" type="submit" aria-label="Submit">
1919
<span class="fa fa-search"></span>
2020
</button>
2121
</div>
22+
</div>
2223
</div>
2324

2425
<% end %>

app/components/dcv/search_context/pagination_component.rb

+3
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
module Dcv::SearchContext
44
class PaginationComponent < Blacklight::SearchContextComponent
5+
def will_render?(**_args)
6+
render?
7+
end
58
end
69
end

app/controllers/application_controller.rb

+5
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ def on_client_disconnect
9898
def on_page_not_found
9999
render(status: :not_found, plain: "Page Not Found")
100100
end
101+
102+
# this is overridden in controller that mixin Blacklight::Catalog
103+
def has_search_parameters?
104+
false
105+
end
101106
end

app/views/kaminari/dcv_collapsible/_paginator.html.erb

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
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.
1616
-%>
1717
<div class="input-group-prepend">
18-
<button class="btn btn-info" type="button" data-toggle="collapse" data-target="#collapsePag" aria-expanded="true" aria-controls="collapsePag" aria-pressed="true"><i class="previous fa fa-exchange-alt" title="Navigate search results" data-toggle="tooltip" data-original-title="Navigate search results"></i></button>
18+
<button class="btn btn-info btn-left" type="button" data-toggle="collapse" data-target=".collapseSearch" aria-expanded="false" aria-controls="collapseQuery" aria-pressed="false">
19+
<i class="previous fa fa-exchange-alt toggle-unpressed" title="Navigate search results" data-toggle="tooltip" data-original-title="Navigate search results"></i>
20+
<i class="previous fa fa-search toggle-pressed" title="Start a quick search" data-toggle="tooltip" data-original-title="Start a quick search"></i>
21+
</button>
1922
</div>
20-
<div class="collapse show width input-group-prepend" id="collapsePag">
23+
<div class="collapse show width input-group-prepend collapseSearch p-0 flex-fill" id="collapsePag">
2124
<% if total_pages > 1 -%>
2225
<%# #render checks if total_pages > 1, so we can't put our fallback
2326
in here .. -%>

0 commit comments

Comments
 (0)