Allow enable 'hide_money' check on admin budget form

Add new 'hide_money' field to admin budget form.

Only display new field 'hide_money' when voting style is 'approval'
This commit is contained in:
decabeza
2022-02-02 13:12:03 +01:00
committed by taitus
parent c98e8a004f
commit 80e64590b7
12 changed files with 183 additions and 1 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -39,6 +39,14 @@
</div>
</div>
<div id="hide_money" class="row expanded <%= hide_money_style %>">
<div class="small-12 column">
<p class="form-label"><%= t("admin.budgets.edit.hide_money") %></p>
<p class="help-text"><%= t("admin.budgets.edit.hide_money_help_text") %></p>
<%= f.check_box :hide_money %>
</div>
</div>
<% unless wizard? %>
<div class="small-12 medium-6 column">
<%= f.select :phase, phases_select_options %>

View File

@@ -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

View File

@@ -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

View File

@@ -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)]

View File

@@ -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)"

View File

@@ -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

View File

@@ -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)"

View File

@@ -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

View File

@@ -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

View File

@@ -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