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

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

Constant Summary collapse

OTHER_MANIFESTS =
[:none, :system, :process_groups].freeze
APPLICATION_CONTEXTS =
[:user_logged_in, :anonymous].freeze

Instance Method Summary collapse

Instance Method Details

#check(status) ⇒ Object



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

def check(status)
  (:span, icon(status ? "check-line" : "close-line", class: "inline-block", aria_label: status, role: "img"), class: "fill-#{status ? "success" : "alert"}")
end

#component_manifests(space = nil) ⇒ Object



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

def component_manifests(space = nil)
  return {} if OTHER_MANIFESTS.include?(space)

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

#components_list(manifest, slug) ⇒ Object



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

def components_list(manifest, slug)
  space = model_for_manifest(manifest)
  return {} unless space&.column_names&.include? "slug"

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

#contexts_listObject



60
61
62
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 60

def contexts_list
  ConfigConstraintsHelpers::APPLICATION_CONTEXTS.index_with { |c| I18n.t("decidim.decidim_awesome.admin.config.#{c}") }
end

#enabled_configs(vars) ⇒ Object

returns only non :disabled vars in config



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

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

#md5(text) ⇒ Object



82
83
84
# File 'app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb', line 82

def md5(text)
  Digest::MD5.hexdigest(text)
end

#participatory_space_manifestsObject



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

def participatory_space_manifests
  manifests = OTHER_MANIFESTS.index_with { |m| I18n.t("decidim.decidim_awesome.admin.config.#{m}") }
  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



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

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

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

#translate_constraint_value(constraint, key) ⇒ Object



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

def translate_constraint_value(constraint, key)
  value = constraint.settings[key]
  translation = case key.to_sym
                when :participatory_space_manifest
                  participatory_space_manifests[value.to_sym]
                when :participatory_space_slug
                  participatory_spaces_list(constraint.settings["participatory_space_manifest"])[value]
                when :component_manifest
                  component_manifests[value.to_sym]
                when :component_id
                  component = Decidim::Component.find_by(id: value)
                  "#{component.id}: #{translated_attribute(component.name)}" if component
                when :application_context
                  I18n.t("decidim.decidim_awesome.admin.config.#{value}")
                end
  translation.presence || value
end