Sha256: da9df41abd311b576ff7a101f815a5d84754d7d6862cb9ad49840245882427a7

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 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.merge(from: model)
        )
      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

4 entries across 4 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.28.3 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.28.2 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.28.1 app/cells/decidim/coauthorships_cell.rb