Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor works mobile filter #326

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 0 additions & 9 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,3 @@ var mobileWidth = 767;
function isMobile() {
return window.innerWidth < mobileWidth;
}

function submit_filters() {
startModal('spinnerdiv');
if(window.innerWidth < mobileWidth) {
$('#mobile_filters').submit();
} else {
$('#works_filters').submit();
}
}
10 changes: 0 additions & 10 deletions app/assets/stylesheets/BY_styles_General.css
Original file line number Diff line number Diff line change
Expand Up @@ -3998,13 +3998,6 @@ a .by-icon-v02:disabled{
#sort-by{
width: auto;
}
.sort-by-desktop{
display: block;
margin-right: 8px;
}
.sort-by-mobile{
display: none;
}

.sort-type{
margin-top: 15px;
Expand Down Expand Up @@ -5068,9 +5061,6 @@ position: absolute;
#sort_by_dd{
display: block;
}
#current_sort_by{
display: none;
}
.select-text label{
line-height: 24px;
margin-top: 0px;
Expand Down
3 changes: 0 additions & 3 deletions app/assets/stylesheets/BY_styles_Max767.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@
#author-whats-new-popup{
background-color: #eeeced;
}
.sort-by-desktop{
display: none;
}
.author-side-sort{
display:none;
}
Expand Down
14 changes: 5 additions & 9 deletions app/assets/stylesheets/BY_styles_Max991.css
Original file line number Diff line number Diff line change
Expand Up @@ -837,16 +837,12 @@
#sort_by_dd{
display: none;
}
#current_sort_by{
display: block;
padding: 0 4px;
.side-sort{
display:none;
}
.author-side-sort{
display: none;
}
.side-sort{
display:none;
}
.author-side-sort{
display: none;
}
.author-sort-area{
width: auto;
padding: 0;
Expand Down
3 changes: 0 additions & 3 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,6 @@ body.modal-open{
.notice a {color:#514721;}
.success a {color:#264409;}

.sort-by-mobile{
display: block !important;
}
.flex-row {
display: flex;
/* flex: 1 0 100%; */
Expand Down
14 changes: 4 additions & 10 deletions app/controllers/authors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,10 @@ def build_es_filter_from_filters
end
# languages
if params['ckb_languages'].present?
if params['ckb_languages'] == ['xlat']
ret << {must_not: {term: {language: 'he'}}}
@filters << [I18n.t(:translations), 'lang_xlat', :checkbox]
else
@languages = params['ckb_languages'].reject{|x| x == 'xlat'}
if @languages.present?
ret << {terms: {language: @languages}}
@filters += @languages.map{|x| ["#{I18n.t(:orig_lang)}: #{helpers.textify_lang(x)}", "lang_#{x}", :checkbox]}
end
@languages = params['ckb_languages'].reject { |x| x == 'xlat' }
if @languages.present?
ret << { terms: { language: @languages } }
@filters += @languages.map { |x| ["#{I18n.t(:orig_lang)}: #{helpers.textify_lang(x)}", "lang_#{x}", :checkbox] }
end
end
# tags by tag_id
Expand Down Expand Up @@ -214,7 +209,6 @@ def get_sort_column(sort_by)
def es_prep_collection
@sort_dir = 'default'
if params[:sort_by].present?
@sort_or_filter = 'sort'
@sort = params[:sort_by].dup
@sort_by = params[:sort_by].sub(/_(a|de)sc$/, '')
@sort_dir = Regexp.last_match(0)[1..] unless Regexp.last_match(0).nil?
Expand Down
11 changes: 0 additions & 11 deletions app/controllers/concerns/filtering_and_pagination_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ module FilteringAndPaginationConcern

private

def es_buckets_to_facet(buckets, codes)
facet = {}
buckets.each do |facethash|
code = codes[facethash['key']]
facet[code] = facethash['doc_count'] unless code.nil?
end
facet
end

def buckets_to_totals_hash(buckets)
buckets.to_h { |facethash| [facethash['key'], facethash['doc_count']] }
end
Expand All @@ -29,8 +20,6 @@ def paginate(collection)
# in works list (e.g. to start second page from index 101)
@page = (params[:page] || 1).to_i

@emit_filters = params[:load_filters] == 'true' || params[:emit_filters] == 'true'

prepare_totals(collection) # This method should be implemented in controllers using this concern

# checking if non-first page should be loaded
Expand Down
56 changes: 29 additions & 27 deletions app/controllers/manifestation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,16 +641,6 @@ def build_es_filter_from_filters
@filters += @tgenders.map { |x| [I18n.t(:translator) + ': ' + I18n.t(x), "tgender_#{x}", :checkbox] }
end

# author ids - multi-select authors
if params['authors'].present?
@search_type = 'authorname'
author_ids = params['authors'].split(',').map(&:to_i)
ret['author_ids'] = author_ids
@authors = author_ids # .join(',')
@authors_names = params['authors_names']
@filters << [I18n.t(:authors_xx, xx: @authors_names), 'authors', :authorlist]
end

# languages
@languages = params['ckb_languages']
if @languages.present?
Expand Down Expand Up @@ -685,17 +675,29 @@ def build_es_filter_from_filters
ret[datefield] = range_expr
end

# author ids - multi-select authors
if params['authors'].present?
author_ids = params['authors'].split(',').map(&:to_i)
ret['author_ids'] = author_ids
@authors = author_ids # .join(',')
@authors_names = params['authors_names']
@filters << [I18n.t(:authors_xx, xx: @authors_names), 'authors', :authorlist]
end

# in browse UI we can either use search by author name or by title, but not together
@authorstr = params['authorstr']
@search_input = params['search_input']
if @search_input.present? || @authorstr.present?
if params['search_type'] == 'authorname' || (@authorstr.present? && @search_input.empty?)
@search_type = params['search_type'] || 'authorname'
if @search_type == 'authorname'
@authorstr = params['authorstr']
@search_input = ''
if @authorstr.present?
ret['author'] = @authorstr
@search_type = 'authorname'
@filters << [I18n.t(:author_x, x: @authorstr), :authors, :text]
else
end
else
@authorstr = ''
@search_input = params['search_input']
if @search_input.present?
ret['title'] = @search_input
@search_type = 'workname'
@filters << [I18n.t(:title_x, x: @search_input), :search_input, :text]
end
end
Expand All @@ -717,16 +719,17 @@ def prepare_totals(collection)

collection = collection.aggregations(standard_aggregations)

@gender_facet = es_buckets_to_facet(collection.aggs['author_genders']['buckets'], Person.genders)
@tgender_facet = es_buckets_to_facet(collection.aggs['translator_genders']['buckets'], Person.genders)
@period_facet = es_buckets_to_facet(collection.aggs['periods']['buckets'], Expression.periods)
@genre_facet = es_buckets_to_facet(collection.aggs['genres']['buckets'], get_genres.to_h { |g| [g, g] })
@language_facet = es_buckets_to_facet(collection.aggs['languages']['buckets'], get_langs.to_h { |l| [l, l] })
@gender_facet = buckets_to_totals_hash(collection.aggs['author_genders']['buckets'])
@tgender_facet = buckets_to_totals_hash(collection.aggs['translator_genders']['buckets'])
@period_facet = buckets_to_totals_hash(collection.aggs['periods']['buckets'])
@genre_facet = buckets_to_totals_hash(collection.aggs['genres']['buckets'])

@language_facet = buckets_to_totals_hash(collection.aggs['languages']['buckets'])
@language_facet[:xlat] = @language_facet.except('he').values.sum
@copyright_facet = es_buckets_to_facet(
collection.aggs['copyright_status']['buckets'],
{ 'false' => 0, 'true' => 1 }
)

@copyright_facet = collection.aggs['copyright_status']['buckets'].to_h do |hash|
[hash['key'] == 'true' ? 1 : 0, hash['doc_count']]
end

# Preparing list of authors to show in multiselect modal on works browse page
if collection.filter.present?
Expand All @@ -745,7 +748,6 @@ def get_sort_column(sort_by)
def es_prep_collection
@sort_dir = 'default'
if params[:sort_by].present?
@sort_or_filter = 'sort'
@sort = params[:sort_by].dup
@sort_by = params[:sort_by].sub(/_(a|de)sc$/,'')
@sort_dir = $&[1..-1] unless $&.nil?
Expand Down
Loading
Loading