Class: Achoo::Achievo::HourRegistrationForm
- Inherits:
-
Object
- Object
- Achoo::Achievo::HourRegistrationForm
- Defined in:
- lib/achoo/achievo/hour_registration_form.rb
Direct Known Subclasses
Instance Method Summary collapse
- #all_projects ⇒ Object
- #billing=(billing) ⇒ Object
- #billing_options ⇒ Object
- #collect_options(field_name) ⇒ Object
- #get_all_projects ⇒ Object
- #hours=(hours) ⇒ Object
-
#initialize ⇒ HourRegistrationForm
constructor
A new instance of HourRegistrationForm.
- #phase ⇒ Object
- #phase=(phaseid) ⇒ Object
- #phases_for_selected_project ⇒ Object
- #print_values ⇒ Object
- #project ⇒ Object
- #project=(projectid) ⇒ Object
- #recent_projects ⇒ Object
- #remark=(remark) ⇒ Object
- #submit ⇒ Object
- #workperiod=(workperiod) ⇒ Object
- #worktime_periods ⇒ Object
Constructor Details
#initialize ⇒ HourRegistrationForm
Returns a new instance of HourRegistrationForm.
9 10 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 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 9 def initialize @page = AGENT.get(RC[:hour_registration_url]) @form = @page.form('entryform') if @form.nil? # Happens if the user has viewed a day or week report for a # locked month. Fetching todays day report should fix this in # most cases. # FIX Ugly call to a private method using send() haf = HourAdministrationForm.new @page = haf.send(:set_page_to_view_for_date, 'dayview', Date.today) @form = @page.form('entryform') end if @form.nil? raise "Failed to retrieve the hour registration form.\nThe likely cause is that you have locked the current month, which is a silly thing to do." end @projects_seen = {} @phases_seen = {} # Need to preselect this for some reason @form.field_with(:name => 'billpercent')..first.select # Preselecting this one as well, just in case @form.field_with(:name => 'workperiod')..first.select end |
Instance Method Details
#all_projects ⇒ Object
115 116 117 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 115 def all_projects @@allprojects_cache ||= get_all_projects end |
#billing=(billing) ⇒ Object
65 66 67 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 65 def billing=(billing) @form.billpercent = "billpercent.id='#{billing}'" end |
#billing_options ⇒ Object
73 74 75 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 73 def ('billpercent') end |
#collect_options(field_name) ⇒ Object
77 78 79 80 81 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 77 def (field_name) @form.field_with(:name => field_name)..collect do |opt| [opt.value.match(/#{field_name}\.id='(\d+)'/)[1], opt.text] end end |
#get_all_projects ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 119 def get_all_projects puts "Getting project page #1..." projects_page = AGENT.get(projects_url) projects = scrape_projects(projects_page) i = 2 while (link = projects_page.link_with(:text => 'Next')) puts "Getting project page ##{i}..." projects_page = link.click projects.merge!(scrape_projects(projects_page)) i += 1 end projects.keys.sort.collect do |name| id = projects[name][0] text = "#{projects[name][1]}: #{name}" @projects_seen[id] = text [id, text] end end |
#hours=(hours) ⇒ Object
49 50 51 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 49 def hours=(hours) @form.time = hours end |
#phase ⇒ Object
53 54 55 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 53 def phase @form.phaseid.match(/phase\.id='(\d+)'/)[1] end |
#phase=(phaseid) ⇒ Object
57 58 59 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 57 def phase=(phaseid) @form.phaseid = "phase.id='#{phaseid}'" end |
#phases_for_selected_project ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 83 def phases_for_selected_project partial_page = retrieve_project_phases_page page = create_page_from_partial(partial_page) field = page.forms.first.field_with(:name => 'phaseid') phases = [] if field.respond_to?(:options) field..each do |opt| phases << [extract_number_from_phaseid(opt.value), opt.text] end else partial_page.body.match(/(^[^<]+) </) phases << [extract_number_from_phaseid(field.value), $1] end phases.each {|p| @phases_seen[p[0]] = p[1]} return phases end |
#print_values ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 140 def print_values format = "%10s: \"%s\"\n" printf format, 'date', date_to_s printf format, 'project', @projects_seen[project] printf format, 'phase', @phases_seen[phase] printf format, 'remark', @form.remark printf format, 'hours', @form.time printf format, 'worktime', @form.field_with(:name => 'workperiod')..first.text printf format, 'billing', @form.field_with(:name => 'billpercent')..first.text # @form.fields.each do |field| # printf format, field.name, field.value # end end |
#project ⇒ Object
37 38 39 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 37 def project extract_number_from_projectid(@form.projectid) end |
#project=(projectid) ⇒ Object
41 42 43 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 41 def project=(projectid) @form.projectid = "project.id='#{projectid}'" end |
#recent_projects ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 103 def recent_projects projects = [] @form.field_with(:name => 'projectid')..each do |opt| val = opt.value["project.id='".length..-2] projects << [val, opt.text] end projects.each {|p| @projects_seen[p[0]] = p[1]} projects end |
#remark=(remark) ⇒ Object
45 46 47 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 45 def remark=(remark) @form.remark = remark end |
#submit ⇒ Object
156 157 158 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 156 def submit @form.submit() end |
#workperiod=(workperiod) ⇒ Object
61 62 63 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 61 def workperiod=(workperiod) @form.workperiod = "workperiod.id='#{workperiod}'" end |
#worktime_periods ⇒ Object
69 70 71 |
# File 'lib/achoo/achievo/hour_registration_form.rb', line 69 def worktime_periods ('workperiod') end |