run.html.erb 3.0 KB

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