Sha256: d2b661e458e42b4fa0e71f0e61c7e095727c98e95dccc1359ba13ac0f04c097e

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # Custom helpers, scoped to the proposals engine.
    #
    module ApplicationHelper
      include Decidim::Comments::CommentsHelper
      include PaginateHelper
      include ProposalVotesHelper
      include Decidim::MapHelper
      include Decidim::Proposals::MapHelper

      # Public: The state of a proposal in a way a human can understand.
      #
      # state - The String state of the proposal.
      #
      # Returns a String.
      def humanize_proposal_state(state)
        I18n.t(state, scope: "decidim.proposals.answers", default: :not_answered)
      end

      # Public: The css class applied based on the proposal state.
      #
      # state - The String state of the proposal.
      #
      # Returns a String.
      def proposal_state_css_class(state)
        case state
        when "accepted"
          "text-success"
        when "rejected"
          "text-alert"
        when "evaluating"
          "text-info"
        else
          "text-warning"
        end
      end

      # Public: The css class applied based on the proposal state to
      #         the proposal badge.
      #
      # state - The String state of the proposal.
      #
      # Returns a String.
      def proposal_state_badge_css_class(state)
        case state
        when "accepted"
          "success"
        when "rejected"
          "warning"
        when "evaluating"
          "secondary"
        when "withdrawn"
          "alert"
        end
      end

      def proposal_limit_enabled?
        proposal_limit.present?
      end

      def proposal_limit
        return if feature_settings.proposal_limit.zero?

        feature_settings.proposal_limit
      end

      def current_user_proposals
        Proposal.where(feature: current_feature, author: current_user)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-proposals-0.9.3 app/helpers/decidim/proposals/application_helper.rb
decidim-proposals-0.9.2 app/helpers/decidim/proposals/application_helper.rb
decidim-proposals-0.9.1 app/helpers/decidim/proposals/application_helper.rb
decidim-proposals-0.9.0 app/helpers/decidim/proposals/application_helper.rb