Class: Lcms::Engine::Filterbar
- Inherits:
-
Object
- Object
- Lcms::Engine::Filterbar
- Defined in:
- app/entities/lcms/engine/filterbar.rb
Constant Summary collapse
- GRADES =
%w(pk k 1 2 3 4 5 6 7 8 9 10 11 12).freeze
- FACETS =
%w(grade module unit lesson multimedia other).freeze
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #facets ⇒ Object
- #grades ⇒ Object
-
#initialize(params) ⇒ Filterbar
constructor
A new instance of Filterbar.
-
#props ⇒ Object
props used for building the Filterbar React component.
- #search_facets ⇒ Object
- #search_params ⇒ Object
- #search_term ⇒ Object
- #subjects ⇒ Object
Constructor Details
#initialize(params) ⇒ Filterbar
Returns a new instance of Filterbar.
11 12 13 |
# File 'app/entities/lcms/engine/filterbar.rb', line 11 def initialize(params) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'app/entities/lcms/engine/filterbar.rb', line 6 def params @params end |
Instance Method Details
#facets ⇒ Object
39 40 41 |
# File 'app/entities/lcms/engine/filterbar.rb', line 39 def facets @facets ||= split(params[:facets]) & FACETS end |
#grades ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/entities/lcms/engine/filterbar.rb', line 15 def grades @grades ||= begin names = untranslated_grades names.map! do |name| name = name.to_s if name.casecmp('K').zero? name = 'kindergarten' elsif name.casecmp('PK').zero? name = 'prekindergarten' elsif !name.start_with?('grade') name = "grade #{name}" end name end names end end |
#props ⇒ Object
props used for building the Filterbar React component
66 67 68 69 70 71 72 73 74 75 |
# File 'app/entities/lcms/engine/filterbar.rb', line 66 def props { filterbar: { subjects: subjects, grades: untranslated_grades, facets: facets, search_term: search_term } } end |
#search_facets ⇒ Object
58 59 60 61 62 63 |
# File 'app/entities/lcms/engine/filterbar.rb', line 58 def search_facets search_facets = facets search_facets.push('video', 'podcast') if search_facets.delete('multimedia') search_facets.push('text_set', 'quick_reference_guide') if search_facets.delete('other') search_facets end |
#search_params ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/entities/lcms/engine/filterbar.rb', line 47 def search_params = pagination.params(strict: true) # handle filters [:doc_type] = search_facets if facets.present? [:subject] = subjects.first if subjects.present? [:grade] = grades if grades.present? end |
#search_term ⇒ Object
43 44 45 |
# File 'app/entities/lcms/engine/filterbar.rb', line 43 def search_term @search_term ||= params[:search_term].presence end |