Class: Decidim::EnhancedTextwork::ParagraphsPickerCell
- Inherits:
-
ViewModel
- Object
- ViewModel
- Decidim::EnhancedTextwork::ParagraphsPickerCell
- Defined in:
- app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb
Overview
This cell renders a paragraphs picker.
Constant Summary collapse
- MAX_PARAGRAPHS =
1000
Instance Method Summary collapse
- #decorated_paragraphs ⇒ Object
- #filtered? ⇒ Boolean
- #filtered_paragraphs ⇒ Object
- #more_paragraphs? ⇒ Boolean
- #more_paragraphs_count ⇒ Object
- #paragraphs ⇒ Object
- #paragraphs_collection_name ⇒ Object
- #paragraphs_count ⇒ Object
- #picker_path ⇒ Object
- #search_text ⇒ Object
- #show ⇒ Object
Instance Method Details
#decorated_paragraphs ⇒ Object
45 46 47 48 49 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 45 def decorated_paragraphs filtered_paragraphs.limit(MAX_PARAGRAPHS).each do |paragraph| yield Decidim::EnhancedTextwork::ParagraphPresenter.new(paragraph) end end |
#filtered? ⇒ Boolean
21 22 23 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 21 def filtered? !search_text.nil? end |
#filtered_paragraphs ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 51 def filtered_paragraphs @filtered_paragraphs ||= if filtered? paragraphs.where("title::text ILIKE ?", "%#{search_text}%") .or(paragraphs.where("reference ILIKE ?", "%#{search_text}%")) .or(paragraphs.where("id::text ILIKE ?", "%#{search_text}%")) else paragraphs end end |
#more_paragraphs? ⇒ Boolean
33 34 35 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 33 def more_paragraphs? @more_paragraphs ||= more_paragraphs_count.positive? end |
#more_paragraphs_count ⇒ Object
37 38 39 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 37 def more_paragraphs_count @more_paragraphs_count ||= paragraphs_count - MAX_PARAGRAPHS end |
#paragraphs ⇒ Object
61 62 63 64 65 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 61 def paragraphs @paragraphs ||= Decidim.find_resource_manifest(:paragraphs).try(:resource_scope, component) &.published &.order(id: :asc) end |
#paragraphs_collection_name ⇒ Object
67 68 69 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 67 def paragraphs_collection_name Decidim::EnhancedTextwork::Paragraph.model_name.human(count: 2) end |
#paragraphs_count ⇒ Object
41 42 43 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 41 def paragraphs_count @paragraphs_count ||= filtered_paragraphs.count end |
#picker_path ⇒ Object
25 26 27 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 25 def picker_path request.path end |
#search_text ⇒ Object
29 30 31 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 29 def search_text params[:q] end |
#show ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/cells/decidim/enhanced_textwork/paragraphs_picker_cell.rb', line 11 def show if filtered? render :paragraphs else render end end |