module ReportsHelper

File

reports_helper.rb

(C)

Hipposoft 2008

Purpose

Support functions for views related to report generation. See controllers/reports_controller.rb for more.


18-Feb-2008 (ADH): Created.

Public Instance Methods

reporthelp_actions( report ) click to toggle source

Return appropriate list view actions for the given report

# File app/helpers/reports_helper.rb, line 341
def reporthelp_actions( report )
  if ( @current_user.admin? || report.user_id == @current_user.id )
    return [ 'edit', 'delete', 'show' ]
  else
    return []
  end
end
reporthelp_decorated_hours( actual, potential ) click to toggle source

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.

# File app/helpers/reports_helper.rb, line 302
def reporthelp_decorated_hours( actual, potential )
  class_name  = actual    < 0 ? 'overrun' : 'no_overrun'
  output      = "<strong><span class=\"#{ class_name }\">#{ apphelp_terse_hours( actual ) }</span> / "
  class_name  = potential < 0 ? 'overrun' : 'no_overrun'
  output     << "<span class=\"#{ class_name }\">#{ apphelp_terse_hours( potential ) }</span></strong>"

  return output.html_safe()
end
reporthelp_end_date( report ) click to toggle source

List helper - formatted end date for the given report

# File app/helpers/reports_helper.rb, line 335
def reporthelp_end_date( report )
  apphelp_date( report.generate_report().range.max )
end
reporthelp_end_time( form ) click to toggle source

Use the Calendar Date Select plug-in to generate a selector for the end time of a report. Pass the form instance upon which to operate.

# File app/helpers/reports_helper.rb, line 123
def reporthelp_end_time( form )
  return form.calendar_date_select(
    :range_end,
    {
      :embedded   => false,
      :year_range => Timesheet.used_range()
    }
  )
end
reporthelp_frequency_selection( form ) click to toggle source

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.).

# File app/helpers/reports_helper.rb, line 180
def reporthelp_frequency_selection( form )
  collection = []

  Report.labels.each_index do | index |
    collection.push( [ Report.labels[ index ], index ] )
  end

  form.select( :frequency, collection )
end
reporthelp_grouping_selector( form ) click to toggle source

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

# File app/helpers/reports_helper.rb, line 233
def reporthelp_grouping_selector( form )
  return apphelp_select(
    form,
    :task_grouping,
    [
      [ 'No special grouping',                'default'  ],
      [ 'Group billable tasks together',      'billable' ],
      [ 'Group active tasks together',        'active'   ],
      [ 'Group both kinds of tasks together', 'both'     ]
    ],
    false
  )
end
reporthelp_hours( calculator, show_zero = false ) click to toggle source

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.

# File app/helpers/reports_helper.rb, line 269
def reporthelp_hours( calculator, show_zero = false )

  if ( calculator.has_hours? )
    output  = ''
    output << apphelp_terse_hours( calculator.total ) if ( @report.include_totals != false )
    output << ' (' if ( @report.include_totals != false and ( @report.include_committed != false or @report.include_not_committed != false ) )

    if ( @report.include_committed != false )
      output << '<span class="timesheet_committed">'
      output << apphelp_terse_hours( calculator.committed )
      output << '</span>'
    end

    output << '/' if ( @report.include_committed != false and @report.include_not_committed != false )

    if ( @report.include_not_committed != false )
      output << '<span class="timesheet_not_committed">'
      output << apphelp_terse_hours( calculator.not_committed )
      output << '</span>'
    end

    output << ')' if ( @report.include_totals != false and ( @report.include_committed != false or @report.include_not_committed != false ) )

    return output.html_safe()
  else
    return ( show_zero ? '0' : '&nbsp;' ).html_safe()
  end
end
reporthelp_month_selection( form, method ) click to toggle source

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 form being constructed and “:range_month_start” or “:range_month_end”.

# File app/helpers/reports_helper.rb, line 138
def reporthelp_month_selection( form, method )
  start_or_end = ( method == :range_month_start ) ? :start : :end

  form.grouped_collection_select(
    method,
    get_year_array(), # Use years for groups
    :months,          # A years's "months" method returns its month list
    :title,           # Use the year 'title' for the group labels
    :id,              # A month's "id" method returns the value for an option tag
    start_or_end,     # A month's "start" or "end" method is used for the option contents
    {
      :include_blank => '-'
    }
  )
end
reporthelp_owner( report ) click to toggle source

List helper - owner of the given report

# File app/helpers/reports_helper.rb, line 317
def reporthelp_owner( report )
  return link_to( report.user.name, user_path( report.user ) )
end
reporthelp_sorting_selector( form, method ) click to toggle source

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”.

# File app/helpers/reports_helper.rb, line 217
def reporthelp_sorting_selector( form, method )
  return apphelp_select(
    form,
    method,
    [
      [ 'Sort by name',          'title'      ],
      [ 'Sort by code',          'code'       ],
      [ 'Sort by addition date', 'created_at' ]
    ],
    false
  )
end
reporthelp_start_date( report ) click to toggle source

List helper - formatted start date for the given report

# File app/helpers/reports_helper.rb, line 329
def reporthelp_start_date( report )
  apphelp_date( report.generate_report().range.min )
end
reporthelp_start_time( form ) click to toggle source

Use the Calendar Date Select plug-in to generate a selector for the start time of a report. Pass the form instance upon which to operate.

# File app/helpers/reports_helper.rb, line 110
def reporthelp_start_time( form )
  return form.calendar_date_select(
    :range_start,
    {
      :embedded   => false,
      :year_range => Timesheet.used_range()
    }
  )
end
reporthelp_updated_at( report ) click to toggle source

List helper - formatted ‘updated at’ date for the given report

# File app/helpers/reports_helper.rb, line 323
def reporthelp_updated_at( report )
  return apphelp_date( report.updated_at )
end
reporthelp_user_selection( form, users ) click to toggle source

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.

# File app/helpers/reports_helper.rb, line 199
def reporthelp_user_selection( form, users )
  if ( users.empty? )
    return ''
  else
    return apphelp_collection_select(
      form,
      'reportable_user_ids',
      users,
      :id,
      :name
    )
  end
end
reporthelp_week_selection( form, method ) click to toggle source

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 the form being constructed and “:range_week_start” or “:range_week_end”.

# File app/helpers/reports_helper.rb, line 159
def reporthelp_week_selection( form, method )
  start_or_end = ( method == :range_week_start ) ? :start : :end

  form.grouped_collection_select(
    method,
    get_year_array(), # Use years for groups
    :weeks,           # A years's "weeks" method returns its week list
    :title,           # Use the year 'title' for the group labels
    :id,              # A week's "id" method returns the value for an option tag
    start_or_end,     # A week's "start" or "end" method is used for the option contents
    {
      :include_blank => '-'
    }
  )
end
reporthelp_work_breakdown_item_name( item ) click to toggle source

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.

# File app/helpers/reports_helper.rb, line 252
def reporthelp_work_breakdown_item_name( item )
  item = item[ :item ]

  if ( item.class == User )
    return "by #{ h( item.name ) }".html_safe()
  else
    return "on '#{ h( item.augmented_title ) }'".html_safe()
  end
end