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'
This commit is contained in:
iagirre
2018-01-23 13:51:41 +01:00
parent 06772a7b87
commit 2821985552
5 changed files with 34 additions and 3 deletions

View File

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

View File

@@ -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 %>
<span class="button hollow disabled float-right clear">
<%= t("admin.budgets.winners.calculate")%>
</span>
<div class="callout warning clear">
<%= t("admin.budget_investments.index.cannot_calculate_winners") %>
</div>
<% end %>
<% end %>
<% if @investments.any? %>
<h3 class="inline-block"><%= page_entries_info @investments %></h3><br>
@@ -134,7 +150,7 @@
<%= paginate @investments %>
<% else %>
<div class="callout primary">
<div class="callout primary clear">
<%= t("admin.budget_investments.index.no_budget_investments") %>
</div>
<% end %>

View File

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

View File

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

View File

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