From 2821985552484886f9a51ba313b554d50a0194b8 Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 23 Jan 2018 13:51:41 +0100 Subject: [PATCH 1/2] Change 'Calculate Winners button' to budget_investments index. Move the button so that it appears in the Winners tab of the budget_investments index. When the budget is in "Balloting projects", "Reviewing Ballots" or "Finished budget" phases, the button will appear as a button (clickable). If there are no winners calculated yet, the text will be "Calculate winner investments"; if there are, the text will be "Recalculate winner investments". If the budget is in another phase, the button will be disabled and a message will appear: 'The budget has to stay on phase "Balloting projects", "Reviewing Ballots" or "Finished budget" in order to calculate winners projects' --- app/helpers/budgets_helper.rb | 12 +++++++++++ .../budget_investments/_investments.html.erb | 20 +++++++++++++++++-- app/views/admin/budgets/_form.html.erb | 1 - config/locales/en/admin.yml | 2 ++ config/locales/es/admin.yml | 2 ++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 8cff4b72b..b4a207ed6 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -68,4 +68,16 @@ module BudgetsHelper return unless current_budget.present? MapLocation.where(investment_id: current_budget.investments).map { |l| l.json_data } end + + def display_calculate_winners_button?(budget) + budget.balloting_or_later? + end + + def calculate_winner_button_text(budget) + if budget.investments.winners.empty? + t("admin.budgets.winners.calculate") + else + t("admin.budgets.winners.recalculate") + end + end end diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index da7a49749..cf1713381 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -9,7 +9,23 @@ <%= link_to t("admin.budget_investments.index.download_current_selection"), admin_budget_budget_investments_path(csv_params), - class: "float-right small" %> + class: "float-right small clear" %> + +<% if params[:filter] == 'winners' %> + <% if display_calculate_winners_button?(@budget) %> + <%= link_to calculate_winner_button_text(@budget), + calculate_winners_admin_budget_path(@budget), + method: :put, + class: "button hollow float-right clear" %> + <% else %> + + <%= t("admin.budgets.winners.calculate")%> + +
+ <%= t("admin.budget_investments.index.cannot_calculate_winners") %> +
+ <% end %> +<% end %> <% if @investments.any? %>

<%= page_entries_info @investments %>


@@ -134,7 +150,7 @@ <%= paginate @investments %> <% else %> -
+
<%= t("admin.budget_investments.index.no_budget_investments") %>
<% end %> diff --git a/app/views/admin/budgets/_form.html.erb b/app/views/admin/budgets/_form.html.erb index f5ce6b027..52a96c077 100644 --- a/app/views/admin/budgets/_form.html.erb +++ b/app/views/admin/budgets/_form.html.erb @@ -68,7 +68,6 @@ budget_results_path(@budget), class: "button hollow margin-left" %> <% end %> - <% if @budget.persisted? %> <%= link_to t("admin.budgets.edit.delete"), admin_budget_path(@budget), diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0292df944..bf4202a60 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -124,6 +124,7 @@ en: winners: calculate: Calculate Winner Investments calculated: Winners being calculated, it may take a minute. + recalculate: Recalculate Winner Investments budget_phases: edit: start_date: Start date @@ -190,6 +191,7 @@ en: table_selection: "Selected" table_evaluation: "Show to valuators" table_incompatible: "Incompatible" + cannot_calculate_winners: The budget has to stay on phase "Balloting projects", "Reviewing Ballots" or "Finished budget" in order to calculate winners projects show: assigned_admin: Assigned administrator assigned_valuators: Assigned valuators diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 5d44c9a17..002fb21ed 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -124,6 +124,7 @@ es: winners: calculate: Calcular propuestas ganadoras calculated: Calculando ganadoras, puede tardar un minuto. + recalculate: Recalcular propuestas ganadoras budget_phases: edit: start_date: Fecha de Inicio @@ -190,6 +191,7 @@ es: table_selection: "Seleccionado" table_evaluation: "Mostrar a evaluadores" table_incompatible: "Incompatible" + cannot_calculate_winners: El presupuesto debe estar en las fases "Votación final", "Votación finalizada" o "Resultados" para poder calcular las propuestas ganadoras show: assigned_admin: Administrador asignado assigned_valuators: Evaluadores asignados From 73b0fe5162e5d0b5ceccec61c71019bb9d40d415 Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 23 Jan 2018 16:50:44 +0100 Subject: [PATCH 2/2] Modified feature spec to pass with the new UI Add feature spec to test if the 'Calculate winners' button is enabled or not, depending on the phase. It also checks the message that clarifies why the button is disabled. --- spec/features/admin/budget_investments_spec.rb | 17 +++++++++++++++++ spec/features/admin/budgets_spec.rb | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index fe386bbaa..4a1beaacd 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -366,6 +366,23 @@ feature 'Admin budget investments' do expect(page).not_to have_select("tag_name", options: ["All tags", "Accessibility"]) end + scenario "Disable 'Calculate winner' button if incorrect phase" do + budget.update(phase: 'reviewing_ballots') + + visit admin_budget_budget_investments_path(budget) + click_link 'Winners' + + expect(page).to have_link "Calculate Winner Investments" + + budget.update(phase: 'accepting') + + visit admin_budget_budget_investments_path(budget) + click_link 'Winners' + + expect(page).not_to have_link "Calculate Winner Investments" + expect(page).to have_content 'The budget has to stay on phase "Balloting projects", "Reviewing Ballots" or "Finished budget" in order to calculate winners projects' + end + scenario "Limiting by max number of investments per heading", :js do group_1 = create(:budget_group, budget: budget) group_2 = create(:budget_group, budget: budget) diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index 6288a2c8e..9872a9d27 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -186,7 +186,8 @@ feature 'Admin budgets' do end context "Calculate Budget's Winner Investments" do - scenario 'For a Budget in reviewing balloting' do + + scenario 'For a Budget in reviewing balloting', :js do budget = create(:budget, phase: 'reviewing_ballots') group = create(:budget_group, budget: budget) heading = create(:budget_heading, group: group, price: 4)