Module: Decidim::Budgets::ProjectsHelper
- Includes:
- ApplicationHelper, MapHelper
- Included in:
- ApplicationHelper, BudgetListItemCell, ProjectLCell, ProjectMetadataCell, ProjectVoteButtonCell
- Defined in:
- decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb
Overview
A helper to render order and budgets actions
Constant Summary
Constants included from AmendmentsHelper
Instance Method Summary collapse
- #budget_confirm_disabled_attr ⇒ Object
-
#budget_to_currency(budget) ⇒ Object
Render a budget as a currency.
- #budgets_select_tag(name, options: {}) ⇒ Object
-
#current_order_budget_percent ⇒ Object
Return a percentage of the current order budget from the total budget.
-
#current_order_budget_percent_minimum ⇒ Object
Return the minimum percentage of the current order budget from the total budget.
-
#current_order_can_be_checked_out? ⇒ Boolean
Return true if the user can continue to the checkout process.
-
#current_order_minimum_reached? ⇒ Boolean
Returns false if the current order does not have a rule for minimum budget Returns false if the current order has not reached the minimum budget Otherwise returns true.
- #current_rule_call_for_action_text ⇒ Object
- #current_rule_description ⇒ Object
- #filter_addition_type_values ⇒ Object
- #filter_sections ⇒ Object
- #has_position?(project) ⇒ Boolean
- #project_data_for_map(project) ⇒ Object
-
#projects_data_for_map(geocoded_projects) ⇒ Object
Serialize a collection of geocoded projects to be used by the dynamic map component.
- #reference_budgets_for_select ⇒ Object
Methods included from MapHelper
#dynamic_map_for, #static_map_link
Methods included from ApplicationHelper
#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials
Methods included from CacheHelper
Methods included from AmendmentsHelper
#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title
Methods included from RichTextEditorHelper
Methods included from ContextualHelpHelper
Methods included from ScopesHelper
#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_select_field, #scopes_select_tag
Methods included from TranslatableAttributes
Methods included from DecidimFormHelper
#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #ordered_scopes_descendants, #ordered_scopes_descendants_for_select, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag
Methods included from OmniauthHelper
#normalize_provider_name, #oauth_icon, #provider_name
Instance Method Details
#budget_confirm_disabled_attr ⇒ Object
33 34 35 36 37 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 33 def budget_confirm_disabled_attr return if current_order_can_be_checked_out? %( disabled="disabled" ).html_safe end |
#budget_to_currency(budget) ⇒ Object
Render a budget as a currency
budget - A integer to represent a budget
13 14 15 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 13 def budget_to_currency(budget) number_to_currency budget, unit: Decidim.currency_unit, precision: 0 end |
#budgets_select_tag(name, options: {}) ⇒ Object
153 154 155 156 157 158 159 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 153 def budgets_select_tag(name, options: {}) select_tag( name, (reference_budgets_for_select), .merge(include_blank: I18n.t("decidim.budgets.prompt")) ) end |
#current_order_budget_percent ⇒ Object
Return a percentage of the current order budget from the total budget
18 19 20 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 18 def current_order_budget_percent current_order&.budget_percent.to_f.floor end |
#current_order_budget_percent_minimum ⇒ Object
Return the minimum percentage of the current order budget from the total budget
23 24 25 26 27 28 29 30 31 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 23 def current_order_budget_percent_minimum return 0 if current_order.minimum_projects_rule? if current_order.projects_rule? (current_order.minimum_projects.to_f / current_order.maximum_projects) else component_settings.vote_threshold_percent end end |
#current_order_can_be_checked_out? ⇒ Boolean
Return true if the user can continue to the checkout process
43 44 45 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 43 def current_order_can_be_checked_out? current_order&.can_checkout? end |
#current_order_minimum_reached? ⇒ Boolean
Returns false if the current order does not have a rule for minimum budget Returns false if the current order has not reached the minimum budget Otherwise returns true
50 51 52 53 54 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 50 def current_order_minimum_reached? return false if current_order.minimum_budget.zero? current_order.total > current_order.minimum_budget end |
#current_rule_call_for_action_text ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 56 def current_rule_call_for_action_text return "" unless current_order if current_order_minimum_reached? t("minimum_reached", scope: "decidim.budgets.projects.order_progress.dynamic_help") elsif current_order.projects.empty? t("start_adding_projects", scope: "decidim.budgets.projects.order_progress.dynamic_help") else t("keep_adding_projects", scope: "decidim.budgets.projects.order_progress.dynamic_help") end end |
#current_rule_description ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 68 def current_rule_description return unless current_order rule_text = if current_order_minimum_reached? "" elsif current_order.projects_rule? if current_order.minimum_projects.positive? && current_order.minimum_projects < current_order.maximum_projects t( "projects_rule.description", scope: "decidim.budgets.projects.order_progress", minimum_number: current_order.minimum_projects, maximum_number: current_order.maximum_projects ) else t( "projects_rule_maximum_only.description", scope: "decidim.budgets.projects.order_progress", maximum_number: current_order.maximum_projects ) end elsif current_order.minimum_projects_rule? t( "minimum_projects_rule.description", scope: "decidim.budgets.projects.order_progress", minimum_number: current_order.minimum_projects ) else t( "vote_threshold_percent_rule.description", scope: "decidim.budgets.projects.order_progress", minimum_budget: budget_to_currency(current_order.minimum_budget) ) end %(<strong>#{current_rule_call_for_action_text}</strong>. #{rule_text}).html_safe end |
#filter_addition_type_values ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 129 def filter_addition_type_values return [] if voting_finished? [ ["all", t("all", scope: "decidim.budgets.projects.project_filter")], ["added", t("added", scope: "decidim.budgets.projects.project_filter")] ] end |
#filter_sections ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 138 def filter_sections @filter_sections ||= begin items = [] items.append(method: :with_any_status, collection: filter_status_values, label: t("decidim.budgets.projects.filters.status"), id: "status") if voting_finished? current_component.available_taxonomy_filters.each do |taxonomy_filter| items.append(method: "with_any_taxonomies[#{taxonomy_filter.root_taxonomy_id}]", collection: filter_taxonomy_values_for(taxonomy_filter), label: decidim_sanitize_translated(taxonomy_filter.name), id: "taxonomy-#{taxonomy_filter.root_taxonomy_id}") end end items.reject { |item| item[:collection].blank? } end |
#has_position?(project) ⇒ Boolean
123 124 125 126 127 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 123 def has_position?(project) return if project.address.blank? project.latitude.present? && project.longitude.present? end |
#project_data_for_map(project) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 113 def project_data_for_map(project) project .slice(:latitude, :longitude, :address) .merge( title: decidim_escape_translated(project.title), link: ::Decidim::ResourceLocatorPresenter.new([project.budget, project]).path, items: cell("decidim/budgets/project_metadata", project).send(:project_items_for_map).to_json ) end |
#projects_data_for_map(geocoded_projects) ⇒ Object
Serialize a collection of geocoded projects to be used by the dynamic map component
geocoded_projects - A collection of geocoded projects
107 108 109 110 111 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 107 def projects_data_for_map(geocoded_projects) geocoded_projects.map do |project| project_data_for_map(project) end end |
#reference_budgets_for_select ⇒ Object
161 162 163 164 165 166 167 |
# File 'decidim-budgets/app/helpers/decidim/budgets/projects_helper.rb', line 161 def reference_budgets_for_select references = Budget.joins(:component) .where(component: { participatory_space: current_participatory_space }).order(weight: :asc) references.map do |budget| ["#{" " * 4} #{decidim_escape_translated(budget.title)}".html_safe, budget.id] end end |