@@ -6,6 +6,17 @@ def initialize(params:, context:)
66 @context = context
77 end
88
9+ def month_facets
10+ ( 0 ..2 ) . map do |i |
11+ date = Time . zone . today << i
12+ PubDateLimiter . new ( {
13+ 'Id' => 'DT1' ,
14+ 'SearchField' => "#{ date . strftime ( '%Y-%m' ) } /#{ Time . zone . today . strftime ( '%Y-%m' ) } " ,
15+ 'Label' => "Since #{ date . strftime ( '%B %Y' ) } "
16+ } , params , context )
17+ end
18+ end
19+
920 def limiters
1021 @limiters ||= available_limiters . map do |limiter |
1122 Limiter . new ( limiter , params , context )
@@ -34,7 +45,6 @@ def eds_params
3445 end
3546
3647 class Limiter
37- FACET_FIELD = 'eds_search_limiters_facet'
3848 delegate :facet_item_presenter , :search_action_path , :search_state , :facet_configuration_for_field , to : :context
3949
4050 def initialize ( limiter , params , context )
@@ -43,6 +53,10 @@ def initialize(limiter, params, context)
4353 @context = context
4454 end
4555
56+ def facet_field
57+ 'eds_search_limiters_facet'
58+ end
59+
4660 def id
4761 limiter [ 'Id' ]
4862 end
@@ -51,6 +65,10 @@ def label
5165 limiter [ 'Label' ]
5266 end
5367
68+ def search_value
69+ label
70+ end
71+
5472 def type
5573 limiter [ 'Type' ]
5674 end
@@ -64,23 +82,33 @@ def enabled_by_default?
6482 end
6583
6684 def selected?
67- search_state . filter ( config ) . include? ( label )
85+ search_state . filter ( config ) . include? ( search_value )
6886 end
6987
7088 def search_url
7189 if selected?
72- search_action_path ( search_state . filter ( FACET_FIELD ) . remove ( label ) . to_h )
90+ search_action_path ( search_state . filter ( facet_field ) . remove ( search_value ) . to_h )
7391 else
74- ( config . item_presenter || Blacklight ::FacetItemPresenter ) . new ( label , config , context , FACET_FIELD ) . href
92+ ( config . item_presenter || Blacklight ::FacetItemPresenter ) . new ( search_value , config , context , facet_field ) . href
7593 end
7694 end
7795
7896 def config
79- facet_configuration_for_field ( FACET_FIELD )
97+ facet_configuration_for_field ( facet_field )
8098 end
8199
82100 private
83101
84102 attr_reader :limiter , :params , :context
85103 end
104+
105+ class PubDateLimiter < Limiter
106+ def facet_field
107+ 'eds_pub_date_facet'
108+ end
109+
110+ def search_value
111+ limiter [ 'SearchField' ]
112+ end
113+ end
86114end
0 commit comments