Class: Decidim::Component

Inherits:
ApplicationRecord show all
Includes:
HasSettings, Loggable, Publicable, Traceable
Defined in:
app/models/decidim/component.rb

Overview

A Component represents a self-contained group of functionalities usually defined via a ComponentManifest. It’s meant to be able to provide a single component that spans over several steps.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Publicable

#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



19
20
21
# File 'app/models/decidim/component.rb', line 19

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::ComponentPresenter
end

Instance Method Details

#manifestObject

Public: Finds the manifest this component is associated to.

Returns a ComponentManifest.



26
27
28
# File 'app/models/decidim/component.rb', line 26

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.



35
36
37
# File 'app/models/decidim/component.rb', line 35

def manifest=(manifest)
  self.manifest_name = manifest.name
end

#mounted_admin_engineObject

Public: The name of the admin engine the component is mounted to.



45
46
47
# File 'app/models/decidim/component.rb', line 45

def mounted_admin_engine
  "decidim_admin_#{participatory_space_name}_#{manifest_name}"
end

#mounted_engineObject

Public: The name of the engine the component is mounted to.



40
41
42
# File 'app/models/decidim/component.rb', line 40

def mounted_engine
  "decidim_#{participatory_space_name}_#{manifest_name}"
end

#mounted_paramsObject

Public: The hash of contextual params when the component is mounted.



50
51
52
53
54
55
56
# File 'app/models/decidim/component.rb', line 50

def mounted_params
  {
    host: organization.host,
    component_id: id,
    "#{participatory_space.underscored_name}_slug".to_sym => participatory_space.slug
  }
end

#primary_statObject

Public: Returns the value of the registered primary stat.



59
60
61
# File 'app/models/decidim/component.rb', line 59

def primary_stat
  @primary_stat ||= manifest.stats.filter(primary: true).with_context([self]).map { |name, value| [name, value] }.first&.last
end