Class: Tempo::Controllers::Start

Inherits:
Base
  • Object
show all
Defined in:
lib/tempo/controllers/start_controller.rb

Class Method Summary collapse

Methods inherited from Base

filter_projects_by_title, fuzzy_match, reassemble_the

Class Method Details

.start_timer(options, args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tempo/controllers/start_controller.rb', line 11

def start_timer(options, args)

  return Views.project_assistance if Model::Project.index.empty?

  if not options[:at]
    time_in = Time.new()
  else
    time_in = Time.parse options[:at]
  end

  return Views.no_match_error( "valid timeframe", options[:at], false ) if time_in.nil?

  opts = { start_time: time_in }
  opts[:description] = reassemble_the args

  if options[:end]
    time_out = Time.parse options[:end]
    return Views.no_match_error( "valid timeframe", options[:end], false ) if time_out.nil?
    opts[:end_time] = time_out
  end

  @time_records.load_last_day options

  if options[:resume]
    last_record = @time_records.last_record

    return Views.error("cannot resume last time record when it is still running") if last_record.running?

    opts[:description] = last_record.description

    # we use the last used project, but don't save it as current
    # in case a different project has been checked out.
    @projects.current = @projects.find_by_id(last_record.project)

    record = @time_records.new(opts)

  else
    record = @time_records.new(opts)
  end

  @time_records.save_to_file options

  Views.start_time_record_view record

end