Skip to content

Commit

Permalink
Merge pull request #506 from MaMpf-HD/fix/restore-media-search-behaviour
Browse files Browse the repository at this point in the history
Fix: Restore media search behaviour
  • Loading branch information
fosterfarrell9 authored May 17, 2023
2 parents c083e5f + cb40501 commit 3774442
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def search_params
:teachable_inheritance, :fulltext, :per,
:clicker, :purpose, :answers_count,
:results_as_list, :all_terms, :all_teachers,
:lecture_option, :user_id,
:lecture_option, :user_id, :from,
types: [],
teachable_ids: [],
tag_ids: [],
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/media_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def media_sorts_select(purpose)
return add_prompt(Medium.select_quizzables) if purpose == 'quiz'
return Medium.select_question if purpose == 'clicker'
return add_prompt(Medium.select_importables) if purpose == 'import'
return add_prompt(Medium.select_generic) if !current_user.admin?
unless current_user.admin_or_editor?
return add_prompt(Medium.select_generic)
end

add_prompt(Medium.select_sorts)
end
Expand Down
19 changes: 15 additions & 4 deletions app/models/medium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def self.select_sorts
end

def self.advanced_sorts
['RandomQuiz', 'Question', 'Remark', 'Erdbeere']
['Question', 'Remark', 'Erdbeere']
end

def self.generic_sorts
Expand Down Expand Up @@ -282,7 +282,17 @@ def self.lecture_search_option
# returns search results for the media search with search_params provided
# by the controller
def self.search_by(search_params, page)
search_params[:types] = [] if search_params[:all_types] == '1'
# If the search is initiated from the start page, you can only get
# generic media sorts as results even if the 'all' radio button
# is seleted
if search_params[:all_types] == '1'
search_params[:types] =
if search_params[:from] == 'start'
Medium.generic_sorts
else
[]
end
end
search_params[:teachable_ids] = TeachableParser.new(search_params)
.teachables_as_strings
search_params[:editor_ids] =
Expand All @@ -295,11 +305,12 @@ def self.search_by(search_params, page)
if search_params[:all_tags] == '1' && search_params[:tag_operator] == 'and'
search_params[:tag_ids] = Tag.pluck(:id)
end
admin = User.find_by(id: search_params[:user_id])&.admin?
user = User.find_by(id: search_params[:user_id])
search = Sunspot.new_search(Medium)
search.build do
with(:sort, search_params[:types])
without(:sort, Medium.advanced_sorts) unless admin
without(:sort, 'RandomQuiz')
without(:sort, Medium.advanced_sorts) unless user&.admin_or_editor?
with(:editor_ids, search_params[:editor_ids])
with(:teachable_compact, search_params[:teachable_ids])
with(:term_id,
Expand Down
3 changes: 2 additions & 1 deletion app/views/main/start/_media_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
'2',
checked: false,
class: 'custom-control-input',
data: { type: 'toggle',
data: { type: 'toggle',
id: 'search_media_lectures'} %>
<%= f.label :lecture_option,
t('search.media.lecture_options.own_selection'),
Expand Down Expand Up @@ -162,6 +162,7 @@
<%= f.hidden_field :purpose, value: purpose %>
<%= f.hidden_field :results_as_list,
value: 'false' %>
<%= f.hidden_field :from, value: 'start' %>
<div class="row mb-3">
<div class="col-12 text-center">
<%= f.submit t('basics.search'),
Expand Down
24 changes: 14 additions & 10 deletions app/views/media/catalog/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
<% if purpose == 'clicker' %>
<%= f.hidden_field :types, value: ['Question'] %>
<% end %>
<div class="custom-control custom-checkbox mb-2">
<%= f.check_box :all_types,
id: 'search_all_media_types',
class: 'custom-control-input',
checked: purpose.in?(['media', 'clicker']),
data: { id: 'search_media_types'} %>
<%= f.label :all_media_types,
t('basics.all'),
{ class: 'custom-control-label' } %>
</div>
<% if purpose == 'media' %>
<div class="custom-control custom-checkbox mb-2">
<%= f.check_box :all_types,
id: 'search_all_media_types',
class: 'custom-control-input',
checked: purpose.in?(['media', 'clicker']),
data: { id: 'search_media_types'} %>
<%= f.label :all_media_types,
t('basics.all'),
{ class: 'custom-control-label' } %>
</div>
<% else %>
<%= f.hidden_field :all_types, value: '0' %>
<% end %>
</div>
<div class="col-6 col-lg-3 form-group">
<%= f.label :teachable_ids, t('basics.associated_to') %>
Expand Down

0 comments on commit 3774442

Please sign in to comment.