Sha256: 68241190b20b8740e56a3bdb70eedf4aaf12a8f1f9c111d47dbf3b5589979482

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # This cell renders the Medium (:m) initiative card
    # for an given instance of an Initiative
    class InitiativeMCell < Decidim::CardMCell
      include Decidim::Initiatives::Engine.routes.url_helpers

      property :state

      private

      def title
        decidim_html_escape(translated_attribute(model.title))
      end

      def hashtag
        decidim_html_escape(model.hashtag)
      end

      def has_state?
        true
      end

      # Explicitely commenting the used I18n keys so their are not flagged as unused
      # i18n-tasks-use t('decidim.initiatives.show.badge_name.accepted')
      # i18n-tasks-use t('decidim.initiatives.show.badge_name.created')
      # i18n-tasks-use t('decidim.initiatives.show.badge_name.discarded')
      # i18n-tasks-use t('decidim.initiatives.show.badge_name.published')
      # i18n-tasks-use t('decidim.initiatives.show.badge_name.rejected')
      # i18n-tasks-use t('decidim.initiatives.show.badge_name.validating')
      def badge_name
        I18n.t(model.state, scope: "decidim.initiatives.show.badge_name")
      end

      def state_classes
        case state
        when "accepted", "published"
          ["success"]
        when "rejected", "discarded"
          ["alert"]
        when "validating"
          ["warning"]
        else
          ["muted"]
        end
      end

      def resource_path
        initiative_path(model)
      end

      def resource_icon
        icon "initiatives", class: "icon--big"
      end

      def authors
        [present(model).author] +
          model.committee_members.approved.non_deleted.excluding_author.map { |member| present(member.user) }
      end

      def has_image?
        image.present?
      end

      def image
        @image ||= model.attachments.find do |attachment|
          attachment.file.content_type.start_with?("image")
        end
      end

      def resource_image_path
        image.url if has_image?
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-initiatives-0.24.3 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.6 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.24.2 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.5 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.24.1 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.24.0 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.24.0.rc2 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.4 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.24.0.rc1 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.3 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.2 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.1 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.1.rc1 app/cells/decidim/initiatives/initiative_m_cell.rb
decidim-initiatives-0.23.0 app/cells/decidim/initiatives/initiative_m_cell.rb