Module: Decidim::DecidimAwesome::Admin::ConfigConstraintsHelpers

Includes:
TranslatableAttributes
Included in:
ConfigController
Defined in:
app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb

Instance Method Summary collapse

Instance Method Details

#check(status) ⇒ Object



9
10
11
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 9

def check(status)
  (:span, icon("check", class: "icon", aria_label: status, role: "img"), class: "text-#{status == :ok ? "success" : "alert"}")
end

#component_manifests(space = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 34

def component_manifests(space = nil)
  return {} if space == "system"

  Decidim.component_manifests.pluck(:name).map do |name|
    [name.to_sym, I18n.t("decidim.components.#{name}.name")]
  end.to_h
end

#components_list(manifest, slug) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 51

def components_list(manifest, slug)
  space = participatory_space_for_manifest(manifest)
  return {} if space.blank?

  components = Component.where(participatory_space: space.find_by(slug: slug))
  components.map do |item|
    [item.id, "#{item.id}: #{translated_attribute(item.name)}"]
  end.to_h
end

#config_enabled?(var) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 20

def config_enabled?(var)
  return DecidimAwesome.config.send(var) != :disabled unless var.is_a? Array

  var.detect { |v| DecidimAwesome.config.send(v) != :disabled }
end

#enabled_configs(vars) ⇒ Object

returns only non :disabled vars in config



14
15
16
17
18
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 14

def enabled_configs(vars)
  vars.filter do |var|
    config_enabled? var
  end
end

#participatory_space_manifestsObject



26
27
28
29
30
31
32
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 26

def participatory_space_manifests
  manifests = { system: I18n.t("decidim.decidim_awesome.admin.config.system") }
  Decidim.participatory_space_manifests.pluck(:name).each do |name|
    manifests[name.to_sym] = I18n.t("decidim.admin.menu.#{name}")
  end
  manifests
end

#participatory_spaces_list(manifest) ⇒ Object



42
43
44
45
46
47
48
49
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 42

def participatory_spaces_list(manifest)
  space = participatory_space_for_manifest(manifest)
  return {} if space.blank?

  space.where(organization: current_organization).map do |item|
    [item.slug, translated_attribute(item.title)]
  end.to_h
end

#translate_constraint_value(constraint, key) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 61

def translate_constraint_value(constraint, key)
  value = constraint.settings[key]
  case key.to_sym
  when :participatory_space_manifest
    participatory_space_manifests[value.to_sym] || value
  when :participatory_space_slug
    manifest = constraint.settings["participatory_space_manifest"]
    participatory_spaces_list(manifest)[value] || value
  when :component_manifest
    component_manifests[value.to_sym] || value
  when :component_id
    component = Component.find_by(id: value)
    return "#{component.id}: #{translated_attribute(component.name)}" if component

    value
  else
    value
  end
end