Sha256: c4a8f29e998075f0d1bcc57263692e6a8283b57fc8ea5dfbb0b6b624ee028b73

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders a collapsible list of a model's coauthors.
  #
  # Example:
  #
  #    cell("decidim/coauthorships", @proposal)
  class CoauthorshipsCell < Decidim::ViewModel
    include Decidim::ApplicationHelper

    def show
      if authorable?
        cell "decidim/author", presenter_for_author(model), has_actions: has_actions?, from: model
      else
        cell(
          "decidim/collapsible_authors",
          presenters_for_identities(model),
          options
        )
      end
    end

    private

    def official?
      model.respond_to?(:official?) && model.official?
    end

    def presenters_for_identities(coauthorable)
      coauthorable.identities.map do |identity|
        if identity.is_a?(Decidim::Organization)
          "#{model.class.module_parent}::OfficialAuthorPresenter".constantize.new
        else
          present(identity)
        end
      end
    end

    def presenter_for_author(authorable)
      if official?
        "#{model.class.module_parent}::OfficialAuthorPresenter".constantize.new
      else
        authorable.user_group&.presenter || authorable.author.presenter
      end
    end

    def authorable?
      model.is_a?(Decidim::Authorable)
    end

    def has_actions?
      options[:has_actions] == true
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.28.0 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.28.0.rc5 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.28.0.rc4 app/cells/decidim/coauthorships_cell.rb