Class: Decidim::ComponentAttachmentCollectionPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Decidim::ComponentAttachmentCollectionPresenter
show all
- Includes:
- TranslatableAttributes
- Defined in:
- decidim-core/app/presenters/decidim/component_attachment_collection_presenter.rb
Overview
Decorator attachments of a component acting as an attachment collection
Instance Method Summary
collapse
#attachment?, #default_locale?
Constructor Details
Returns a new instance of ComponentAttachmentCollectionPresenter.
10
11
12
13
14
|
# File 'decidim-core/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 'decidim-core/app/presenters/decidim/component_attachment_collection_presenter.rb', line 16
def attachments
@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 'decidim-core/app/presenters/decidim/component_attachment_collection_presenter.rb', line 56
def description; end
|
#documents ⇒ Object
30
31
32
|
# File 'decidim-core/app/presenters/decidim/component_attachment_collection_presenter.rb', line 30
def documents
@documents ||= attachments.with_attached_file.order(:weight).select(&:document?)
end
|
#documents_visible_for(user) ⇒ Object
34
35
36
37
38
|
# File 'decidim-core/app/presenters/decidim/component_attachment_collection_presenter.rb', line 34
def documents_visible_for(user)
return documents unless resource_model.respond_to?(:visible_for)
attachments.merge(resource_model.visible_for(user)).with_attached_file.order(:weight).select(&:document?)
end
|
#id ⇒ Object
44
45
46
|
# File 'decidim-core/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 'decidim-core/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 'decidim-core/app/presenters/decidim/component_attachment_collection_presenter.rb', line 40
def unused?
documents.blank?
end
|