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
|
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
|
end
|
||||||
|
|
|
@ -7,12 +7,12 @@ class Job < ActiveRecord::Base
|
||||||
presence: true
|
presence: true
|
||||||
|
|
||||||
belongs_to :project
|
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
|
has_many :time_budgets, dependent: :destroy
|
||||||
accepts_nested_attributes_for :time_budgets, allow_destroy: true
|
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 :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
|
def with_all_time_budgets
|
||||||
time_budgets.build(job_id: id, activity_id: nil) unless time_budgets.where(activity_id: nil).exists?
|
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
|
end
|
||||||
|
|
||||||
def time_budget_for(activity)
|
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
|
end
|
||||||
|
|
||||||
def total_time_logged
|
def total_time_logged
|
||||||
|
@ -47,6 +49,17 @@ class Job < ActiveRecord::Base
|
||||||
.sum(:hours)
|
.sum(:hours)
|
||||||
end
|
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
|
def to_s
|
||||||
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
||||||
ActionController::Base.helpers.link_to name, ActionController::Base.helpers.project_job_path(project, self)
|
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="label"><%= budget.activity&.name || "Unassigned" %></div>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
<%= l_hours_short(
|
<%= progress_bar_for(budget) %>
|
||||||
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>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
<td><%= job.project_id %></td>
|
<td><%= job.project_id %></td>
|
||||||
<td><%= job.external_project_id %></td>
|
<td><%= job.external_project_id %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= l_hours_short(job.total_time_logged) %> /
|
|
||||||
<%= l_hours_short(job.total_time_budget) %>
|
<%= 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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
<th>Ends on</th>
|
<th>Ends on</th>
|
||||||
<th>Project</th>
|
<th>Project</th>
|
||||||
<th>External project</th>
|
<th>External project</th>
|
||||||
<th>Budget</th>
|
<th>Total budget</th>
|
||||||
|
<th>Progress</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
<div class="status attribute">
|
<div class="status attribute">
|
||||||
<div class="label">Total:</div>
|
<div class="label">Total:</div>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
<%= l_hours_short(@job.total_time_logged) %> / <%= l_hours_short(@job.total_time_budget) %>
|
<%= total_progress_bar(@job) %>
|
||||||
<progress max="<%= @job.total_time_budget %>" value="<%= @job.total_time_logged %>"></progress>
|
|
||||||
</div>
|
</div>
|
||||||
<% @job.time_budgets.each do |budget| %>
|
<% @job.time_budgets.each do |budget| %>
|
||||||
<%= render partial: "budget", locals: { budget: budget } %>
|
<%= render partial: "budget", locals: { budget: budget } %>
|
||||||
|
|
Loading…
Reference in New Issue