run.html.erb 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <% if @error %>
  2. <div class="alert alert-danger"><%= @error %></div>
  3. <% elsif !@success %>
  4. <% if @only_chart %>
  5. <p class="text-muted">Select variables</p>
  6. <% else %>
  7. <div class="alert alert-info">Can’t preview queries with variables...yet!</div>
  8. <% end %>
  9. <% else %>
  10. <% unless @only_chart %>
  11. <% if @cached_at %>
  12. <p class="text-muted" style="float: right;">Cached <%= time_ago_in_words(@cached_at) %> ago</p>
  13. <% end %>
  14. <p class="text-muted"><%= pluralize(@rows.size, "row") %></p>
  15. <% end %>
  16. <% if @rows.any? %>
  17. <% values = @rows.first.values %>
  18. <% chart_id = SecureRandom.hex %>
  19. <% if values.size >= 2 && (values.first.is_a?(Time) || values.first.is_a?(Date)) && values[1..-1].all?{|v| v.is_a?(Numeric) } %>
  20. <% time_k = @columns.keys.first %>
  21. <%= line_chart @columns.keys[1..-1].map{|k| {name: k, data: @rows.map{|r| [r[time_k], r[k]] }} }, id: chart_id, min: nil %>
  22. <% elsif values.size == 3 && (values.first.is_a?(Time) || values.first.is_a?(Date)) && values[1].is_a?(String) && values[2].is_a?(Numeric) %>
  23. <% keys = @columns.keys %>
  24. <%= line_chart @rows.group_by { |v| v[keys[1]] }.map { |name, v| {name: name, data: v.map { |v2| [v2[keys[0]], v2[keys[2]]] } } }, id: chart_id, min: nil %>
  25. <% elsif values.size == 2 && values.first.is_a?(String) && values.last.is_a?(Numeric) %>
  26. <%= pie_chart @rows.map(&:values), library: {sliceVisibilityThreshold: 1 / 40.0}, id: chart_id %>
  27. <% elsif @only_chart %>
  28. <% if @rows.size == 1 && @rows.first.size == 1 %>
  29. <p style="font-size: 160px;"><%= format_value(@rows.first.keys.first, @rows.first.values.first) %></p>
  30. <% else %>
  31. <% @no_chart = true %>
  32. <% end %>
  33. <% end %>
  34. <% unless @only_chart && !@no_chart %>
  35. <% header_width = 100 / @rows.first.keys.size.to_f %>
  36. <div class="results-container">
  37. <table class="table results-table" style="margin-bottom: 0;">
  38. <thead>
  39. <tr>
  40. <% @columns.each do |key, type| %>
  41. <th style="width: <%= header_width %>%;" data-sort="<%= type %>">
  42. <div style="min-width: <%= @min_width_types.include?(key) ? 180 : 60 %>px;">
  43. <%= key %>
  44. </div>
  45. </th>
  46. <% end %>
  47. </tr>
  48. </thead>
  49. <tbody>
  50. <% @rows.each do |row| %>
  51. <tr>
  52. <% row.each do |k, v| %>
  53. <td>
  54. <% if v.is_a?(Time) %>
  55. <% v = v.in_time_zone(Blazer.time_zone) %>
  56. <% end %>
  57. <% unless v.nil? %>
  58. <% if v == "" %>
  59. <div class="text-muted">empty string</div>
  60. <% elsif @linked_columns[k] %>
  61. <%= link_to format_value(k, v), @linked_columns[k].gsub("{value}", u(v.to_s)), target: "_blank" %>
  62. <% else %>
  63. <%= format_value(k, v) %>
  64. <% end %>
  65. <% if v2 = (@boom[k] || {})[v] %>
  66. <div class="text-muted"><%= v2 %></div>
  67. <% end %>
  68. <% end %>
  69. </td>
  70. <% end %>
  71. </tr>
  72. <% end %>
  73. </tbody>
  74. </table>
  75. </div>
  76. <% end %>
  77. <% elsif @only_chart %>
  78. <p class="text-muted">No rows</p>
  79. <% end %>
  80. <% end %>