From 76369e5cc67f27d1f5c96269f16cce604f2e8e71 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 May 2012 15:03:15 +1200 Subject: [PATCH] Hide large segments of external files in backtraces, centred around in-app files. Expand external traces when clicking [...] button. --- app/assets/javascripts/errbit.js | 6 ++++++ app/assets/stylesheets/errbit.css | 20 ++++++++++++++++++++ app/helpers/notices_helper.rb | 33 +++++++++++++++++++++++++++++++++ app/views/notices/_backtrace.html.haml | 25 ++++++++++++++----------- app/views/notices/_backtrace_line.html.haml | 6 ++++++ 5 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 app/views/notices/_backtrace_line.html.haml diff --git a/app/assets/javascripts/errbit.js b/app/assets/javascripts/errbit.js index 6aef53f..bedcbb6 100644 --- a/app/assets/javascripts/errbit.js +++ b/app/assets/javascripts/errbit.js @@ -95,4 +95,10 @@ $(function() { } init(); + + // Show external backtrace lines when clicking separator + $('td.backtrace_separator span').live('click', function(){ + $('tr.hidden_external_backtrace').removeClass('hidden_external_backtrace'); + $('td.backtrace_separator').hide(); + }); }); diff --git a/app/assets/stylesheets/errbit.css b/app/assets/stylesheets/errbit.css index c07db63..9d3e4b4 100644 --- a/app/assets/stylesheets/errbit.css +++ b/app/assets/stylesheets/errbit.css @@ -762,6 +762,26 @@ table.backtrace td.line.in-app { table.backtrace td.line.in-app .file { color: #2AEB2E; } table.backtrace td.line.in-app .method { color: #2ACB2E; } +/* External backtrace classes and separators */ +table.backtrace tr.hidden_external_backtrace { + display: none; +} +table.backtrace td.backtrace_separator span { + cursor: pointer; + display: inline-block; + font-size: 17px; + font-weight: bold; + padding: 0px 11px 5px; + margin: 4px 0; + background-color: #444444; + border: 1px solid #555555; +} +table.backtrace td.backtrace_separator span:hover { + background-color: #666666; + border: 1px solid #777777; +} + + /* Extra empty rows at top and bottom of table */ table.backtrace tr.padding th, table.backtrace tr.padding td { diff --git a/app/helpers/notices_helper.rb b/app/helpers/notices_helper.rb index cb29ff4..d27a1a5 100644 --- a/app/helpers/notices_helper.rb +++ b/app/helpers/notices_helper.rb @@ -30,5 +30,38 @@ module NoticesHelper href = app.issue_tracker.url_to_file(file_path, line['number']) link_to(text || file_name, href, :target => '_blank') end + + # Group lines into sections of in-app files and external files + # (An implementation of Enumerable#chunk so we don't break 1.8.7 support.) + def grouped_lines(lines) + line_groups = [] + lines.each do |line| + in_app = Notice.in_app_backtrace_line?(line) + if line_groups.last && line_groups.last[0] == in_app + line_groups.last[1] << line + else + line_groups << [in_app, [line]] + end + end + line_groups + end + + def rows_for_line_segment(lines, start, length, row_class = nil) + html = "" + lines[start, length].each do |line| + html << render(:partial => "notices/backtrace_line", :locals => {:line => line, :row_class => row_class}) + end + html.html_safe + end + + def path_for_backtrace_line(line) + path = File.dirname(line['file']) + path == "." ? "" : path + '/' + end + + def file_for_backtrace_line(line) + file = File.basename(line['file']) + line['number'].present? ? "#{file}:#{line['number']}" : file + end end diff --git a/app/views/notices/_backtrace.html.haml b/app/views/notices/_backtrace.html.haml index 4babe9f..060c155 100644 --- a/app/views/notices/_backtrace.html.haml +++ b/app/views/notices/_backtrace.html.haml @@ -1,14 +1,17 @@ .window %table.backtrace - - lines.each do |line| - - path = File.dirname(line['file']) - - path = path == "." ? "" : path + '/' - - file = File.basename(line['file']) - - file = "#{file}:#{line['number']}" unless line['number'].blank? - %tr - %td.line{:class => (Notice.in_app_backtrace_line?(line) ? 'in-app' : nil)} - %span.path>= path - %span.file= link_to_source_file(@app, line, file).html_safe - → - %span.method= line['method'] + -# Group lines into internal / external so we can toggle the external backtrace + -# Includes a margin of x lines that are not toggled. + - external_margin = 3 + - grouped_lines(lines).each do |in_app, line_group| + - if !in_app && line_group.size > 6 + = rows_for_line_segment(line_group, 0, external_margin) + = rows_for_line_segment(line_group, 2, line_group.size - (external_margin * 2), 'hidden_external_backtrace') + %tr + %td.line.backtrace_separator + %span ... + = rows_for_line_segment(line_group, external_margin * -1, external_margin) + - else + - line_group.each do |line| + = render :partial => "notices/backtrace_line", :locals => {:line => line} diff --git a/app/views/notices/_backtrace_line.html.haml b/app/views/notices/_backtrace_line.html.haml new file mode 100644 index 0000000..ec48cf8 --- /dev/null +++ b/app/views/notices/_backtrace_line.html.haml @@ -0,0 +1,6 @@ +%tr{:class => defined?(row_class) ? row_class : nil} + %td.line{:class => (Notice.in_app_backtrace_line?(line) ? 'in-app' : nil)} + %span.path>= path_for_backtrace_line(line) + %span.file= link_to_source_file(@app, line, file_for_backtrace_line(line)).html_safe + → + %span.method= line['method'] -- libgit2 0.21.2