Module: Achoo::UI::RegisterHours
Instance Method Summary
collapse
#get_exception_reason, #handle_exception, #handle_fatal_exception
#date_chooser, #month_chooser, #optionally_ranged_date_chooser
Instance Method Details
#all_projects_chooser(form) ⇒ Object
131
132
133
134
135
|
# File 'lib/achoo/ui/register_hours.rb', line 131
def all_projects_chooser(form)
projects = form.all_projects
answer = Achoo::Term.choose('Project', projects.collect { |p| p[1] })
projects[answer.to_i-1][0]
end
|
#billing_chooser(form) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/achoo/ui/register_hours.rb', line 65
def billing_chooser(form)
options = form.billing_options
puts "Billing options"
answer = Achoo::Term.choose('Billing [1]', options.collect {|p| p[1] }, nil, [''])
answer = '1' if answer.empty?
options[answer.to_i-1][0]
end
|
#hours_chooser ⇒ Object
85
86
87
88
|
# File 'lib/achoo/ui/register_hours.rb', line 85
def hours_chooser
answer = Achoo::Term::ask 'Hours [7:30]'
return answer == '' ? '7.5' : answer
end
|
#phase_chooser(form) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/achoo/ui/register_hours.rb', line 49
def phase_chooser(form)
phases = form.phases_for_selected_project
puts "Phases"
answer = Achoo::Term.choose('Phase', phases.collect {|p| p[1] })
phases[answer.to_i-1][0]
end
|
#print_hours_help(date) ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/achoo/ui/register_hours.rb', line 74
def print_hours_help(date)
puts "Awake log:"
begin
awake = Achoo::Awake.new
awake.at(date)
puts
rescue Exception => e
print handle_exception("Failed to retrieve awake log.", e)
end
end
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/achoo/ui/register_hours.rb', line 91
def (date)
puts "VCS logs for #{date}:"
begin
Achoo::VCS.print_logs_for(date, RC[:vcs_dirs])
rescue Exception => e
puts handle_exception("Failed to retrieve VCS logs.", e)
end
puts '-' * 80
puts "Calendar events for #{date}:"
puts '---'
begin
RC[:ical].each do |config|
Achoo::ICal.from_http_request(config).print_events(date)
end
rescue Exception => e
puts handle_exception("Failed to retrieve calendar events.", e)
end
end
|
#project_chooser(form) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/achoo/ui/register_hours.rb', line 115
def project_chooser(form)
puts 'Recently used projects'
projects = form.recent_projects
answer = Achoo::Term.choose('Project [1]', projects.collect { |p| p[1] },
'Other', [''])
case answer
when ''
projects[0][0]
when '0'
return all_projects_chooser(form)
else
return projects[answer.to_i-1][0]
end
end
|
#register_hours(agent) ⇒ Object
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
|
# File 'lib/achoo/ui/register_hours.rb', line 15
def register_hours(agent)
date = optionally_ranged_date_chooser
puts "Fetching data ..."
form = if date.class == Date
Achoo::HourRegistrationForm
else
Achoo::HourRegistrationFormRanged
end.new(agent)
form.date = date
form.project = project_chooser(form)
form.phase = phase_chooser(form)
(date) if date.class == Date
form. =
print_hours_help(date) if date.class == Date
form.hours = hours_chooser
answer = Achoo::Term.ask("Do you want to change the defaults for worktime period and/or billing percentage? [N/y]").downcase
if answer == 'y'
form.workperiod = workperiod_chooser(form)
form.billing = billing_chooser(form)
end
form.print_values
if confirm
puts "Submitting ..."
form.submit
else
puts "Cancelled"
end
end
|
110
111
112
|
# File 'lib/achoo/ui/register_hours.rb', line 110
def
Achoo::Term::ask 'Remark'
end
|
#workperiod_chooser(form) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/achoo/ui/register_hours.rb', line 57
def workperiod_chooser(form)
periods = form.worktime_periods
puts "Worktime periods"
answer = Achoo::Term.choose('Period [1]', periods.collect {|p| p[1] }, nil, [''])
answer = '1' if answer.empty?
periods[answer.to_i-1][0]
end
|