Extract method to get a budget phase title

This commit is contained in:
Javi Martín
2021-03-05 18:49:12 +01:00
parent 70cf956210
commit 014d29b991
12 changed files with 16 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
<ul class="no-bullet budget-phases">
<% budget.published_phases.each do |phase| %>
<li class="phase <%= "is-active" if phase.current? %>">
<h3><%= t("budgets.phase.#{phase.kind}") %></h3>
<h3><%= phase.name %></h3>
<span>
<%= l(phase.starts_at.to_date, format: :long) if phase.starts_at.present? %>
-

View File

@@ -155,10 +155,6 @@ class Budget < ApplicationRecord
heading_ids.include?(heading.id) ? heading.price : -1
end
def translated_phase
I18n.t "budgets.phase.#{phase}"
end
def formatted_amount(amount)
ActionController::Base.helpers.number_to_currency(amount,
precision: 0,

View File

@@ -36,6 +36,10 @@ class Budget
PHASE_KINDS[PHASE_KINDS.index(phase)..-1]
end
def name
Class.new.extend(ActionView::Helpers::TranslationHelper).t("budgets.phase.#{kind}")
end
def next_enabled_phase
next_phase&.enabled? ? next_phase : next_phase&.next_enabled_phase
end
@@ -81,7 +85,7 @@ class Budget
if enabled? && starts_at.present? && prev_enabled_phase.present?
prev_enabled_phase.assign_attributes(ends_at: starts_at)
if prev_enabled_phase.invalid_dates_range?
phase_name = I18n.t("budgets.phase.#{prev_enabled_phase.kind}")
phase_name = prev_enabled_phase.name
error = I18n.t("budgets.phases.errors.prev_phase_dates_invalid", phase_name: phase_name)
errors.add(:starts_at, error)
end
@@ -92,7 +96,7 @@ class Budget
if enabled? && ends_at.present? && next_enabled_phase.present?
next_enabled_phase.assign_attributes(starts_at: ends_at)
if next_enabled_phase.invalid_dates_range?
phase_name = I18n.t("budgets.phase.#{next_enabled_phase.kind}")
phase_name = next_enabled_phase.name
error = I18n.t("budgets.phases.errors.next_phase_dates_invalid", phase_name: phase_name)
errors.add(:ends_at, error)
end

View File

@@ -2,7 +2,7 @@
<div class="row">
<div class="small-12 column">
<h2><%= t("admin.budgets.edit.title") %> - <%= t("budgets.phase.#{@phase.kind}") %></h2>
<h2><%= t("admin.budgets.edit.title") %> - <%= @phase.name %></h2>
</div>
</div>

View File

@@ -59,7 +59,7 @@
<% @budget.phases.order(:id).each do |phase| %>
<tr id="<%= dom_id(phase) %>" class="phase">
<td>
<%= t("budgets.phase.#{phase.kind}") %>
<%= phase.name %>
<% if phase.current? %>
<span class="label success"><strong><%= t("admin.budgets.edit.active") %></strong></span>
<% end %>

View File

@@ -29,7 +29,7 @@
<strong><%= budget.name %></strong>
</td>
<td class="small">
<%= t("budgets.phase.#{budget.phase}") %>
<%= budget.current_phase.name %>
</td>
<td>
<%= render Admin::Budgets::TableActionsComponent.new(budget) %>

View File

@@ -23,7 +23,7 @@
<p>
<strong><%= t("budgets.show.phase") %></strong>
</p>
<h2><%= t("budgets.phase.#{current_budget.phase}") %></h2>
<h2><%= current_budget.current_phase.name %></h2>
<%= link_to t("budgets.index.section_header.all_phases"), "#all_phases" %>

View File

@@ -15,7 +15,7 @@
<p>
<strong><%= t("budgets.show.phase") %></strong>
</p>
<h2><%= t("budgets.phase.#{@budget.phase}") %></h2>
<h2><%= @budget.current_phase.name %></h2>
<% if @budget.accepting? %>
<% if current_user %>

View File

@@ -13,7 +13,7 @@
<% @budgets.each do |budget| %>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.translated_phase %></td>
<td><%= budget.current_phase.name %></td>
<td align="right">
<%= link_to t("management.budgets.create_new_investment"),
new_management_budget_investment_path(budget),

View File

@@ -11,7 +11,7 @@
<tbody>
<tr id="<%= dom_id(@budget) %>">
<td><%= @budget.name %></td>
<td><%= @budget.translated_phase %></td>
<td><%= @budget.current_phase.name %></td>
<td align="right">
<%= link_to t("management.budgets.print_investments"),
print_management_budget_investments_path(@budget) %>

View File

@@ -13,7 +13,7 @@
<% @budgets.each do |budget| %>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.translated_phase %></td>
<td><%= budget.current_phase.name %></td>
<td align="right">
<%= link_to t("management.budgets.support_investments"),
management_budget_investments_path(budget),

View File

@@ -16,7 +16,7 @@
<%= @budget.name %>
</td>
<td>
<%= t("budgets.phase.#{@budget.phase}") %>
<%= @budget.current_phase.name %>
</td>
<td>
<%= @investments.count %>