Sha256: a6ce3a1c00f55dae8fc4ee640a69b3fdb71867b8d1cba693a89b6d8f96e8ca46

Contents?: true

Size: 1.18 KB

Versions: 51

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    module ContentBlocks
      class HighlightedConsultationsCell < Decidim::ViewModel
        delegate :current_user, to: :controller

        def show
          render if highlighted_consultations.any?
        end

        def max_results
          model.settings.max_results
        end

        def highlighted_consultations
          @highlighted_consultations ||= OrganizationActiveConsultations
                                         .new(current_organization)
                                         .query
                                         .limit(max_results)
        end

        def i18n_scope
          "decidim.consultations.pages.home.highlighted_consultations"
        end

        def decidim_consultations
          Decidim::Consultations::Engine.routes.url_helpers
        end

        def voting_ends_text_for(consultation)
          remaining_days = (consultation.end_voting_date - Time.zone.today).to_i
          return I18n.t("voting_ends_today", scope: i18n_scope) if remaining_days.zero?

          I18n.t("voting_ends_in", scope: i18n_scope, count: remaining_days)
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
decidim-consultations-0.27.9 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.8 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.7 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.6 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.10 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.9 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.5 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.8 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.4 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.3 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.7 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.5 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.2 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.1 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.4 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.0 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.3 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.0.rc2 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.27.0.rc1 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.26.2 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb