Sha256: 3d87ba5592b1f6aa32e23f5201daf49243dbcb2ccdbc92ccc52f957a814a255f

Contents?: true

Size: 1.98 KB

Versions: 14

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

module Decidim
  # 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 Component < ApplicationRecord
    include HasSettings
    include Publicable
    include Traceable
    include Loggable

    belongs_to :participatory_space, polymorphic: true

    default_scope { order(arel_table[:weight].asc, arel_table[:manifest_name].asc) }

    delegate :organization, :categories, to: :participatory_space

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

    # Public: Finds the manifest this component is associated to.
    #
    # Returns a ComponentManifest.
    def manifest
      Decidim.find_component_manifest(manifest_name)
    end

    # Public: Assigns a manifest to this component.
    #
    # manifest - The ComponentManifest for this Component.
    #
    # Returns nothing.
    def manifest=(manifest)
      self.manifest_name = manifest.name
    end

    # Public: The name of the engine the component is mounted to.
    def mounted_engine
      "decidim_#{participatory_space_name}_#{manifest_name}"
    end

    # Public: The name of the admin engine the component is mounted to.
    def mounted_admin_engine
      "decidim_admin_#{participatory_space_name}_#{manifest_name}"
    end

    # Public: The hash of contextual params when the component is mounted.
    def mounted_params
      {
        host: organization.host,
        component_id: id,
        "#{participatory_space.underscored_name}_slug".to_sym => participatory_space.slug
      }
    end

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

    private

    def participatory_space_name
      participatory_space.underscored_name
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-core-0.14.4 app/models/decidim/component.rb
decidim-core-0.14.3 app/models/decidim/component.rb
decidim-core-0.14.2 app/models/decidim/component.rb
decidim-core-0.14.1 app/models/decidim/component.rb
decidim-core-0.13.1 app/models/decidim/component.rb
decidim-core-0.12.2 app/models/decidim/component.rb
decidim-core-0.13.0 app/models/decidim/component.rb
decidim-core-0.12.1 app/models/decidim/component.rb
decidim-core-0.13.0.pre1 app/models/decidim/component.rb
decidim-core-0.12.0 app/models/decidim/component.rb
decidim-core-0.11.2 app/models/decidim/component.rb
decidim-core-0.12.0.pre app/models/decidim/component.rb
decidim-core-0.11.1 app/models/decidim/component.rb
decidim-core-0.11.0.pre1 app/models/decidim/component.rb