Sha256: 851b8ec75ec9e57e4f6d20b3ba485c834ce05c3913d273cec9f1fb2ecdb10729

Contents?: true

Size: 1.47 KB

Versions: 21

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

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

        def show
          return if upcoming_events.blank?

          render
        end

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

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

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

        private

        def limit
          geolocation_enabled? ? 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

21 entries across 21 versions & 1 rubygems

Version Path
decidim-meetings-0.25.2 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.25.1 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.25.0 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.25.0.rc4 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.25.0.rc3 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.25.0.rc2 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.25.0.rc1 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.24.3 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.6 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.24.2 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.5 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.24.1 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.24.0 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.24.0.rc2 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.4 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.24.0.rc1 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.3 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.2 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.1 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb
decidim-meetings-0.23.1.rc1 app/cells/decidim/meetings/content_blocks/upcoming_events_cell.rb