Sha256: 816c9f9e6fcd0d479e133d9e595f2a6c3a28528a7475e316db22d5a465f94d04

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Decidim
  module ContentBlocks
    # A cell to be rendered as a content block with the latest activities performed
    # in a Decidim Organization.
    class MenuBreadcrumbLastActivityCell < LastActivityCell
      private

      def activities
        @activities ||= if model.is_a?(Decidim::Organization)
                          Decidim::LastActivity.new(model).query
                        else
                          Decidim::ParticipatorySpaceLastActivity.new(model).query
                        end.limit(activities_to_show * 6)
      end

      # A MD5 hash of model attributes is needed because
      # it ensures the cache version value will always be the same size
      def cache_hash
        hash = []
        hash << "decidim/content_blocks/menu_breadcrumb_last_activity"
        hash << id_prefix
        hash << Digest::MD5.hexdigest(valid_activities.map(&:cache_key_with_version).to_s)
        hash << I18n.locale.to_s

        hash.join(Decidim.cache_key_separator)
      end

      def activities_options
        @activities_options ||= { id_prefix: }.merge(options.slice(:hide_participatory_space))
      end

      def id_prefix
        @id_prefix ||= options[:id_prefix] || model.respond_to?(:to_gid) ? model.to_gid.to_param : "menu-breadcrumb"
      end

      def activities_to_show
        4
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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