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, &block) ⇒ 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, &block)
  return unless map_utility_dynamic

  map = awesome_builder.map_element({ class: "google-map", id: "awesome-map-container" }, &block)
  help = (:div, class: "map__help") do
    sr_content = (:p, t("screen_reader_explanation", scope: "decidim.map.dynamic"), class: "show-for-sr")

    sr_content
  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: component).only_emendations.count : 0
                           }
                         end.to_json,
    "data-hide-controls" => settings_source.try(:hide_controls),
    "data-collapsed" => global_settings.collapse,
    "data-truncate" => global_settings.truncate || 255,
    "data-map-center" => global_settings.map_center,
    "data-map-zoom" => global_settings.map_zoom || 8,
    "data-menu-merge-components" => global_settings.menu_merge_components,
    "data-menu-amendments" => global_settings.menu_amendments,
    "data-menu-meetings" => global_settings.menu_meetings,
    "data-menu-categories" => global_settings.menu_categories,
    "data-menu-hashtags" => global_settings.menu_hashtags,
    "data-show-not-answered" => step_settings&.show_not_answered,
    "data-show-accepted" => step_settings&.show_accepted,
    "data-show-withdrawn" => step_settings&.show_withdrawn,
    "data-show-evaluating" => step_settings&.show_evaluating,
    "data-show-rejected" => step_settings&.show_rejected
  }

  (:div, html_options) do
     :div, class: "row column" do
      help + map
    end
  end
end

#current_categories(categories) ⇒ Object

rubocop:disable Rails/HelperInstanceVariable



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

def current_categories(categories)
  return @current_categories if @current_categories

  @golden_ratio_conjugate = 0.618033988749895
  # @h = rand # use random start value
  @h = 0.41
  @current_categories = []
  categories.first_class.each do |category|
    append_category category
    category.subcategories.each do |subcat|
      append_category subcat
    end
  end
  @current_categories
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