Module ReportsHelper
In: app/helpers/reports_helper.rb
File:reports_helper.rb
(C):Hipposoft 2008, 2009
Purpose:Support functions for views related to report generation. See controllers/reports_controller.rb for more.

          18-Feb-2008 (ADH): Created.

Methods

Included Modules

TrackRecordReport

Classes and Modules

Class ReportsHelper::ReportMonth
Class ReportsHelper::ReportWeek
Class ReportsHelper::ReportYear

Public Instance methods

Report a terse number of hours with an ‘overrun’ span if negative or a ‘no_overrun’ span if >= 0 in two sections separated by a "/" - the idea is to pass actual and potential remaining hours for a task in here.

[Source]

     # File app/helpers/reports_helper.rb, line 309
309:   def reporthelp_decorated_hours( actual, potential )
310:     class_name  = actual    < 0 ? 'overrun' : 'no_overrun'
311:     output      = "<strong><span class=\"#{ class_name }\">#{ apphelp_terse_hours( actual ) }</span> / "
312:     class_name  = potential < 0 ? 'overrun' : 'no_overrun'
313:     output     << "<span class=\"#{ class_name }\">#{ apphelp_terse_hours( potential ) }</span></strong>"
314: 
315:     return output
316:   end

Use the Calendar Date Select plug-in to generate a selector for the end time of a report.

[Source]

     # File app/helpers/reports_helper.rb, line 125
125:   def reporthelp_end_time
126:     return calendar_date_select(
127:       :report,
128:       :range_end,
129:       {
130:         :embedded   => false,
131:         :year_range => Timesheet.used_range(),
132:         :size       => 24
133:       }
134:     )
135:   end

Return HTML suitable for inclusion in the form passed in the first parameter (i.e. the ‘f’ in "form for … do |f|" ), which provides a selection list allowing the user to choose a report frequency (weekly, monthly etc.).

[Source]

     # File app/helpers/reports_helper.rb, line 187
187:   def reporthelp_frequency_selection( form )
188:     collection = []
189: 
190:     Report.labels.each_index do | index |
191:       collection.push( [ Report.labels[ index ], index ] )
192:     end
193: 
194:     form.select( :frequency, collection )
195:   end

Generate a menu for the given form allowing the user to choose a grouping option.

[Source]

     # File app/helpers/reports_helper.rb, line 240
240:   def reporthelp_grouping_selector( form )
241:     return apphelp_select(
242:       form,
243:       :task_grouping,
244:       [
245:         [ 'No special grouping',                'default'  ],
246:         [ 'Group billable tasks together',      'billable' ],
247:         [ 'Group active tasks together',        'active'   ],
248:         [ 'Group both kinds of tasks together', 'both'     ]
249:       ],
250:       false
251:     )
252:   end

For a report ‘show’ view, generate a series of hidden fields that carry all information about a report so that a ‘new’ view, or another report creation operation, can progress with the same parameters as the current item. Pass the wrapping form object reference ("f" in "form_for :report… do | f |").

[Source]

     # File app/helpers/reports_helper.rb, line 323
323:   def reporthelp_hidden_fields( form )
324:     output  = form.hidden_field( :range_start           )
325:     output << form.hidden_field( :range_end             )
326:     output << form.hidden_field( :range_week_start      )
327:     output << form.hidden_field( :range_week_end        )
328:     output << form.hidden_field( :range_month_start     )
329:     output << form.hidden_field( :range_month_end       )
330:     output << form.hidden_field( :frequency             )
331:     output << form.hidden_field( :task_filter           )
332:     output << form.hidden_field( :task_grouping         )
333:     output << form.hidden_field( :task_sort_field       )
334:     output << form.hidden_field( :project_sort_field    )
335:     output << form.hidden_field( :customer_sort_field   )
336:     output << form.hidden_field( :include_totals        )
337:     output << form.hidden_field( :include_committed     )
338:     output << form.hidden_field( :include_not_committed )
339:     output << form.hidden_field( :exclude_zero_rows     )
340:     output << form.hidden_field( :exclude_zero_cols     )
341: 
342:     @report.users.each_index do | index |
343:       user = @report.users[ index ]
344:       output << hidden_field_tag( "report[user_ids][#{ index }]", user.id.to_s )
345:     end
346: 
347:     @report.tasks.each_index do | index |
348:       task = @report.tasks[ index ]
349:       output << hidden_field_tag( "report[task_ids][#{ index }]", task.id.to_s )
350:     end
351: 
352:     return output
353:   end

Return HTML suitable for an ‘hours’ field which gives a total amount, then a committed and not-committed amount wrapped in SPANs to give the correct committed/uncommitted text styles. If the overall total time is zero, "&nbsp;" is returned instead. Pass any object subclassing TrackRecordReport::ReportElementaryCalculator and, optionally, ‘true’ to show "0.0" rather than "&nbsp;" in the zero hours total case.

[Source]

     # File app/helpers/reports_helper.rb, line 276
276:   def reporthelp_hours( calculator, show_zero = false )
277: 
278:     if ( calculator.has_hours? )
279:       output  = ''
280:       output << apphelp_terse_hours( calculator.total ) if ( @report.include_totals != false )
281:       output << ' (' if ( @report.include_totals != false and ( @report.include_committed != false or @report.include_not_committed != false ) )
282: 
283:       if ( @report.include_committed != false )
284:         output << '<span class="timesheet_committed">'
285:         output << apphelp_terse_hours( calculator.committed )
286:         output << '</span>'
287:       end
288: 
289:       output << '/' if ( @report.include_committed != false and @report.include_not_committed != false )
290: 
291:       if ( @report.include_not_committed != false )
292:         output << '<span class="timesheet_not_committed">'
293:         output << apphelp_terse_hours( calculator.not_committed )
294:         output << '</span>'
295:       end
296: 
297:       output << ')' if ( @report.include_totals != false and ( @report.include_committed != false or @report.include_not_committed != false ) )
298: 
299:       return output
300:     else
301:       return ( show_zero ? '0' : '&nbsp;' )
302:     end
303:   end

Return HTML suitable for inclusion in a form which provides a pull-down menu of years for the full permitted time range subdivided into months. Pass the current item to select or nil for none, then ‘true’ for a start time menu, else an end time menu.

[Source]

     # File app/helpers/reports_helper.rb, line 143
143:   def reporthelp_month_selection( to_select, is_start )
144:     method = is_start ? :start : :end
145:     years  = get_year_array()
146: 
147:     data = "<select id=\"report_range_month_#{method}\" name=\"report[range_month_#{method}]\">"
148:     data << '<option value="">-</option>'
149:     data << option_groups_from_collection_for_select(
150:       years,   # Use years for groups
151:       :months, # A years's "months" method returns its month list
152:       :title,  # Use the year 'title' for the group labels
153:       :id,     # A month's "id" method returns the value for an option tag
154:       method,  # A month's "start" or "end" method is used for the option contents
155:       to_select
156:     )
157:     return data << '</select>'
158:   end

[Source]

     # File app/helpers/reports_helper.rb, line 355
355:   def reporthelp_shortcut_path
356:     "#{ report_shortcut_path }?#{ { 'report' => params[ 'report' ] } .to_query }"
357:   end

Generate a sort field selector menu for the given form which will use the given method to set the chosen option in the report - one of ":customer_sort_field", ":project_sort_field" or ":task_sort_field".

[Source]

     # File app/helpers/reports_helper.rb, line 224
224:   def reporthelp_sorting_selector( form, method )
225:     return apphelp_select(
226:       form,
227:       method,
228:       [
229:         [ 'Sort by name',          'title'      ],
230:         [ 'Sort by code',          'code'       ],
231:         [ 'Sort by addition date', 'created_at' ]
232:       ],
233:       false
234:     )
235:   end

Use the Calendar Date Select plug-in to generate a selector for the start time of a report.

[Source]

     # File app/helpers/reports_helper.rb, line 110
110:   def reporthelp_start_time
111:     return calendar_date_select(
112:       :report,
113:       :range_start,
114:       {
115:         :embedded   => false,
116:         :year_range => Timesheet.used_range(),
117:         :size       => 25
118:       }
119:     )
120:   end

Return HTML suitable for inclusion in the form passed in the first parameter (i.e. the ‘f’ in "form for … do |f|" ), based on the user array given in the second parameter, which provides:

  • A <select> tag with options listing all users in the array in the order in which they are stored in that array.
  • An empty string if the input users array is itself empty.

[Source]

     # File app/helpers/reports_helper.rb, line 206
206:   def reporthelp_user_selection( form, users )
207:     if ( users.empty? )
208:       return ''
209:     else
210:       return apphelp_collection_select(
211:         form,
212:         'user_ids',
213:         users,
214:         :id,
215:         :name
216:       )
217:     end
218:   end

Return HTML suitable for inclusion in a form which provides a pull-down menu of years for the full permitted time range subdivided into weeks. Pass ‘true’ for a start time menu, else an end time menu.

[Source]

     # File app/helpers/reports_helper.rb, line 165
165:   def reporthelp_week_selection( to_select, is_start )
166:     method = is_start ? :start : :end
167:     years  = get_year_array()
168: 
169:     data = "<select id=\"report_range_week_#{method}\" name=\"report[range_week_#{method}]\">"
170:     data << '<option value="">-</option>'
171:     data << option_groups_from_collection_for_select(
172:       years,  # Use years for groups
173:       :weeks, # A years's "weeks" method returns its week list
174:       :title, # Use the year 'title' for the group labels
175:       :id,    # A week's "id" method returns the value for an option tag
176:       method, # A week's "start" or "end" method is used for the option contents
177:       to_select
178:     )
179:     return data << '</select>'
180:   end

Pass a hash. The ":item" entry is read. If a User, a string of "by <name>" is returned. Otherwise, a string of "on ’<title>’" is returned. Useful for indicating hours are done by a user, or were worked on some task.

[Source]

     # File app/helpers/reports_helper.rb, line 259
259:   def reporthelp_work_breakdown_item_name( item )
260:     item = item[ :item ]
261: 
262:     if ( item.class == User )
263:       return "by #{ h( item.name ) }"
264:     else
265:       return "on '#{ h( item.augmented_title ) }'"
266:     end
267:   end

[Validate]