Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 40 additions & 33 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,41 @@
//= require ol
//= require ol-geocoder

function redirect_to_sort_url(){
url = new URL(window.location.href);
url.searchParams.set(
"sort",
$("#sort").find(":selected").val()
);
window.location.replace(url.toString());
}

function redirect_with_updated_search(param, paramVal) {
url = new URL(window.location.href);
// special case for empty range types
if (param == 'start' && paramVal == '/') {
url.searchParams.delete(param);
} else {
url.searchParams.set(param, paramVal);
}
window.location.replace(url.toString());
}

function reposition_tiles(container, tileClass){
var $container = $("." + container);

$container.imagesLoaded(function () {
$container.masonry({
// options...
itemSelector: "." + tileClass,
columnWidth: 20
const Index = {
applySorting: function () {
Index.setParam("sort", $("#sort").val());
},

applyPerPage: function () {
Index.setParam("per_page", $("#per_page").val());
},

applyDateParam: function (param, value) {
const url = new URL(window.location.href);
if (param === 'start' && value === '/') {
url.searchParams.delete(param);
} else {
url.searchParams.set(param, value);
}
window.location.replace(url.toString());
},

setParam: function (param, value) {
const url = new URL(window.location.href);
url.searchParams.set(param, value);
window.location.replace(url.toString());
},

repositionTiles(containerSelector, itemSelector) {
const container = $(containerSelector);
container.imagesLoaded(function () {
container.masonry({
// options...
itemSelector: itemSelector,
columnWidth: 20
});
});
});
}
}

// Perform an ajax request to load the calendar and replace the contents
Expand Down Expand Up @@ -152,7 +157,7 @@ document.addEventListener("turbolinks:load", function(e) {
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
addTabToFilters(e.target.href.split('#').pop());
// and reposition masonry tiles
reposition_tiles('masonry', 'masonry-brick');
Index.repositionTiles('.masonry', '.masonry-brick');
});

// Manually trigger bootstrap tab history (we should probably remove the dependency and reimplement in a turbolink-compatible way)
Expand All @@ -168,12 +173,14 @@ document.addEventListener("turbolinks:load", function(e) {

// Masonry
$(".nav-tabs a").on("shown.bs.tab", function(e) {
reposition_tiles('masonry', 'masonry-brick');
Index.repositionTiles('.masonry', '.masonry-brick');
});

$(window).on("orientationchange", function() {
reposition_tiles("masonry", "masonry-brick");
Index.repositionTiles('.masonry', '.masonry-brick');
});
reposition_tiles("masonry", "masonry-brick");

Index.repositionTiles('.masonry', '.masonry-brick');

new Clipboard(".clipboard-btn");

Expand Down
13 changes: 12 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,21 @@ ul.unstyled {
}

.search-results-count {
margin-right: 5px;
margin-right: 1em;
display: inline-block
}

.search-results-per-page {
display: inline-block;

select {
border: none;
padding: 0;
background: transparent;
border-bottom: 1px dashed $text-color;
}
}

.index-display-options {
margin: 5px 0;
}
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/concerns/searchable_index.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# The concern for searchable index
module SearchableIndex
DEFAULT_PAGE_SIZE = 10
PER_PAGE_OPTIONS = [10, 20, 50, 100]

extend ActiveSupport::Concern

included do
Expand All @@ -19,7 +22,7 @@ def count
def fetch_resources
if TeSS::Config.solr_enabled
page = page_param.blank? ? 1 : page_param.to_i
per_page = per_page_param.blank? ? 10 : per_page_param.to_i
per_page = per_page_param.blank? ? DEFAULT_PAGE_SIZE : per_page_param.to_i

@search_results = @model.search_and_filter(current_user, @search_params, @facet_params,
page: page, per_page: per_page, sort_by: @sort_by)
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,4 +698,9 @@ def unverified_notice(resource)
def theme_path
"themes/#{params[:theme_preview] || current_space&.theme || TeSS::Config.site['default_theme'] || 'default'}"
end

def per_page_options_for_select
options_for_select(SearchableIndex::PER_PAGE_OPTIONS.map { |k| [k, k] },
params[:per_page].presence || SearchableIndex::DEFAULT_PAGE_SIZE)
end
end
4 changes: 2 additions & 2 deletions app/views/search/common/_facet_sidebar_date_filter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</li>

<li class="nav-item active" style="display: none; font-size: 15px; text-align: center;">
<input type="date" name="<%= facet_field %>_lb" value="<%= lb %>" style="width: 47%;" onchange="redirect_with_updated_search('<%= facet_field %>', this.value + '/' + '<%= ub %>');">
<input type="date" name="<%= facet_field %>_lb" value="<%= lb %>" style="width: 47%;" onchange="Index.applyDate('<%= facet_field %>', this.value + '/' + '<%= ub %>');">
-
<input type="date" name="<%= facet_field %>_ub" value="<%= ub %>" style="width: 47%;" onchange="redirect_with_updated_search('<%= facet_field %>', '<%= lb %>' + '/' + this.value);">
<input type="date" name="<%= facet_field %>_ub" value="<%= ub %>" style="width: 47%;" onchange="Index.applyDate('<%= facet_field %>', '<%= lb %>' + '/' + this.value);">
</li>
</ul>
</li>
4 changes: 4 additions & 0 deletions app/views/search/common/_search_panel.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<div class="search-results-count">
<%= pluralize(resources.total, resource_type.model_name.human.downcase ) %> found
</div>
<div class="search-results-per-page form-inline pull-right">
<label for="per_page"><%= t('sidebar.per_page') %></label>
<%= select_tag('per_page', per_page_options_for_select, onchange: 'Index.applyPerPage()', class: 'font-size-sm') %>
</div>
<% end %>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/search/common/_sort_by.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ e.g.
<li class="facet-sort-group">
<span class="icon icon-lg sort-icon facet-sort-icon"></span>
<%= select_tag(:sort, options_for_select(options, @sort_by),
onchange: 'redirect_to_sort_url()', class: 'form-control facet-select font-size-sm facet-sort')
onchange: 'Index.applySorting()', class: 'form-control facet-select font-size-sm facet-sort')
%>
</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ en:
values:
show_hidden: 'Show hidden items'
hide_hidden: 'Hide hidden items'
per_page: 'Results per page: '
collections:
show:
curate_materials: "Curate materials"
Expand Down
Loading