Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#display_time(time) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/application_helper.rb', line 21

def display_time(time)
  seconds = Time.now.to_i - time.to_i
  
  if seconds.abs < 10
    out = "Now"
  elsif seconds > 0
    out = "#{time_ago_in_words(time)} ago"
  else
    out = "#{time_ago_in_words(time)} from now"
  end
  out += " (#{time.strftime("%T %Z")})"
end

#formatter_display(object) ⇒ Object



71
72
73
74
75
76
# File 'app/helpers/application_helper.rb', line 71

def formatter_display(object)
  out  = "<hr/>".html_safe 
  out += (:p, "Formatter: " + object.formatter.to_s)
  out += simple_format(h(JSON.pretty_generate(object.formatter_data)).gsub(" ", "&nbsp;")) unless object.formatter_data.blank?
  out.html_safe
end

#header_titleObject



10
11
12
# File 'app/helpers/application_helper.rb', line 10

def header_title
  @title
end

#page_titleObject



6
7
8
# File 'app/helpers/application_helper.rb', line 6

def page_title
  @title || "Daily"
end

#report_error_html(report) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/application_helper.rb', line 60

def report_error_html(report)
  report.jobs.each do |job|
    if job.last_error 
      msg = job.last_error.gsub("\\n", "\n")
      msg = msg.split("\n").first unless Rails.env.development?
      return simple_format(msg)
    end
  end
  ""
end

#report_time_ago(report) ⇒ Object



49
50
51
52
53
# File 'app/helpers/application_helper.rb', line 49

def report_time_ago(report)
  return "None" unless report.file_exists?
  return "Unknown" if report.generate_ended_at.nil?
  display_time(report.generate_ended_at)
end

#report_time_next(report) ⇒ Object



42
43
44
45
46
47
# File 'app/helpers/application_helper.rb', line 42

def report_time_next(report)
  job = report.next_job
  return "Not scheduled" if job.nil?
  return "Running now..." if job.locked_at.present?
  display_time(job.run_at)
end

#report_time_run(report) ⇒ Object



34
35
36
37
38
39
40
# File 'app/helpers/application_helper.rb', line 34

def report_time_run(report)
  return "Unknown" if report.generate_started_at.nil?
  return "Unknown" if report.generate_ended_at.nil?
  
  time = report.generate_ended_at.to_i - report.generate_started_at.to_i
  seconds_sentence(time)
end

#seconds_sentence(time) ⇒ Object



14
15
16
17
18
19
# File 'app/helpers/application_helper.rb', line 14

def seconds_sentence(time)
  return "Running now..." if time < 0
  return "Less than a second" if time == 0
  return "1 second" if time == 1
  "#{time} seconds"
end

#table_time_run(table) ⇒ Object



55
56
57
58
# File 'app/helpers/application_helper.rb', line 55

def table_time_run(table)
  return "Unknown" if table.fetch_time_in_seconds.nil?
  seconds_sentence(table.fetch_time_in_seconds)
end

#title(text) ⇒ Object



2
3
4
# File 'app/helpers/application_helper.rb', line 2

def title(text)
  @title = text
end

#transform_display(object) ⇒ Object



78
79
80
81
82
83
84
# File 'app/helpers/application_helper.rb', line 78

def transform_display(object)
  return "" if object.transform.blank?
  out  = "<hr/>".html_safe 
  out += (:p, "Transform: " + object.transform.constantize.display_name)
  out += simple_format(h(JSON.pretty_generate(object.transform_data)).gsub(" ", "&nbsp;")) unless object.transform_data.blank?
  out.html_safe
end