Sha256: ff3a5088ef1d465465b21bbe99d59c48851f5983c3bf1c04a61bb926de928714

Contents?: true

Size: 946 Bytes

Versions: 12

Compression:

Stored size: 946 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.limit(4)
      end

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

Version data entries

12 entries across 12 versions & 1 rubygems

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