Sha256: 9c7967e5322cfb816ed5abe8b3dc398125695d105c14bbd1159838b315fee75f

Contents?: true

Size: 1.19 KB

Versions: 45

Compression:

Stored size: 1.19 KB

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

    # 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?

      render
    end

    def activity_cell_for(activity)
      options = {
        show_author: (context[:user] != activity.user)
      }

      cell "#{activity.resource_type.constantize.name.underscore}_activity", activity, context: options
    rescue NameError
      cell "decidim/activity", activity, context: options
    end

    def activities
      @activities ||= last_activities.select do |activity|
        activity.visible_for?(current_user)
      end
    end

    def last_activities
      @last_activities ||= model.map do |activity|
        activity.organization_lazy
        activity.resource_lazy
        activity.participatory_space_lazy
        activity.component_lazy
        activity
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/cells/decidim/activities_cell.rb
decidim-core-0.26.9 app/cells/decidim/activities_cell.rb
decidim-core-0.26.8 app/cells/decidim/activities_cell.rb
decidim-core-0.27.3 app/cells/decidim/activities_cell.rb
decidim-core-0.26.7 app/cells/decidim/activities_cell.rb
decidim-core-0.26.5 app/cells/decidim/activities_cell.rb
decidim-core-0.27.2 app/cells/decidim/activities_cell.rb
decidim-core-0.27.1 app/cells/decidim/activities_cell.rb
decidim-core-0.26.4 app/cells/decidim/activities_cell.rb
decidim-core-0.27.0 app/cells/decidim/activities_cell.rb
decidim-core-0.26.3 app/cells/decidim/activities_cell.rb
decidim-core-0.27.0.rc2 app/cells/decidim/activities_cell.rb
decidim-core-0.27.0.rc1 app/cells/decidim/activities_cell.rb
decidim-core-0.26.2 app/cells/decidim/activities_cell.rb
decidim-core-0.26.1 app/cells/decidim/activities_cell.rb
decidim-core-0.26.0 app/cells/decidim/activities_cell.rb
decidim-core-0.26.0.rc2 app/cells/decidim/activities_cell.rb
decidim-core-0.26.0.rc1 app/cells/decidim/activities_cell.rb
decidim-core-0.25.2 app/cells/decidim/activities_cell.rb
decidim-core-0.25.1 app/cells/decidim/activities_cell.rb