Sha256: 755508f00eb2dfb0e592702b65c37047d875e1a355c469c3bfb939a449314e9b

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    # This cell renders metadata for an instance of an Election
    class ElectionMetadataCell < Decidim::CardMetadataCell
      def initialize(*)
        super

        @items.prepend(*election_items)
      end

      private

      def election_items
        [dates_metadata_item, state_item]
      end

      def state_item
        return if model.voting_period_status.blank?

        { text: content_tag(:span, I18n.t(model.voting_period_status, scope: "decidim.elections.election_m.badge_name"), class: "label #{state_class}") }
      end

      def state_class
        case model.voting_period_status
        when :ongoing
          "success"
        when :upcoming
          "warning"
        end
      end

      def start_date
        return unless model.start_time

        model.start_time.to_date
      end

      def end_date
        return unless model.end_time

        model.end_time.to_date
      end

      def dates_metadata_item
        {
          icon: "calendar-todo-line",
          text: [
            start_date.present? ? l(start_date, format: :decidim_short_with_month_name_short) : "?",
            end_date.present? ? l(end_date, format: :decidim_short_with_month_name_short) : "?"
          ].join(" → ")
        }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/cells/decidim/elections/election_metadata_cell.rb
decidim-elections-0.28.3 app/cells/decidim/elections/election_metadata_cell.rb
decidim-elections-0.28.2 app/cells/decidim/elections/election_metadata_cell.rb
decidim-elections-0.28.1 app/cells/decidim/elections/election_metadata_cell.rb
decidim-elections-0.28.0 app/cells/decidim/elections/election_metadata_cell.rb
decidim-elections-0.28.0.rc5 app/cells/decidim/elections/election_metadata_cell.rb
decidim-elections-0.28.0.rc4 app/cells/decidim/elections/election_metadata_cell.rb