Sha256: c3622fee99f33303f6243b02b80518e0653a83ca34a5df08ed268ff5e63035af

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module ContentBlocks
      class HighlightedVotingsCell < Decidim::ViewModel
        delegate :current_user, to: :controller

        cache :show, expires_in: 10.minutes, if: :perform_caching? do
          cache_hash
        end

        def show
          render if highlighted_votings.any?
        end

        def max_results
          model.settings.max_results
        end

        def highlighted_votings
          OrganizationPrioritizedVotings.new(current_organization, current_user)
                                        .query
                                        .limit(max_results)
        end

        def i18n_scope
          "decidim.votings.pages.home.highlighted_votings"
        end

        def decidim_votings
          Decidim::Votings::Engine.routes.url_helpers
        end

        private

        def cache_hash
          hash = []
          hash.push(I18n.locale)
          hash.push(highlighted_votings.map(&:cache_key_with_version))
          hash.join(Decidim.cache_key_separator)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb
decidim-elections-0.26.9 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb
decidim-elections-0.26.8 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb
decidim-elections-0.26.7 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb
decidim-elections-0.26.5 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb
decidim-elections-0.26.4 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb
decidim-elections-0.26.3 app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb