Module: Decidim::Plans::ApplicationHelper

Includes:
Comments::CommentsHelper, MapHelper, LinksHelper, PaginateHelper
Included in:
PlanCellsHelper
Defined in:
app/helpers/decidim/plans/application_helper.rb

Overview

Custom helpers, scoped to the plans engine.

Instance Method Summary collapse

Methods included from LinksHelper

#request_params, #request_params_query

Instance Method Details

#authors_for(plan) ⇒ Object



52
53
54
# File 'app/helpers/decidim/plans/application_helper.rb', line 52

def authors_for(plan)
  plan.identities.map { |identity| present(identity) }
end

#current_user_plansObject



42
43
44
45
46
47
48
49
50
# File 'app/helpers/decidim/plans/application_helper.rb', line 42

def current_user_plans
  Plan.joins(:coauthorships).where(
    component: current_component,
    decidim_coauthorships: {
      decidim_author_id: current_user.id,
      decidim_author_type: "Decidim::UserBaseEntity"
    }
  )
end

#filter_state_valuesObject



56
57
58
59
60
61
62
63
64
# File 'app/helpers/decidim/plans/application_helper.rb', line 56

def filter_state_values
  [
    ["except_rejected", t("decidim.plans.application_helper.filter_state_values.except_rejected")],
    ["accepted", t("decidim.plans.application_helper.filter_state_values.accepted")],
    ["evaluating", t("decidim.plans.application_helper.filter_state_values.evaluating")],
    ["rejected", t("decidim.plans.application_helper.filter_state_values.rejected")],
    ["all", t("decidim.plans.application_helper.filter_state_values.all")]
  ]
end

#filter_type_valuesObject



66
67
68
69
70
71
72
# File 'app/helpers/decidim/plans/application_helper.rb', line 66

def filter_type_values
  [
    ["all", t("decidim.plans.application_helper.filter_type_values.all")],
    ["plans", t("decidim.plans.application_helper.filter_type_values.plans")],
    ["amendments", t("decidim.plans.application_helper.filter_type_values.amendments")]
  ]
end

#humanize_plan_state(state) ⇒ Object

Public: The state of a plan in a way a human can understand.

state - The String state of the plan.

Returns a String.



18
19
20
# File 'app/helpers/decidim/plans/application_helper.rb', line 18

def humanize_plan_state(state)
  I18n.t(state, scope: "decidim.plans.answers", default: :not_answered)
end

#plan_filter_form_for(filter, url = url_for) ⇒ Object

We need a custom filter form helper because of the following bug in the core: github.com/decidim/decidim/issues/4584



76
77
78
79
80
81
82
83
# File 'app/helpers/decidim/plans/application_helper.rb', line 76

def plan_filter_form_for(filter, url = url_for)
  namespace = SecureRandom.hex(10)
   :div, class: "filters" do
    form_for filter, namespace: "filters_#{namespace}", builder: FilterFormBuilder, url: url, as: :filter, method: :get, remote: true, html: { id: nil } do |form|
      yield form
    end
  end
end

#plan_state_css_class(state) ⇒ Object

Public: The css class applied based on the plan state.

state - The String state of the plan.

Returns a String.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/decidim/plans/application_helper.rb', line 27

def plan_state_css_class(state)
  case state
  when "accepted"
    "text-success"
  when "rejected"
    "text-alert"
  when "evaluating"
    "text-warning"
  when "withdrawn"
    "text-alert"
  else
    "text-info"
  end
end

#tabs_id_for_content(idx) ⇒ Object



85
86
87
# File 'app/helpers/decidim/plans/application_helper.rb', line 85

def tabs_id_for_content(idx)
  "content_#{idx}"
end