Sha256: 2680fded325cb790081b8618a72e8375ddffa879f912c9dfc3c024f3b2c81a2f

Contents?: true

Size: 976 Bytes

Versions: 34

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

require "cell/partial"

module Decidim
  module Accountability
    # This cell renders the highlighted results for a given component.
    # It is intended to be used in the `participatory_space_highlighted_elements`
    # view hook.
    class HighlightedResultsForComponentCell < Decidim::ViewModel
      include ActiveSupport::NumberHelper
      include Decidim::Accountability::ApplicationHelper
      include Decidim::ComponentPathHelper
      include Decidim::LayoutHelper
      include Cell::ViewModel::Partial

      def show
        render unless results_count.zero?
      end

      private

      def results
        @results ||= Decidim::Accountability::Result.where(component: model).order_randomly(rand * 2 - 1)
      end

      def results_to_render
        @results_to_render ||= results.includes(:component, :status).limit(4)
      end

      def results_count
        @results_count ||= results.count
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
decidim-accountability-0.26.10 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.9 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.8 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.7 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.5 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.4 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.3 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.2 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.1 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.0 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.0.rc2 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.26.0.rc1 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.2 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.1 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.0 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.0.rc4 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.0.rc3 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.0.rc2 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.25.0.rc1 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb
decidim-accountability-0.24.3 app/cells/decidim/accountability/highlighted_results_for_component_cell.rb