Module: Decidim::DecidimAwesome::MapHelper

Includes:
MapHelper
Included in:
ContentBlocks::MapCell
Defined in:
app/helpers/decidim/decidim_awesome/map_helper.rb

Instance Method Summary collapse

Instance Method Details

#api_ready?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/helpers/decidim/decidim_awesome/map_helper.rb', line 8

def api_ready?
  Decidim::Api::Schema.max_complexity >= 1300
end

#awesome_map_for(components) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/decidim/decidim_awesome/map_helper.rb', line 14

def awesome_map_for(components, &)
  return unless map_utility_dynamic

  map = awesome_builder.map_element({ class: "dynamic-map", id: "awesome-map-container" }, &)
  help = (:div, class: "map__skip-container") do
    (:p, t("screen_reader_explanation", scope: "decidim.map.dynamic"), class: "sr-only")
  end

  html_options = {
    class: "awesome-map",
    id: "awesome-map",
    data: {
      "components" => components.map do |component|
                        {
                          id: component.id,
                          type: component.manifest.name,
                          name: translated_attribute(component.name),
                          url: Decidim::EngineRouter.main_proxy(component).root_path,
                          amendments: component.manifest.name == :proposals ? Decidim::Proposals::Proposal.where(component:).only_emendations.count : 0
                        }
                      end.to_json,
      "hide-controls" => settings_source.try(:hide_controls),
      "collapsed" => global_settings.collapse,
      "truncate" => global_settings.truncate || 255,
      "map-center" => global_settings.map_center,
      "map-zoom" => global_settings.map_zoom || 8,
      "menu-merge-components" => global_settings.menu_merge_components,
      "menu-amendments" => global_settings.menu_amendments,
      "menu-meetings" => global_settings.menu_meetings,
      "menu-taxonomies" => global_settings.menu_taxonomies,
      "menu-hashtags" => global_settings.menu_hashtags,
      "show-not-answered" => step_settings&.show_not_answered,
      "show-accepted" => step_settings&.show_accepted,
      "show-withdrawn" => step_settings&.show_withdrawn,
      "show-evaluating" => step_settings&.show_evaluating,
      "show-rejected" => step_settings&.show_rejected
    }
  }

  (:div, html_options) do
     :div, class: "w-full" do
      help + map
    end
  end
end

#current_taxonomies(taxonomies) ⇒ Object

rubocop:disable Rails/HelperInstanceVariable



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/helpers/decidim/decidim_awesome/map_helper.rb', line 75

def current_taxonomies(taxonomies)
  return @current_taxonomies if @current_taxonomies

  @golden_ratio_conjugate = 0.618033988749895
  # @h = rand # use random start value
  @h = 0.41
  @current_taxonomies = []
  taxonomies.each do |taxonomy|
    append_taxonomy taxonomy
    taxonomy&.children&.each do |subtax|
      append_taxonomy subtax
      subtax&.children&.each do |subsubtax|
        append_taxonomy subsubtax
      end
    end
  end
  @current_taxonomies
end

#global_settingsObject



66
67
68
# File 'app/helpers/decidim/decidim_awesome/map_helper.rb', line 66

def global_settings
  settings_source.try(:settings)
end

#settings_sourceObject



70
71
72
# File 'app/helpers/decidim/decidim_awesome/map_helper.rb', line 70

def settings_source
  try(:current_component) || self
end

#step_settingsObject

rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity



62
63
64
# File 'app/helpers/decidim/decidim_awesome/map_helper.rb', line 62

def step_settings
  settings_source.try(:current_settings)
end