Sha256: aa38985afa871a76be92c26ed8d4a9af7053f1947e17018a51bfd631dcb65a45

Contents?: true

Size: 1.97 KB

Versions: 31

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders a collapsible list of a model's coauthors.
  #
  # Available sizes:
  #  - any number from 1 to 12
  #  - default value is 1
  #  - it is delegated to the `decidim/collapsible_list` cell
  #
  # Extra params:
  # - `extra_small` => boolean: when this cell is included in small places this
  #     option adds extra css ("author-data--small") to make the box smaller.
  #
  # Example:
  #
  #    cell("decidim/coauthorships", @proposal)
  class CoauthorshipsCell < Decidim::ViewModel
    include Decidim::ApplicationHelper

    def show
      if authorable?
        cell "decidim/author", presenter_for_author(model), extra_classes.merge(has_actions: has_actions?, from: model)
      else
        cell(
          "decidim/collapsible_authors",
          presenters_for_identities(model),
          cell_name: "decidim/author",
          cell_options: extra_classes,
          size: size,
          from: model,
          has_actions: has_actions?
        )
      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

    def extra_classes
      if options[:extra_small]
        { extra_classes: ["author-data--small"] }
      else
        {}
      end
    end

    def size
      options[:size] || 1
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.8 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.7 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.6 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.10 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.9 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.5 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.8 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.4 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.3 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.7 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.5 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.2 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.1 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.4 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.0 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.3 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.0.rc2 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.27.0.rc1 app/cells/decidim/coauthorships_cell.rb
decidim-core-0.26.2 app/cells/decidim/coauthorships_cell.rb