From 0a265fbbcef22d16c1816422ecb2bd328dd3ae26 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Mon, 27 Nov 2023 08:55:57 +0000 Subject: [PATCH] Use standard Redmine progress bars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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… --- app/helpers/jobs_helper.rb | 13 +++++++++++++ app/models/job.rb | 19 ++++++++++++++++--- app/views/jobs/_budget.html.erb | 9 +-------- app/views/jobs/_job.html.erb | 5 +++-- app/views/jobs/index.html.erb | 3 ++- app/views/jobs/show.html.erb | 3 +-- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/helpers/jobs_helper.rb b/app/helpers/jobs_helper.rb index 44c7bf6..b56b93d 100644 --- a/app/helpers/jobs_helper.rb +++ b/app/helpers/jobs_helper.rb @@ -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 diff --git a/app/models/job.rb b/app/models/job.rb index a118b04..a599540 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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) diff --git a/app/views/jobs/_budget.html.erb b/app/views/jobs/_budget.html.erb index 284e127..ef83d67 100644 --- a/app/views/jobs/_budget.html.erb +++ b/app/views/jobs/_budget.html.erb @@ -1,11 +1,4 @@
<%= budget.activity&.name || "Unassigned" %>
- <%= l_hours_short( - budget.job.total_time_logged_for(budget.activity) - ) %> / - <%= l_hours_short( - budget.hours - ) %> - + <%= progress_bar_for(budget) %>
diff --git a/app/views/jobs/_job.html.erb b/app/views/jobs/_job.html.erb index 27bfcb6..377ee01 100644 --- a/app/views/jobs/_job.html.erb +++ b/app/views/jobs/_job.html.erb @@ -5,9 +5,10 @@ <%= job.project_id %> <%= job.external_project_id %> - <%= l_hours_short(job.total_time_logged) %> / <%= l_hours_short(job.total_time_budget) %> - + + + <%= total_progress_bar(job) %> diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index 124d13d..b455453 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -16,7 +16,8 @@ Ends on Project External project - Budget + Total budget + Progress diff --git a/app/views/jobs/show.html.erb b/app/views/jobs/show.html.erb index 72d428e..87bb891 100644 --- a/app/views/jobs/show.html.erb +++ b/app/views/jobs/show.html.erb @@ -27,8 +27,7 @@
Total:
- <%= l_hours_short(@job.total_time_logged) %> / <%= l_hours_short(@job.total_time_budget) %> - + <%= total_progress_bar(@job) %>
<% @job.time_budgets.each do |budget| %> <%= render partial: "budget", locals: { budget: budget } %>