Class: Decidim::Component

Inherits:
ApplicationRecord show all
Includes:
HasSettings, Loggable, Publicable, ScopableComponent, ShareableWithToken, Traceable
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'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


21
22
23
# File 'decidim-core/app/models/decidim/component.rb', line 21

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

Instance Method Details

#can_participate_in_space?(user) ⇒ Boolean

Returns:

  • (Boolean)

85
86
87
88
89
90
# File 'decidim-core/app/models/decidim/component.rb', line 85

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_classObject

Public: The Form Class for this component.

Returns a ComponentForm.


68
69
70
# File 'decidim-core/app/models/decidim/component.rb', line 68

def form_class
  manifest.component_form_class
end

#manifestObject

Public: Finds the manifest this component is associated to.

Returns a ComponentManifest.


33
34
35
# File 'decidim-core/app/models/decidim/component.rb', line 33

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.


42
43
44
# File 'decidim-core/app/models/decidim/component.rb', line 42

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

#mounted_admin_engineObject

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


52
53
54
# File 'decidim-core/app/models/decidim/component.rb', line 52

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.


47
48
49
# File 'decidim-core/app/models/decidim/component.rb', line 47

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

#mounted_paramsObject

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


57
58
59
60
61
62
63
# File 'decidim-core/app/models/decidim/component.rb', line 57

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.


73
74
75
# File 'decidim-core/app/models/decidim/component.rb', line 73

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

#resource_descriptionObject

Public: Returns an empty description


83
# File 'decidim-core/app/models/decidim/component.rb', line 83

def resource_description; end

#resource_titleObject

Public: Returns the component's name as resource title


78
79
80
# File 'decidim-core/app/models/decidim/component.rb', line 78

def resource_title
  name
end

#shareable_url(share_token) ⇒ Object

Public: Public URL for component with given share token as query parameter


93
94
95
# File 'decidim-core/app/models/decidim/component.rb', line 93

def shareable_url(share_token)
  EngineRouter.main_proxy(self).root_path(self, share_token: share_token.token)
end

#siblingsObject

Other components with the same manifest and same participatory space as this one.


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

def siblings
  @siblings ||= participatory_space.components.where.not(id: id).where(manifest_name: manifest_name)
end