diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a5ba883..2412b76 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,45 @@ module ApplicationHelper + + def lighthouse_tracker? object object.issue_tracker_type == "lighthouseapp" end + + + def user_agent_graph(error) + tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)} + create_percentage_table(tallies, :total => error.notices.count) + end + + def pretty_user_agent(user_agent) + (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" + end + + + def tally(collection, &block) + collection.inject({}) do |tallies, item| + value = yield item + tallies[value] = (tallies[value] || 0) + 1 + tallies + end + end + + + def create_percentage_table(tallies, options={}) + total = (options[:total] || total_from_tallies(tallies)) + percent = 100.0 / total.to_f + rows = tallies.map {|value, count| [(count.to_f * percent), value]} \ + .sort {|a, b| a[0] <=> b[0]} + render :partial => "errs/tally_table", :locals => {:rows => rows} + end + + +private + + + def total_from_tallies(tallies) + tallies.values.inject(0) {|sum, n| sum + n} + end + + end diff --git a/app/views/errs/_tally_table.html.haml b/app/views/errs/_tally_table.html.haml new file mode 100644 index 0000000..bf54ce5 --- /dev/null +++ b/app/views/errs/_tally_table.html.haml @@ -0,0 +1,5 @@ +%table.tally + - rows.each do |row| + %tr + %td.percent= number_to_percentage(row[0], :precision => 1) + %th.value= row[1] diff --git a/app/views/notices/_summary.html.haml b/app/views/notices/_summary.html.haml index 06889e6..d38b79a 100644 --- a/app/views/notices/_summary.html.haml +++ b/app/views/notices/_summary.html.haml @@ -15,4 +15,7 @@ %td= notice.created_at.to_s(:micro) %tr %th Similar - %td= notice.err.notices.count - 1 \ No newline at end of file + %td= notice.err.notices.count - 1 + %tr + %th Browser + %td= user_agent_graph(notice.err) \ No newline at end of file diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 41ac340..6886a2e 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -562,7 +562,7 @@ table.errs td.app .environment { table.errs td.message a { width: 420px; display: block; - word-wrap: break-word; + word-wrap: break-word; } table.errs td.message em { color: #727272; @@ -574,6 +574,27 @@ table.errs tr.resolved td > * { -webkit-opacity: 0.5; } +/* Tally tables */ +table.tally { + border:none; +} +table.tally td, +table.tally th { + border:none !important; + background:none !important; + padding:8px 0 0; +} +table.tally tbody tr:first-child td, +table.tally tbody tr:first-child th { + padding-top:0; +} +table.tally td.percent { + width:4.5em; +} +table.tally th.value { + text-transform:none; +} + /* Resolve Errs */ #action-bar a.resolve { background: transparent url(images/icons/thumbs-up.png) 6px 5px no-repeat; -- libgit2 0.21.2