Class: Decidim::Component
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Component
- Includes:
- HasSettings, HasTaxonomySettings, Loggable, Publicable, ScopableComponent, ShareableWithToken, SoftDeletable, Traceable, TranslatableAttributes
- Defined in:
- decidim-core/app/models/decidim/component.rb
Overview
A Component represents a self-contained group of functionalities usually defined via a ComponentManifest. It is meant to be able to provide a single component that spans over several steps.
Class Method Summary collapse
Instance Method Summary collapse
- #can_participate_in_space?(user) ⇒ Boolean
-
#form_class ⇒ Object
Public: The Form Class for this component.
- #hierarchy_title ⇒ Object
-
#manifest ⇒ Object
Public: Finds the manifest this component is associated to.
-
#manifest=(manifest) ⇒ Object
Public: Assigns a manifest to this component.
-
#mounted_admin_engine ⇒ Object
Public: The name of the admin engine the component is mounted to.
-
#mounted_engine ⇒ Object
Public: The name of the engine the component is mounted to.
-
#mounted_params ⇒ Object
Public: The hash of contextual params when the component is mounted.
-
#primary_stat ⇒ Object
Public: Returns the value of the registered primary stat.
- #private_non_transparent_space? ⇒ Boolean
-
#resource_description ⇒ Object
Public: Returns an empty description.
-
#resource_title ⇒ Object
Public: Returns the component’s name as resource title.
-
#shareable_url(share_token) ⇒ Object
Public: Public URL for component with given share token as query parameter.
-
#siblings ⇒ Object
Other components with the same manifest and same participatory space as this one.
Methods included from TranslatableAttributes
Methods included from Publicable
#previously_published?, #publish!, #published?, #unpublish!
Methods included from HasSettings
#current_settings, #default_step_settings, #default_step_settings=, #settings, #settings=, #step_settings, #step_settings=
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
27 28 29 |
# File 'decidim-core/app/models/decidim/component.rb', line 27 def self.log_presenter_class_for(_log) Decidim::AdminLog::ComponentPresenter end |
Instance Method Details
#can_participate_in_space?(user) ⇒ Boolean
99 100 101 102 103 104 |
# File 'decidim-core/app/models/decidim/component.rb', line 99 def can_participate_in_space?(user) return true unless participatory_space.try(:private_space?) return false unless user participatory_space.can_participate?(user) end |
#form_class ⇒ Object
Public: The Form Class for this component.
Returns a ComponentForm.
74 75 76 |
# File 'decidim-core/app/models/decidim/component.rb', line 74 def form_class manifest.component_form_class end |
#hierarchy_title ⇒ Object
88 89 90 91 92 93 94 |
# File 'decidim-core/app/models/decidim/component.rb', line 88 def hierarchy_title [ I18n.t("decidim.admin.menu.#{participatory_space.class.name.demodulize.underscore.pluralize}"), translated_attribute(participatory_space.title), translated_attribute(name) ].join(" / ") end |
#manifest ⇒ Object
Public: Finds the manifest this component is associated to.
Returns a ComponentManifest.
39 40 41 |
# File 'decidim-core/app/models/decidim/component.rb', line 39 def manifest Decidim.find_component_manifest(manifest_name) end |
#manifest=(manifest) ⇒ Object
Public: Assigns a manifest to this component.
manifest - The ComponentManifest for this Component.
Returns nothing.
48 49 50 |
# File 'decidim-core/app/models/decidim/component.rb', line 48 def manifest=(manifest) self.manifest_name = manifest.name end |
#mounted_admin_engine ⇒ Object
Public: The name of the admin engine the component is mounted to.
58 59 60 |
# File 'decidim-core/app/models/decidim/component.rb', line 58 def mounted_admin_engine "decidim_admin_#{participatory_space_name}_#{manifest_name}" end |
#mounted_engine ⇒ Object
Public: The name of the engine the component is mounted to.
53 54 55 |
# File 'decidim-core/app/models/decidim/component.rb', line 53 def mounted_engine "decidim_#{participatory_space_name}_#{manifest_name}" end |
#mounted_params ⇒ Object
Public: The hash of contextual params when the component is mounted.
63 64 65 66 67 68 69 |
# File 'decidim-core/app/models/decidim/component.rb', line 63 def mounted_params { :host => organization.host, :component_id => id, :"#{participatory_space.underscored_name}_slug" => participatory_space.slug } end |
#primary_stat ⇒ Object
Public: Returns the value of the registered primary stat.
79 80 81 |
# File 'decidim-core/app/models/decidim/component.rb', line 79 def primary_stat @primary_stat ||= manifest.stats.filter(primary: true).with_context([self]).map { |name, value| [name, value] }.first&.last end |
#private_non_transparent_space? ⇒ Boolean
106 107 108 109 110 111 112 113 114 115 |
# File 'decidim-core/app/models/decidim/component.rb', line 106 def private_non_transparent_space? return false unless participatory_space.respond_to?(:private_space?) return false unless participatory_space.private_space? if participatory_space.respond_to?(:is_transparent?) !participatory_space.is_transparent? else true end end |
#resource_description ⇒ Object
Public: Returns an empty description
97 |
# File 'decidim-core/app/models/decidim/component.rb', line 97 def resource_description; end |
#resource_title ⇒ Object
Public: Returns the component’s name as resource title
84 85 86 |
# File 'decidim-core/app/models/decidim/component.rb', line 84 def resource_title name end |
#shareable_url(share_token) ⇒ Object
Public: Public URL for component with given share token as query parameter
118 119 120 |
# File 'decidim-core/app/models/decidim/component.rb', line 118 def shareable_url(share_token) EngineRouter.main_proxy(self).root_url(self, share_token: share_token.token) end |
#siblings ⇒ Object
Other components with the same manifest and same participatory space as this one.
32 33 34 |
# File 'decidim-core/app/models/decidim/component.rb', line 32 def siblings @siblings ||= participatory_space.components.where.not(id:).where(manifest_name:) end |