Sha256: e24ee31b1bb82572c5713ab1f1bde70d18ff65d22ca118b82a4cc39d969d2a30

Contents?: true

Size: 1000 Bytes

Versions: 12

Compression:

Stored size: 1000 Bytes

Contents

# frozen_string_literal: true

require "cell/partial"

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

      def show
        render unless proposals_count.zero?
      end

      private

      def proposals
        @proposals ||= Decidim::Proposals::Proposal.published.not_hidden.except_withdrawn
                                                   .where(component: model)
                                                   .order_randomly(rand * 2 - 1)
      end

      def proposals_to_render
        @proposals_to_render ||= proposals.limit(Decidim::Proposals.config.participatory_space_highlighted_proposals_limit)
      end

      def proposals_count
        @proposals_count ||= proposals.count
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-proposals-0.21.0 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.20.1 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.20.0 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.19.1 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.18.1 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.19.0 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.17.2 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.18.0 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.17.1 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.16.1 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.17.0 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb
decidim-proposals-0.16.0 app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb