Sha256: 4d23e715766385b4d73edb7ec0b9a588be085a34f57c35f8ce7b4a142eac4807

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    module ContentBlocks
      class HighlightedConsultationsCell < Decidim::ViewModel
        delegate :current_organization, to: :controller
        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

5 entries across 5 versions & 1 rubygems

Version Path
decidim-consultations-0.16.1 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.16.0 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.15.2 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.15.1 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb
decidim-consultations-0.15.0 app/cells/decidim/consultations/content_blocks/highlighted_consultations_cell.rb