Module: Callstacking::Rails::Helpers::HeadsUpDisplayHelper

Includes:
ActionView::Context, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::TagHelper
Included in:
Trace
Defined in:
lib/callstacking/rails/helpers/heads_up_display_helper.rb

Instance Method Summary collapse

Instance Method Details

#hud(url) ⇒ Object



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
# File 'lib/callstacking/rails/helpers/heads_up_display_helper.rb', line 12

def hud(url)
  frame_url = "#{url || Callstacking::Rails::Settings::PRODUCTION_URL}/traces/#{Callstacking::Rails::Trace.current_trace_id}/print"

  body = []
  body << ((:div, data: { turbo: false },
                       style: 'top: 50%; right: 10px; font-size: 24pt; :hover{text-shadow: 1px 1px 2px #000000};
                    padding: 0px; position: fixed; height: 50px; width: 40px; cursor: pointer;',
                       onclick: 'document.getElementById("callstacking-debugger").style.display = "unset";
                      document.getElementById("callstacking-close").style.display = "unset";') do
    "<span title='ctrl-d'><center>#{Callstacking::Rails::Trace::ICON}</center></span>".html_safe
  end)

  body << ((:iframe, src: frame_url, id: 'callstacking-debugger', data: { turbo: false },
                       style: "width: 50%; height: 100%; overflow: scroll; top: 20px; right: 20px; position: fixed;
                    z-index: 99; opacity: 1.0; background-color: #FFF; color: #000; border: 1px solid;
                    margin: 0; padding: 0; box-shadow: 5px 5px; display: none;") do
  end)

  body << (javascript_tag('
  document.onkeyup = function(e) {
    // Mac - option-d   Win - alt-d
    if (e.ctrlKey && e.which == 68) {
      if (document.getElementById("callstacking-debugger").style.display === "none") {
        document.getElementById("callstacking-debugger").style.display = "block";
        document.getElementById("callstacking-debugger").contentDocument.location.reload(true);
        document.getElementById("callstacking-debugger").focus();
      } else {
        document.getElementById("callstacking-debugger").style.display = "none";
      }
    }
  };'))

  body.join
end

#inject_hud(settings, request, response) ⇒ Object



47
48
49
50
51
# File 'lib/callstacking/rails/helpers/heads_up_display_helper.rb', line 47

def inject_hud(settings, request, response)
  if request.format.html?
    response.body = response.body.sub(/<\/body>/i, "#{hud(settings.url)}</body>")
  end
end