123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <% if @error %>
- <% if @only_chart %>
- <p><%= @error %></p>
- <% else %>
- <div class="alert alert-danger"><%= @error %></div>
- <% end %>
- <% elsif !@success %>
- <% if @only_chart %>
- <p>Choose variables</p>
- <% else %>
- <div class="alert alert-info">Can’t preview queries with variables...yet!</div>
- <% end %>
- <% else %>
- <% unless @only_chart %>
- <p class="text-muted"><%= pluralize(@rows.size, "row") %></p>
- <% end %>
- <% if @rows.any? %>
- <% values = @rows.first.values %>
- <% chart_id = SecureRandom.hex %>
- <% if values.size >= 2 && (values.first.is_a?(Time) || values.first.is_a?(Date)) && values[1..-1].all?{|v| v.is_a?(Numeric) } %>
- <% time_k = @columns.keys.first %>
- <%= 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 %>
- <% elsif values.size == 3 && (values.first.is_a?(Time) || values.first.is_a?(Date)) && values[1].is_a?(String) && values[2].is_a?(Numeric) %>
- <% keys = @columns.keys %>
- <%= 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 %>
- <% elsif values.size == 2 && values.first.is_a?(String) && values.last.is_a?(Numeric) %>
- <%= pie_chart @rows.map(&:values), library: {sliceVisibilityThreshold: 1 / 40.0}, id: chart_id %>
- <% elsif @only_chart %>
- <p>No chart</p>
- <% end %>
- <% unless @only_chart %>
- <% header_width = 100 / @rows.first.keys.size.to_f %>
- <table class="table">
- <thead>
- <tr>
- <% @columns.each do |key, type| %>
- <th style="width: <%= header_width %>%;" data-sort="<%= type %>">
- <div style="min-width: <%= @min_width_types.include?(key) ? 180 : 60 %>px;">
- <%= key %>
- </div>
- </th>
- <% end %>
- </tr>
- </thead>
- <tbody>
- <% @rows.each do |row| %>
- <tr>
- <% row.each do |k, v| %>
- <td>
- <% if v.is_a?(Time) %>
- <% v = v.in_time_zone(Blazer.time_zone) %>
- <% end %>
- <% unless v.nil? %>
- <% if v == "" %>
- <div class="text-muted">empty string</div>
- <% elsif @linked_columns[k] %>
- <%= link_to format_value(k, v), @linked_columns[k].gsub("{value}", u(v.to_s)), target: "_blank" %>
- <% else %>
- <%= format_value(k, v) %>
- <% end %>
- <% if v2 = (@boom[k] || {})[v] %>
- <div class="text-muted"><%= v2 %></div>
- <% end %>
- <% end %>
- </td>
- <% end %>
- </tr>
- <% end %>
- </tbody>
- </table>
- <% end %>
- <% elsif @only_chart %>
- <p>No chart</p>
- <% end %>
- <% end %>
|