Class: Footnotes::Notes::QueriesNote

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

Constant Summary collapse

@@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



9
10
11
# File 'lib/rails-footnotes/notes/queries_note.rb', line 9

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

.to_symObject



13
14
15
# File 'lib/rails-footnotes/notes/queries_note.rb', line 13

def self.to_sym
  :queries
end

Instance Method Details

#contentObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rails-footnotes/notes/queries_note.rb', line 30

def content
  html = ''

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

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

  return html
end

#stylesheetObject



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

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

#titleObject



17
18
19
# File 'lib/rails-footnotes/notes/queries_note.rb', line 17

def title
  "Queries (#{@@sql.length})"
end