Class: Tempo::Controllers::Report

Inherits:
Base
  • Object
show all
Defined in:
lib/tempo/controllers/report_controller.rb

Class Method Summary collapse

Methods inherited from Base

filter_projects_by_title, fuzzy_match, reassemble_the

Class Method Details

.report(options, args) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tempo/controllers/report_controller.rb', line 9

def report(options, args)

  return Tempo::Views.project_assistance if Tempo::Model::Project.index.empty?

  # A from flag has been supplied by the user
  # and possibly a to flag,
  # so we return a period of day records
  #
  if options[:from] != "last record"
    from = Time.parse options[:from]
    return Views.no_match_error( "valid timeframe", options[:from], false ) if from.nil?

    to = Time.parse options[:to]
    return Views.no_match_error( "valid timeframe", options[:to], false ) if to.nil?

    @time_records.load_days_records from, to, options

    error_timeframe = " from #{from.strftime('%m/%d/%Y')} to #{to.strftime('%m/%d/%Y')}"

  # no arguments or flags have been supplied, so we return the
  # current day record
  #
  elsif args.empty?
    @time_records.load_last_day options

  # arguments have been supplied,
  # so we return the records for a single day
  #
  else
    time = reassemble_the args

    day = Time.parse time
    return Views.no_match_error( "valid timeframe", time, false ) if day.nil?

    @time_records.load_day_record day, options

    error_timeframe = " on #{day.strftime('%m/%d/%Y')}"
  end

  return Views.no_items( "time records#{error_timeframe}", :error ) if @time_records.index.empty?

  Views.report_records_view options
end