diff --git a/app/cells/decidim/budgets/project_vote_button/show.erb b/app/cells/decidim/budgets/project_vote_button/show.erb
index eebd2c1..da0802f 100644
--- a/app/cells/decidim/budgets/project_vote_button/show.erb
+++ b/app/cells/decidim/budgets/project_vote_button/show.erb
@@ -14,7 +14,11 @@
disabled: vote_button_disabled?,
title: vote_button_label do %>
<% if resource_added? %>
- <%= current_order.score_for(model) %>
+ <% if model.budget.settings.disable_custom_budgets %>
+ <%= icon("x", class: "icon--small", aria_label: vote_button_label, role: "img") %>
+ <% else %>
+ <%= current_order.score_for(model) %>
+ <% end %>
<% else %>
<%= icon("check", class: "icon--small", aria_label: vote_button_label, role: "img") %>
<% end %>
diff --git a/app/views/decidim/budgets/projects/_budget_confirm.html.erb b/app/views/decidim/budgets/projects/_budget_confirm.html.erb
index 8a88e52..818a4ad 100644
--- a/app/views/decidim/budgets/projects/_budget_confirm.html.erb
+++ b/app/views/decidim/budgets/projects/_budget_confirm.html.erb
@@ -11,9 +11,11 @@
<% current_order.sorted_projects.each do |project| %>
-
-
- <%= current_order.score_for(project) %>
-
+ <% unless budget.component.settings.disable_custom_budgets %>
+
+ <%= current_order.score_for(project) %>
+
+ <% end %>
<%= link_to translated_attribute(project.title), resource_locator([budget, project]).path %>
<%= budget_to_currency project.budget_amount %>
diff --git a/app/views/decidim/budgets/projects/_order_selected_projects.html.erb b/app/views/decidim/budgets/projects/_order_selected_projects.html.erb
index 37c1a29..95d7b9d 100644
--- a/app/views/decidim/budgets/projects/_order_selected_projects.html.erb
+++ b/app/views/decidim/budgets/projects/_order_selected_projects.html.erb
@@ -9,9 +9,11 @@
<% current_order.sorted_projects.each do |project| %>
-
-
- <%= current_order.score_for(project) %>
-
+ <% unless budget.component.settings.disable_custom_budgets %>
+
+ <%= current_order.score_for(project) %>
+
+ <% end %>
<%= link_to translated_attribute(project.title), resource_locator([budget, project]).path %>
diff --git a/config/initializers/budgets_overrides.rb b/config/initializers/budgets_overrides.rb
index 8640b92..64b54d8 100644
--- a/config/initializers/budgets_overrides.rb
+++ b/config/initializers/budgets_overrides.rb
@@ -1,25 +1,37 @@
# frozen_string_literal: true
+Decidim.component_registry.find(:budgets).tap do |component|
+ component.settings(:global) do |settings|
+ settings.attribute :disable_custom_budgets, type: :boolean, default: false
+ end
+end
+
Rails.application.config.to_prepare do
Decidim::Budgets::Project.class_eval do
+ alias_method :original_confirmed_orders_count, :confirmed_orders_count
+
def confirmed_votes_count
query = <<-SQL.squish
- SELECT SUM(score) FROM (
- SELECT dbli.*, #{budget.projects.count} - (RANK() OVER (
- PARTITION BY dbli.decidim_order_id
- ORDER BY dbli.id ASC
+ SELECT SUM(score) FROM (
+ SELECT dbli.*, #{budget.projects.count} - (RANK() OVER (
+ PARTITION BY dbli.decidim_order_id
+ ORDER BY dbli.id ASC
) - 1) score
FROM decidim_budgets_orders dbo
JOIN decidim_budgets_line_items dbli ON dbo.id = dbli.decidim_order_id AND dbo.checked_out_at IS NOT NULL
JOIN decidim_budgets_projects dbp ON dbp.id = dbli.decidim_project_id
- ) ranks
- WHERE decidim_project_id = #{id}
+ ) ranks
+ WHERE decidim_project_id = #{id}
SQL
@confirmed_votes_count ||= ActiveRecord::Base.connection.execute(Arel.sql(query))[0]["sum"].to_i
end
def confirmed_orders_count
- confirmed_votes_count
+ if budget.component.settings.disable_custom_budgets
+ original_confirmed_orders_count
+ else
+ confirmed_votes_count
+ end
end
end
@@ -56,6 +68,8 @@ def project_count
Decidim::Budgets::ProjectVotesCountCell.class_eval do
delegate :current_order, to: :controller
+ alias_method :original_content, :content
+
def votes_count
@votes_count ||= if current_order.checked_out?
model.confirmed_orders_count
@@ -65,6 +79,8 @@ def votes_count
end
def content
+ return original_content if model.budget.component.settings.disable_custom_budgets
+
if options[:layout] == :one_line
safe_join([votes_count, " ", label(t("decidim.budgets.projects.project.votes", count: votes_count))])
else
@@ -78,9 +94,13 @@ def number
end
Decidim::Budgets::ProjectVotedHintCell.class_eval do
+ alias_method :original_hint, :hint
+
private
def hint
+ return original_hint if model.budget.component.settings.disable_custom_budgets
+
contents = []
contents << icon("check", role: "img", "aria-hidden": true)
contents << " "
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 36b55bf..f63d6d6 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -16,6 +16,11 @@ es:
month: Mes
year: Año
decidim:
+ components:
+ budgets:
+ settings:
+ global:
+ disable_custom_budgets: Deshabilitar presupuestos personalizados
authorization_handlers:
census_authorization_handler:
connection_error: No ha sido posible realizar la verificación