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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/tempo/controllers/update_controller.rb', line 23
def parse(options, args)
reassemble_the args
return Views.project_assistance if Model::Project.index.empty?
return running(options, args) if options[:running]
if options[:on]
day = Time.parse options[:on]
return Views.no_match_error( "valid timeframe", options[:from], false ) if day.nil?
@time_records.load_day_record day, options
else
day = @time_records.load_last_day options
end
if options[:id]
record = @time_records.find_by_id( options[:id], day )
return Views.no_match_error( "time record on #{day.strftime('%m/%d/%Y')}", "id = #{options[:id]}", false ) if !record
else
record = @time_records.current || @time_records.index.last
return Views.no_items( "time records on #{day.strftime('%m/%d/%Y')}", :error ) if ! record
end
if options[:delete]
if Tempo::Model::TimeRecord.ids(record.d_id).length == 1
@time_records.delete_day_record record.d_id, options
else
record.delete
@time_records.save_to_file options
end
Views.delete_time_record_view record
else
if options[:start]
start_time = Time.parse options[:start]
return Views.no_match_error( "valid timeframe", options[:at], false ) if start_time.nil?
if record.valid_start_time? start_time
record.start_time = start_time
elsif record.valid_start_time? start_time.on_date(record.start_time)
record.start_time = start_time.on_date(record.start_time)
else
return Views::ViewRecords::Message.new "cannot change start time to #{start_time.strftime('%H:%M')}", category: :error
end
end
if options[:end]
end_time = Time.parse options[:end]
return Views.no_match_error( "valid timeframe", options[:at], false ) if end_time.nil?
if record.valid_end_time? end_time
record.end_time = end_time
elsif record.valid_end_time? end_time.on_date(record.end_time)
record.end_time = end_time.on_date(record.end_time)
else
return Views::ViewRecords::Message.new "cannot change end time to #{end_time.strftime('%H:%M')}", category: :error
end
end
if options[:project]
record.project = @projects.current.id
end
options[:description] = reassemble_the args
record.description = options[:description] if options[:description] && !options[:description].empty?
@time_records.save_to_file options
Views.update_time_record_view record
end
end
|