Sha256: 1073bfd4855f5f5824d25aebdcd9f2069e9f6d2e04d98d133060f47f2ce7a567

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require "cell/partial"

module Decidim
  module Meetings
    # This cell renders the highlighted meetings for a given component.
    # It is intended to be used in the `participatory_space_highlighted_elements`
    # view hook.
    class HighlightedMeetingsForComponentCell < Decidim::ViewModel
      include Decidim::ComponentPathHelper
      include Decidim::CardHelper

      def show
        render unless meetings_count.zero?
      end

      private

      def meetings
        @meetings ||= Decidim::Meetings::Meeting.where(component: model)
                                                .except_withdrawn
                                                .published
                                                .not_hidden
                                                .visible_for(current_user)
      end

      def past_meetings
        @past_meetings ||= meetings.past.order(end_time: :desc, start_time: :desc).limit(3)
      end

      def upcoming_meetings
        @upcoming_meetings ||= meetings.upcoming.order(:start_time, :end_time).limit(3)
      end

      def meetings_count
        @meetings_count ||= meetings.count
      end

      def past_meetings_count
        @past_meetings_count ||= meetings.past.count
      end

      def upcoming_meetings_count
        @upcoming_meetings_count ||= meetings.upcoming.count
      end

      def cache_hash
        hash = []
        hash << "decidim/meetings/highlighted_meetings_for_component"
        hash << meetings.cache_key_with_version
        hash.push(current_user.try(:id))
        hash << I18n.locale.to_s
        hash.join(Decidim.cache_key_separator)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-meetings-0.27.9 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.8 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.7 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.6 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.5 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.4 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.3 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.2 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.1 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.0 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.0.rc2 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb
decidim-meetings-0.27.0.rc1 app/cells/decidim/meetings/highlighted_meetings_for_component_cell.rb