Class: Decidim::ComponentAttachmentCollectionPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Decidim::ComponentAttachmentCollectionPresenter
- Includes:
- TranslatableAttributes
- Defined in:
- app/presenters/decidim/component_attachment_collection_presenter.rb
Overview
Decorator attachments of a component acting as an attachment collection
Instance Method Summary collapse
- #attachments ⇒ Object
- #description ⇒ Object
- #documents ⇒ Object
- #documents_visible_for(user) ⇒ Object
- #id ⇒ Object
-
#initialize(resource, opts = {}) ⇒ ComponentAttachmentCollectionPresenter
constructor
A new instance of ComponentAttachmentCollectionPresenter.
- #name ⇒ Object
- #unused? ⇒ Boolean
Methods included from TranslatableAttributes
Constructor Details
#initialize(resource, opts = {}) ⇒ ComponentAttachmentCollectionPresenter
Returns a new instance of ComponentAttachmentCollectionPresenter.
10 11 12 13 14 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 10 def initialize(resource, opts = {}) super(resource) @include_component_name = opts[:include_component_name] end |
Instance Method Details
#attachments ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 16 def @attachments ||= if [resource_model_name, resource_table_name].all?(&:present?) base_query = Decidim::Attachment.joins(resource_join.join_sources) .where(resource_table_name => { decidim_component_id: __getobj__.id }) if resource_model&.include?(Decidim::Publicable) base_query.where.not(resource_table_name => { published_at: nil }) else base_query end else Decidim::Attachment.none end end |
#description ⇒ Object
56 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 56 def description; end |
#documents ⇒ Object
30 31 32 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 30 def documents @documents ||= .with_attached_file.order(:weight).select(&:document?) end |
#documents_visible_for(user) ⇒ Object
34 35 36 37 38 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 34 def documents_visible_for(user) return documents unless resource_model.respond_to?(:visible_for) .merge(resource_model.visible_for(user)).with_attached_file.order(:weight).select(&:document?) end |
#id ⇒ Object
44 45 46 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 44 def id "component-#{__getobj__.id}" end |
#name ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 48 def name base_name = I18n.t(manifest_name, scope: "decidim.application.documents.component_documents") return base_name unless @include_component_name "#{base_name} - #{translated_attribute(__getobj__.name)}" end |
#unused? ⇒ Boolean
40 41 42 |
# File 'app/presenters/decidim/component_attachment_collection_presenter.rb', line 40 def unused? documents.blank? end |