Sha256: 8bc462726ac7efc48bd8af86d7fa9b5b96cbf3bc48bc5f10c3a91048fd9768aa

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module ContentBlocks
      class UpcomingMeetingsCell < Decidim::ViewModel
        include Decidim::CardHelper

        def show
          return if upcoming_meetings.blank?

          render
        end

        def upcoming_meetings
          @upcoming_meetings ||= Decidim::Meetings::Meeting
                                 .includes(component: :participatory_space)
                                 .where(component: meeting_components)
                                 .visible_meeting_for(current_user)
                                 .published
                                 .where("end_time >= ?", Time.current)
                                 .except_withdrawn
                                 .not_hidden
                                 .order(start_time: :asc)
                                 .limit(limit)
        end

        def show_map?
          maps_active? && !all_online_meetings?
        end

        def maps_active?
          Decidim::Map.available?(:geocoding)
        end

        def all_online_meetings?
          upcoming_meetings.collect(&:type_of_meeting).all?("online")
        end

        def meetings_directory_path
          Decidim::Meetings::DirectoryEngine.routes.url_helpers.root_path
        end

        private

        def limit
          maps_active? ? 4 : 8
        end

        def meeting_components
          @meeting_components ||= Decidim::Component
                                  .where(manifest_name: "meetings")
                                  .where(participatory_space: participatory_spaces)
                                  .published
        end

        def participatory_spaces
          @participatory_spaces ||= current_organization.public_participatory_spaces
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-meetings-0.26.10 app/cells/decidim/meetings/content_blocks/upcoming_meetings_cell.rb
decidim-meetings-0.26.9 app/cells/decidim/meetings/content_blocks/upcoming_meetings_cell.rb