Module: TimeTrackable

Extended by:
ActiveSupport::Concern
Included in:
Issue, MergeRequest
Defined in:
app/models/concerns/time_trackable.rb

Overview

TimeTrackable concern

Contains functionality related to objects that support time tracking.

Used by Issue and MergeRequest.

Instance Method Summary collapse

Instance Method Details

#human_time_changeObject



59
60
61
# File 'app/models/concerns/time_trackable.rb', line 59

def human_time_change
  Gitlab::TimeTrackingFormatter.output(time_change)
end

#human_time_estimateObject



63
64
65
# File 'app/models/concerns/time_trackable.rb', line 63

def human_time_estimate
  Gitlab::TimeTrackingFormatter.output(time_estimate)
end

#human_total_time_spentObject



51
52
53
# File 'app/models/concerns/time_trackable.rb', line 51

def human_total_time_spent
  Gitlab::TimeTrackingFormatter.output(total_time_spent)
end

#set_time_estimate_default_valueObject



71
72
73
74
75
76
# File 'app/models/concerns/time_trackable.rb', line 71

def set_time_estimate_default_value
  return if new_record?
  return unless has_attribute?(:time_estimate)

  self.time_estimate ||= self.class.column_defaults['time_estimate']
end

#spend_time(options) ⇒ Object Also known as: spend_time=

rubocop:disable Gitlab/ModuleWithInstanceVariables



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/concerns/time_trackable.rb', line 28

def spend_time(options)
  @time_spent = options[:duration]
  @time_spent_note_id = options[:note_id]
  @time_spent_user = User.find(options[:user_id])
  @spent_at = options[:spent_at]
  @summary = options[:summary]
  @original_total_time_spent = nil

  return if @time_spent == 0

  @timelog = if @time_spent == :reset
               reset_spent_time
             else
               add_or_subtract_spent_time
             end
end

#time_changeObject



55
56
57
# File 'app/models/concerns/time_trackable.rb', line 55

def time_change
  @timelog&.time_spent.to_i # rubocop:disable Gitlab/ModuleWithInstanceVariables
end

#time_estimate=(val) ⇒ Object



67
68
69
# File 'app/models/concerns/time_trackable.rb', line 67

def time_estimate=(val)
  val.is_a?(Integer) ? super([val, Gitlab::Database::MAX_INT_VALUE].min) : super(val)
end

#total_time_spentObject

rubocop:enable Gitlab/ModuleWithInstanceVariables



47
48
49
# File 'app/models/concerns/time_trackable.rb', line 47

def total_time_spent
  timelogs.sum(:time_spent)
end