Sha256: a862a81b0adccae25cbc0a7626d35917666f22bc47f8ebe94a3bbcb0aabbda6c

Contents?: true

Size: 983 Bytes

Versions: 3

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # Renders a collection of activities using a different cell for
  # each one.
  class ActivitiesCell < Decidim::ViewModel
    include Decidim::CardHelper
    include Decidim::IconHelper
    include Decidim::Core::Engine.routes.url_helpers

    delegate :current_organization, to: :controller

    # Since we're rendering each activity separatedly we need to trigger
    # BatchLoader in order to accumulate all the ids to be found later.
    def show
      return if activities.blank?

      activities.map do |activity|
        activity.organization_lazy
        activity.resource_lazy
        activity.participatory_space_lazy
        activity.component_lazy
      end

      render
    end

    def activity_cell_for(activity)
      cell "#{activity.resource_type.constantize.name.underscore}_activity", activity
    rescue NameError
      cell "decidim/activity", activity
    end

    def activities
      model
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.15.2 app/cells/decidim/activities_cell.rb
decidim-core-0.15.1 app/cells/decidim/activities_cell.rb
decidim-core-0.15.0 app/cells/decidim/activities_cell.rb