Include duration in budgets table
This commit is contained in:
committed by
Javi Martín
parent
fe05bfe9ea
commit
d2871d7770
29
app/components/admin/budgets/duration_component.rb
Normal file
29
app/components/admin/budgets/duration_component.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class Admin::Budgets::DurationComponent < ApplicationComponent
|
||||
attr_reader :durable
|
||||
|
||||
def initialize(durable)
|
||||
@durable = durable
|
||||
end
|
||||
|
||||
def dates
|
||||
safe_join([formatted_start_date, "-", formatted_end_date], " ")
|
||||
end
|
||||
|
||||
def duration
|
||||
distance_of_time_in_words(durable.starts_at, durable.ends_at)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def formatted_start_date
|
||||
formatted_date(durable.starts_at) if durable.starts_at.present?
|
||||
end
|
||||
|
||||
def formatted_end_date
|
||||
formatted_date(durable.ends_at - 1.second) if durable.ends_at.present?
|
||||
end
|
||||
|
||||
def formatted_date(time)
|
||||
time_tag(time, format: :datetime)
|
||||
end
|
||||
end
|
||||
@@ -13,6 +13,7 @@
|
||||
<tr>
|
||||
<th><%= t("admin.budgets.index.table_name") %></th>
|
||||
<th><%= t("admin.budgets.index.table_phase") %></th>
|
||||
<th><%= t("admin.budgets.index.table_duration") %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -27,8 +28,13 @@
|
||||
<% end %>
|
||||
<strong><%= budget.name %></strong>
|
||||
</td>
|
||||
<td class="small">
|
||||
<td>
|
||||
<%= budget.current_phase.name %>
|
||||
<small><%= phase_progress_text(budget) %></small>
|
||||
</td>
|
||||
<td>
|
||||
<%= dates(budget) %>
|
||||
<%= duration(budget) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= render Admin::Budgets::TableActionsComponent.new(budget) %>
|
||||
|
||||
@@ -9,4 +9,24 @@ class Admin::Budgets::IndexComponent < ApplicationComponent
|
||||
def title
|
||||
t("admin.budgets.index.title")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def phase_progress_text(budget)
|
||||
t("admin.budgets.index.table_phase_progress",
|
||||
current_phase_number: current_enabled_phase_number(budget),
|
||||
total_phases: budget.phases.enabled.count)
|
||||
end
|
||||
|
||||
def current_enabled_phase_number(budget)
|
||||
budget.phases.enabled.order(:id).pluck(:kind).index(budget.phase) + 1
|
||||
end
|
||||
|
||||
def dates(budget)
|
||||
Admin::Budgets::DurationComponent.new(budget).dates
|
||||
end
|
||||
|
||||
def duration(budget)
|
||||
Admin::Budgets::DurationComponent.new(budget).duration
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user