From 2e65372e6eefa1c149c60e9f75781c8d456d82af Mon Sep 17 00:00:00 2001 From: Peter Hankiewicz Date: Fri, 23 Sep 2022 20:16:09 +0200 Subject: [PATCH] Make search facets work properly in media mentions view Enlarge work description fields in admin --- CHANGELOG.md | 5 ++++ .../lumen/faceted_search_form.js.coffee | 2 +- .../rails_admin/custom/notice_edit_form.js | 6 +++-- .../media_mentions/search_controller.rb | 1 + app/controllers/notices/search_controller.rb | 24 +------------------ app/controllers/search_controller.rb | 18 ++++++++++++++ app/views/search/index.html.erb | 2 +- config/routes.rb | 6 ++++- 8 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 589d6a203..6c7a38a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). It uses [CalVer](https://calver.org/) as of May 2019. +## [22.09e](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.09e) - 2022-09-23 +### Fixed +* Enlarge the `work description` fields in the `admin`. +* Made `search facets` work properly in the `media mentions` view. + ## [22.09d](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.09d) - 2022-09-21 ### Changed * Moved the `site language` to the `database`. diff --git a/app/assets/javascripts/lumen/faceted_search_form.js.coffee b/app/assets/javascripts/lumen/faceted_search_form.js.coffee index efad20139..e257a5f3d 100644 --- a/app/assets/javascripts/lumen/faceted_search_form.js.coffee +++ b/app/assets/javascripts/lumen/faceted_search_form.js.coffee @@ -42,7 +42,7 @@ $('ol.results-facets .dropdown-toggle').on 'click', (event) -> list.html(loader) $.get( - facet_notices_search_index_path + window.location.search, + facet_search_index_path + window.location.search, { facet_id: clicked_elem.nextAll('input[type=hidden]').first().attr('id') }, (response) -> new_facet_list = $(response).find('ol').html() diff --git a/app/assets/javascripts/rails_admin/custom/notice_edit_form.js b/app/assets/javascripts/rails_admin/custom/notice_edit_form.js index 93bd03650..761664cd0 100644 --- a/app/assets/javascripts/rails_admin/custom/notice_edit_form.js +++ b/app/assets/javascripts/rails_admin/custom/notice_edit_form.js @@ -59,10 +59,12 @@ class NoticeEditForm { 'type': 'object', 'properties': { 'description': { - 'type': 'string' + 'type': 'string', + 'format': 'html' }, 'description_original': { - 'type': 'string' + 'type': 'string', + 'format': 'html' }, 'kind': { 'type': 'string' diff --git a/app/controllers/media_mentions/search_controller.rb b/app/controllers/media_mentions/search_controller.rb index 536da99e9..33937f3ba 100644 --- a/app/controllers/media_mentions/search_controller.rb +++ b/app/controllers/media_mentions/search_controller.rb @@ -12,6 +12,7 @@ def set_model_specific_variables @ordering_options = MediaMention::ORDERING_OPTIONS @url_root = URL_ROOT @search_all_placeholder = 'Search all research and media mentions...' + @facet_search_index_path = facet_media_mentions_search_index_path end def item_searcher diff --git a/app/controllers/notices/search_controller.rb b/app/controllers/notices/search_controller.rb index 0575e8c7b..6fe206b68 100644 --- a/app/controllers/notices/search_controller.rb +++ b/app/controllers/notices/search_controller.rb @@ -3,29 +3,6 @@ class Notices::SearchController < SearchController URL_ROOT = 'notices'.freeze SEARCHED_MODEL = Notice - def facet - if current_user.nil? && !Rails.env.test? - time_permission = session[:captcha_permission] - return if time_permission.nil? || time_permission < Time.now - end - - filterable_field_facet = Notice::FILTERABLE_FIELDS.select { |filterable_field| filterable_field.parameter.to_s == params[:facet_id] }.first - - resource_not_found and return if filterable_field_facet.nil? - - @searcher = ElasticsearchQuery.new(params).tap do |searcher| - Notice::SEARCHABLE_FIELDS.each do |searched_field| - searcher.register searched_field - end - - searcher.register(filterable_field_facet) - end - - @searchdata = @searcher.search - - render filterable_field_facet, locals: { results: @searchdata.response['aggregations'] } - end - private def set_model_specific_variables @@ -36,6 +13,7 @@ def set_model_specific_variables @ordering_options = Notice::ORDERING_OPTIONS @url_root = URL_ROOT @search_all_placeholder = 'Search all notices...' + @facet_search_index_path = facet_notices_search_index_path end def item_searcher diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ec2fece2b..732bce977 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -41,6 +41,24 @@ def index end end + def facet + filterable_field_facet = @filterable_fields.select { |filterable_field| filterable_field.parameter.to_s == params[:facet_id] }.first + + resource_not_found and return if filterable_field_facet.nil? + + @searcher = ElasticsearchQuery.new(params, @model_class).tap do |searcher| + @searchable_fields.each do |searched_field| + searcher.register searched_field + end + + searcher.register(filterable_field_facet) + end + + @searchdata = @searcher.search + + render filterable_field_facet, locals: { results: @searchdata.response['aggregations'] } + end + private def html_responder; end diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index 17fdc331e..9a59cbc4b 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -38,6 +38,6 @@ <% end %> diff --git a/config/routes.rb b/config/routes.rb index a9e5eb652..dc3a803de 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,7 +69,11 @@ get 'blog_feed', to: 'blog_feed#index' namespace :media_mentions do - resources :search, only: [:index] + resources :search, only: %i[index] do + collection do + get :facet + end + end end resources :media_mentions, only: :show