Use standard Redmine progress bars
Proper HTML ones would be nicer, but this increases consistency with the rest of Redmine which is more important here. Maybe a PR is in the offing…
This commit is contained in:
parent
5d5ea8e302
commit
0a265fbbce
|
@ -1,2 +1,15 @@
|
|||
module JobsHelper
|
||||
def total_progress_bar(job)
|
||||
progress_bar(job.done_ratio,
|
||||
legend: "#{job.done_ratio}%
|
||||
(#{l_hours_short(job.total_time_logged)}/#{l_hours_short(job.total_time_budget)})",
|
||||
class: "progress")
|
||||
end
|
||||
|
||||
def progress_bar_for(budget)
|
||||
progress_bar(budget.job.done_ratio_for(budget.activity),
|
||||
legend: "#{budget.job.done_ratio_for(budget.activity)}%
|
||||
(#{l_hours_short(budget.job.total_time_logged_for(budget.activity))}/#{l_hours_short(budget.hours)})",
|
||||
class: "progress")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,12 +7,12 @@ class Job < ActiveRecord::Base
|
|||
presence: true
|
||||
|
||||
belongs_to :project
|
||||
has_many :time_entries, dependent: :restrict_with_error, message: "You cannot delete a job with time logged against it."
|
||||
has_many :time_entries, dependent: :restrict_with_error
|
||||
has_many :time_budgets, dependent: :destroy
|
||||
accepts_nested_attributes_for :time_budgets, allow_destroy: true
|
||||
|
||||
scope :project, ->(project) { where(project_id: project.id) }
|
||||
scope :project_or_parent, ->(project) { where(project_id: [project.id, project.parent&.id]) }
|
||||
scope :active, -> { where(starts_on: ..Date.today, ends_on: Date.today..) }
|
||||
|
||||
def with_all_time_budgets
|
||||
time_budgets.build(job_id: id, activity_id: nil) unless time_budgets.where(activity_id: nil).exists?
|
||||
|
@ -34,7 +34,9 @@ class Job < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def time_budget_for(activity)
|
||||
time_budgets.where(activity_id: activity.id).hours || 0
|
||||
return 0 if activity.nil? || time_budgets.find_by(activity_id: activity.id).nil?
|
||||
|
||||
time_budgets.find_by(activity_id: activity.id).hours
|
||||
end
|
||||
|
||||
def total_time_logged
|
||||
|
@ -47,6 +49,17 @@ class Job < ActiveRecord::Base
|
|||
.sum(:hours)
|
||||
end
|
||||
|
||||
|
||||
def done_ratio
|
||||
(total_time_logged / total_time_budget * 100).to_i
|
||||
end
|
||||
|
||||
def done_ratio_for(activity)
|
||||
return 0 if total_time_logged_for(activity).zero?
|
||||
|
||||
(total_time_logged_for(activity) / time_budget_for(activity) * 100).to_i
|
||||
end
|
||||
|
||||
def to_s
|
||||
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
||||
ActionController::Base.helpers.link_to name, ActionController::Base.helpers.project_job_path(project, self)
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<div class="label"><%= budget.activity&.name || "Unassigned" %></div>
|
||||
<div class="value">
|
||||
<%= l_hours_short(
|
||||
budget.job.total_time_logged_for(budget.activity)
|
||||
) %> /
|
||||
<%= l_hours_short(
|
||||
budget.hours
|
||||
) %>
|
||||
<progress max="<%= budget %>"
|
||||
value="<%= budget.job.total_time_logged_for(budget.activity) %>"></progress>
|
||||
<%= progress_bar_for(budget) %>
|
||||
</div>
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
<td><%= job.project_id %></td>
|
||||
<td><%= job.external_project_id %></td>
|
||||
<td>
|
||||
<%= l_hours_short(job.total_time_logged) %> /
|
||||
<%= l_hours_short(job.total_time_budget) %>
|
||||
<progress max="<%= job.total_time_budget %>" value="<%= job.total_time_logged %>"></progress>
|
||||
</td>
|
||||
<td>
|
||||
<%= total_progress_bar(job) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
<th>Ends on</th>
|
||||
<th>Project</th>
|
||||
<th>External project</th>
|
||||
<th>Budget</th>
|
||||
<th>Total budget</th>
|
||||
<th>Progress</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
<div class="status attribute">
|
||||
<div class="label">Total:</div>
|
||||
<div class="value">
|
||||
<%= l_hours_short(@job.total_time_logged) %> / <%= l_hours_short(@job.total_time_budget) %>
|
||||
<progress max="<%= @job.total_time_budget %>" value="<%= @job.total_time_logged %>"></progress>
|
||||
<%= total_progress_bar(@job) %>
|
||||
</div>
|
||||
<% @job.time_budgets.each do |budget| %>
|
||||
<%= render partial: "budget", locals: { budget: budget } %>
|
||||
|
|
Loading…
Reference in New Issue