forked from sistephens/finder-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirection_controller.rb
56 lines (47 loc) · 2.33 KB
/
redirection_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# typed: false
require 'publications_routes'
class RedirectionController < ApplicationController
include PublicationsRoutes
DEFAULT_PUBLICATIONS_PATH = 'search/all'.freeze
def announcements
respond_to do |format|
format.html { redirect_to(finder_path('search/news-and-communications', params: convert_common_parameters)) }
format.atom { redirect_to(finder_path('search/news-and-communications', params: convert_common_parameters, format: :atom)) }
end
end
def publications
respond_to do |format|
format.html { redirect_to(finder_path(publications_base_path, params: convert_common_parameters.merge(content_store_document_type: set_document_type).compact)) }
format.atom { redirect_to(finder_path(publications_base_path, params: convert_common_parameters.merge(content_store_document_type: set_document_type).compact, format: :atom)) }
end
end
def published_statistics
respond_to do |format|
format.html { redirect_to(finder_path('search/statistics', params: convert_common_parameters)) }
format.atom { redirect_to(finder_path('search/statistics', params: convert_common_parameters, format: :atom)) }
end
end
def upcoming_statistics
respond_to do |format|
format.html { redirect_to(finder_path('search/statistics', params: convert_common_parameters.merge(content_store_document_type: :statistics_upcoming))) }
format.atom { redirect_to(finder_path('search/statistics', params: convert_common_parameters.merge(content_store_document_type: :statistics_upcoming), format: :atom)) }
end
end
private
def publications_base_path
base_path = PUBLICATIONS_ROUTES.dig(params[:publication_filter_option], :base_path)
base_path || DEFAULT_PUBLICATIONS_PATH
end
def set_document_type
PUBLICATIONS_ROUTES.dig(params[:publication_filter_option], :special_params, :content_store_document_type)
end
def convert_common_parameters
{ keywords: params['keywords'],
level_one_taxon: params['taxons'].try(:first) || params['topics'].try(:first),
level_two_taxon: params['subtaxons'].try(:first),
organisations: params['departments'] || params['organisations'],
people: params['people'],
world_locations: params['world_locations'],
public_timestamp: { from: params['from_date'], to: params['to_date'] }.compact.presence }.compact
end
end