diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 6f6203f6e..0918ffb1d 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -110,6 +110,7 @@
//= require cookies
//= require columns_selector
//= require budget_edit_associations
+//= require budget_hide_money
//= require datepicker
//= require_tree ./admin
//= require_tree ./sdg
@@ -166,6 +167,7 @@ var initialize_modules = function() {
App.AdminBudgetsWizardCreationStep.initialize();
App.AdminMachineLearningScripts.initialize();
App.BudgetEditAssociations.initialize();
+ App.BudgetHideMoney.initialize();
App.Datepicker.initialize();
App.SDGRelatedListSelector.initialize();
App.SDGManagementRelationSearch.initialize();
diff --git a/app/assets/javascripts/budget_hide_money.js b/app/assets/javascripts/budget_hide_money.js
new file mode 100644
index 000000000..2c433ac9b
--- /dev/null
+++ b/app/assets/javascripts/budget_hide_money.js
@@ -0,0 +1,17 @@
+(function() {
+ "use strict";
+ App.BudgetHideMoney = {
+ initialize: function() {
+ $("#budget_voting_style").on({
+ change: function() {
+ if ($(this).val() === "approval") {
+ $("#hide_money").removeClass("hide");
+ } else {
+ $("#budget_hide_money").prop("checked", false);
+ $("#hide_money").addClass("hide");
+ }
+ }
+ });
+ }
+ };
+}).call(this);
diff --git a/app/components/admin/budgets/form_component.html.erb b/app/components/admin/budgets/form_component.html.erb
index 5df2e0e92..dd9bbddc9 100644
--- a/app/components/admin/budgets/form_component.html.erb
+++ b/app/components/admin/budgets/form_component.html.erb
@@ -39,6 +39,14 @@
+
+
+
<%= t("admin.budgets.edit.hide_money") %>
+
<%= t("admin.budgets.edit.hide_money_help_text") %>
+ <%= f.check_box :hide_money %>
+
+
+
<% unless wizard? %>
<%= f.select :phase, phases_select_options %>
diff --git a/app/components/admin/budgets/form_component.rb b/app/components/admin/budgets/form_component.rb
index d57457e7a..4b598e3b6 100644
--- a/app/components/admin/budgets/form_component.rb
+++ b/app/components/admin/budgets/form_component.rb
@@ -34,4 +34,8 @@ class Admin::Budgets::FormComponent < ApplicationComponent
def valuators
@valuators ||= Valuator.includes(:user).order(description: :asc).order("users.email ASC")
end
+
+ def hide_money_style
+ "hide" if budget.voting_style == "knapsack"
+ end
end
diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb
index 00d238260..139abde34 100644
--- a/app/controllers/admin/budgets_controller.rb
+++ b/app/controllers/admin/budgets_controller.rb
@@ -59,6 +59,7 @@ class Admin::BudgetsController < Admin::BaseController
valid_attributes = [:phase,
:currency_symbol,
:voting_style,
+ :hide_money,
administrator_ids: [],
valuator_ids: [],
image_attributes: image_attributes
diff --git a/app/controllers/admin/budgets_wizard/budgets_controller.rb b/app/controllers/admin/budgets_wizard/budgets_controller.rb
index 92003fe5a..90f188f60 100644
--- a/app/controllers/admin/budgets_wizard/budgets_controller.rb
+++ b/app/controllers/admin/budgets_wizard/budgets_controller.rb
@@ -37,7 +37,7 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BudgetsWizard::BaseContro
end
def allowed_params
- valid_attributes = [:currency_symbol, :voting_style, administrator_ids: [],
+ valid_attributes = [:currency_symbol, :voting_style, :hide_money, administrator_ids: [],
valuator_ids: [], image_attributes: image_attributes]
valid_attributes + [translation_params(Budget)]
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index 973455a05..d02d6499c 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -160,6 +160,7 @@ en:
voting_style: "Final voting style"
voting_style_knapsack: "Knapsack"
voting_style_approval: "Approval"
+ hide_money: "Hide money amount for this budget"
budget/translation:
main_link_text: "Text on the link"
main_link_url: "The link takes you to (add a link)"
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index a740a897a..e26670d17 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -136,6 +136,8 @@ en:
info:
budget_settings: "General participatory budget settings"
staff_settings: "Administrators and Valuators assigned to the budget"
+ hide_money: "Hide money"
+ hide_money_help_text: "If this option is checked, all fields showing the amount of money will be hidden throughout the process."
destroy:
success_notice: Budget deleted successfully
unable_notice: You cannot delete a budget that has associated investments
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index 82c682edf..b7cf2fc07 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -160,6 +160,7 @@ es:
voting_style: "Estilo de la votación final"
voting_style_knapsack: Bolsa de dinero
voting_style_approval: Por aprobación
+ hide_money: "Ocultar la cantidad de dinero para este presupuesto"
budget/translation:
main_link_text: "Texto del enlace"
main_link_url: "El enlace te lleva a (añade un enlace)"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 9ff38ec50..fd7a0d28c 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -136,6 +136,8 @@ es:
info:
budget_settings: "Configuración genérica del presupuesto participativo"
staff_settings: "Administradores y Evaluadores asigandos al presupuesto"
+ hide_money: "Ocultar dinero"
+ hide_money_help_text: "Si esta opción está marcada, todos los campos que muestran la cantidad de dinero se ocultarán durante todo el proceso."
destroy:
success_notice: Presupuesto eliminado correctamente
unable_notice: No se puede eliminar un presupuesto con proyectos asociados
diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb
index 81f2089ec..59ae4b977 100644
--- a/spec/factories/budgets.rb
+++ b/spec/factories/budgets.rb
@@ -68,6 +68,10 @@ FactoryBot.define do
trait :with_winner do
after(:create) { |budget| create(:budget_investment, :winner, budget: budget) }
end
+
+ trait :hide_money do
+ hide_money { true }
+ end
end
factory :budget_group, class: "Budget::Group" do
diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb
index db39f419f..ede90d9c9 100644
--- a/spec/system/admin/budgets_spec.rb
+++ b/spec/system/admin/budgets_spec.rb
@@ -94,6 +94,76 @@ describe "Admin budgets", :admin do
end
end
+ context "Create" do
+ scenario "Create budget - Approval voting with hide money" do
+ visit admin_budgets_path
+ click_button "Create new budget"
+ click_link "Create multiple headings budget"
+
+ expect(page).to have_select("Final voting style", selected: "Knapsack")
+ expect(page).not_to have_selector("#budget_hide_money")
+
+ fill_in "Name", with: "Budget hide money"
+ select "Approval", from: "Final voting style"
+ check "Hide money amount for this budget"
+ click_button "Continue to groups"
+
+ expect(page).to have_content "New participatory budget created successfully!"
+ expect(page).to have_content "Budget hide money"
+
+ click_link "Go back to edit budget"
+
+ expect(page).to have_select("Final voting style", selected: "Approval")
+ expect(page).to have_field "Hide money amount for this budget", checked: true
+ end
+
+ scenario "Create a budget with hide money by steps" do
+ visit admin_budgets_path
+ click_button "Create new budget"
+ click_link "Create multiple headings budget"
+
+ fill_in "Name", with: "Multiple headings budget with hide money"
+ select "Approval", from: "Final voting style"
+ check "Hide money amount for this budget"
+ click_button "Continue to groups"
+
+ expect(page).to have_content "New participatory budget created successfully!"
+ expect(page).to have_content "There are no groups."
+
+ click_button "Add new group"
+ fill_in "Group name", with: "All city"
+ click_button "Create new group"
+
+ expect(page).to have_content "Group created successfully!"
+
+ click_button "Add new group"
+ fill_in "Group name", with: "District A"
+ click_button "Create new group"
+
+ expect(page).to have_content "Group created successfully!"
+
+ within("table") do
+ expect(page).to have_content "All city"
+ expect(page).to have_content "District A"
+ end
+ expect(page).not_to have_content "There are no groups."
+
+ click_link "Continue to headings"
+
+ expect(page).to have_content "Showing headings from the All city group."
+ expect(page).to have_link "Manage headings from the District A group."
+
+ click_button "Add new heading"
+ fill_in "Heading name", with: "All city"
+ click_button "Create new heading"
+
+ expect(page).to have_content "Heading created successfully!"
+ expect(page).to have_content "All city"
+ expect(page).to have_link "Continue to phases"
+ expect(page).not_to have_content "There are no headings."
+ end
+ end
+
context "Publish" do
let(:budget) { create(:budget, :drafting) }
@@ -260,6 +330,76 @@ describe "Admin budgets", :admin do
expect(page).to have_content "New English Name"
end
+
+ scenario "Hide money active" do
+ budget_hide_money = create(:budget, :approval, :hide_money)
+ group = create(:budget_group, budget: budget_hide_money)
+ heading = create(:budget_heading, group: group)
+ heading_2 = create(:budget_heading, group: group)
+
+ visit admin_budget_path(budget_hide_money)
+
+ expect(page).to have_content heading.name
+ expect(page).to have_content heading_2.name
+
+ visit edit_admin_budget_path(budget_hide_money)
+
+ expect(page).to have_field "Hide money amount for this budget", checked: true
+ expect(page).to have_select("Final voting style", selected: "Approval")
+ end
+
+ scenario "Change voting style uncheck hide money" do
+ budget_hide_money = create(:budget, :approval, :hide_money)
+ hide_money_help_text = "If this option is checked, all fields showing the amount of money "\
+ "will be hidden throughout the process."
+
+ visit edit_admin_budget_path(budget_hide_money)
+
+ expect(page).to have_field "Hide money amount for this budget", checked: true
+ expect(page).to have_content hide_money_help_text
+
+ select "Knapsack", from: "Final voting style"
+
+ expect(page).not_to have_field "Hide money amount for this budget"
+ expect(page).not_to have_content hide_money_help_text
+
+ select "Approval", from: "Final voting style"
+
+ expect(page).to have_field "Hide money amount for this budget", checked: false
+ expect(page).to have_content hide_money_help_text
+ end
+
+ scenario "Edit knapsack budget do not show hide money info" do
+ budget = create(:budget, :knapsack)
+ hide_money_help_text = "If this option is checked, all fields showing the amount of money "\
+ "will be hidden throughout the process."
+
+ visit edit_admin_budget_path(budget)
+
+ expect(page).not_to have_field "Hide money amount for this budget"
+ expect(page).not_to have_content hide_money_help_text
+
+ select "Approval", from: "Final voting style"
+
+ expect(page).to have_field "Hide money amount for this budget", checked: false
+ expect(page).to have_content hide_money_help_text
+ end
+
+ scenario "Edit approval budget show hide money info" do
+ budget = create(:budget, :approval)
+ hide_money_help_text = "If this option is checked, all fields showing the amount of money "\
+ "will be hidden throughout the process."
+
+ visit edit_admin_budget_path(budget)
+
+ expect(page).to have_field "Hide money amount for this budget", checked: false
+ expect(page).to have_content hide_money_help_text
+
+ select "Knapsack", from: "Final voting style"
+
+ expect(page).not_to have_field "Hide money amount for this budget"
+ expect(page).not_to have_content hide_money_help_text
+ end
end
context "Update" do