app/helpers/decidim/budgets/projects_helper.rb in decidim-budgets-0.26.10 vs app/helpers/decidim/budgets/projects_helper.rb in decidim-budgets-0.27.0.rc1

- old
+ new

@@ -2,10 +2,13 @@ module Decidim module Budgets # A helper to render order and budgets actions module ProjectsHelper + include Decidim::ApplicationHelper + include Decidim::MapHelper + # Render a budget as a currency # # budget - A integer to represent a budget def budget_to_currency(budget) number_to_currency budget, unit: Decidim.currency_unit, precision: 0 @@ -77,9 +80,35 @@ elsif current_order.minimum_projects_rule? t(".minimum_projects_rule.description", minimum_number: current_order.minimum_projects) else t(".vote_threshold_percent_rule.description", minimum_budget: budget_to_currency(current_order.minimum_budget)) end + end + + # Serialize a collection of geocoded projects to be used by the dynamic map component + # + # geocoded_projects - A collection of geocoded projects + def projects_data_for_map(geocoded_projects) + geocoded_projects.map do |project| + project_data_for_map(project) + end + end + + def project_data_for_map(project) + project + .slice(:latitude, :longitude, :address) + .merge( + title: decidim_html_escape(translated_attribute(project.title)), + description: html_truncate(decidim_sanitize_editor(translated_attribute(project.description)), length: 100), + icon: icon("project", width: 40, height: 70, remove_icon_class: true), + link: ::Decidim::ResourceLocatorPresenter.new([project.budget, project]).path + ) + end + + def has_position?(project) + return if project.address.blank? + + project.latitude.present? && project.longitude.present? end end end end