Skip to content

Commit 257210b

Browse files
committed
Dropdown to adjust page size. Fixes #1195
1 parent e1f4443 commit 257210b

6 files changed

Lines changed: 35 additions & 2 deletions

File tree

app/assets/javascripts/application.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ function redirect_to_sort_url(){
5050
window.location.replace(url.toString());
5151
}
5252

53+
function apply_per_page(){
54+
url = new URL(window.location.href);
55+
url.searchParams.set(
56+
"per_page",
57+
$("#per_page").val()
58+
);
59+
window.location.replace(url.toString());
60+
}
61+
5362
function redirect_with_updated_search(param, paramVal) {
5463
url = new URL(window.location.href);
5564
// special case for empty range types

app/assets/stylesheets/application.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,21 @@ ul.unstyled {
418418
}
419419

420420
.search-results-count {
421-
margin-right: 5px;
421+
margin-right: 1em;
422422
display: inline-block
423423
}
424424

425+
.search-results-per-page {
426+
display: inline-block;
427+
428+
select {
429+
border: none;
430+
padding: 0;
431+
background: transparent;
432+
border-bottom: 1px dashed $text-color;
433+
}
434+
}
435+
425436
.index-display-options {
426437
margin: 5px 0;
427438
}

app/controllers/concerns/searchable_index.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# The concern for searchable index
22
module SearchableIndex
3+
DEFAULT_PAGE_SIZE = 10
4+
PER_PAGE_OPTIONS = [10, 20, 50, 100]
5+
36
extend ActiveSupport::Concern
47

58
included do
@@ -19,7 +22,7 @@ def count
1922
def fetch_resources
2023
if TeSS::Config.solr_enabled
2124
page = page_param.blank? ? 1 : page_param.to_i
22-
per_page = per_page_param.blank? ? 10 : per_page_param.to_i
25+
per_page = per_page_param.blank? ? DEFAULT_PAGE_SIZE : per_page_param.to_i
2326

2427
@search_results = @model.search_and_filter(current_user, @search_params, @facet_params,
2528
page: page, per_page: per_page, sort_by: @sort_by)

app/helpers/application_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,9 @@ def omniauth_login_link(provider, config)
708708
method: :post
709709
)
710710
end
711+
712+
def per_page_options_for_select
713+
options_for_select(SearchableIndex::PER_PAGE_OPTIONS.map { |k| [k, k] },
714+
params[:per_page].presence || SearchableIndex::DEFAULT_PAGE_SIZE)
715+
end
711716
end

app/views/search/common/_search_panel.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<div class="search-results-count">
2828
<%= pluralize(resources.total, resource_type.model_name.human.downcase ) %> found
2929
</div>
30+
<div class="search-results-per-page form-inline pull-right">
31+
<label for="per_page"><%= t('sidebar.per_page') %></label>
32+
<%= select_tag('per_page', per_page_options_for_select, onchange: 'apply_per_page()', class: 'font-size-sm') %>
33+
</div>
3034
<% end %>
3135
</div>
3236
</div>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ en:
910910
values:
911911
show_hidden: 'Show hidden items'
912912
hide_hidden: 'Hide hidden items'
913+
per_page: 'Results per page: '
913914
collections:
914915
show:
915916
curate_materials: "Curate materials"

0 commit comments

Comments
 (0)