Class: Footnotes::Notes::QueriesNote

Inherits:
AbstractNote show all
Defined in:
lib/rails-footnotes/notes/queries_note.rb

Constant Summary collapse

@@alert_db_time =
0.16
@@alert_sql_number =
8
@@sql =
[]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNote

close!, #has_fieldset?, included?, #initialize, #javascript, #legend, #link, #onclick, #row, title, #to_sym, #valid?

Constructor Details

This class inherits a constructor from Footnotes::Notes::AbstractNote

Class Method Details

.start!(controller) ⇒ Object



11
12
13
# File 'lib/rails-footnotes/notes/queries_note.rb', line 11

def self.start!(controller)
  @@sql = []
end

.to_symObject



15
16
17
# File 'lib/rails-footnotes/notes/queries_note.rb', line 15

def self.to_sym
  :queries
end

Instance Method Details

#contentObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rails-footnotes/notes/queries_note.rb', line 39

def content
  html = ''

  @@sql.each_with_index do |item, i|
    sql_links = []
    sql_links << "<a href=\"javascript:Footnotes.toggle('qtable_#{i}')\" style=\"color:#A00;\">explain</a>" if item.explain
    sql_links << "<a href=\"javascript:Footnotes.toggle('qtrace_#{i}')\" style=\"color:#00A;\">trace</a>" if item.trace

    html << "  <b id=\"qtitle_\#{i}\">\#{escape(item.type.to_s.upcase)}</b> (\#{sql_links.join(' | ')})<br />\n  \#{print_name_and_time(item.name, item.time)}<br />\n  <span id=\"explain_\#{i}\">\#{print_query(item.query)}</span><br />\n  \#{print_explain(i, item.explain) if item.explain}\n  <p id=\"qtrace_\#{i}\" style=\"display:none;\">\#{parse_trace(item.trace) if item.trace}</p><br />\n    HTML\n  end\n\n  return html\nend\n"

#stylesheetObject



30
31
32
33
34
35
36
37
# File 'lib/rails-footnotes/notes/queries_note.rb', line 30

def stylesheet
  "  #queries_debug_info table td, #queries_debug_info table th{border:1px solid #A00; padding:0 3px; text-align:center;}\n  #queries_debug_info table thead, #queries_debug_info table tbody {color:#A00;}\n  #queries_debug_info p {background-color:#F3F3FF; border:1px solid #CCC; margin:12px; padding:4px 6px;}\n  #queries_debug_info a:hover {text-decoration:underline;}\n  STYLESHEET\nend\n"

#titleObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/rails-footnotes/notes/queries_note.rb', line 19

def title
  db_time = @@sql.inject(0){|sum, item| sum += item.time }
  query_color = generate_red_color(@@sql.length, alert_sql_number)
  db_color    = generate_red_color(db_time, alert_db_time)

  "  <span style=\"background-color:\#{query_color}\">Queries (\#{@@sql.length})</span> \n  <span style=\"background-color:\#{db_color}\">DB (\#{\"%.6f\" % db_time}s)</span>\n  TITLE\nend\n"