_show.html.erb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <% content_for :head do %>
  2. <%= javascript_include_tag "graphing" %>
  3. <%= javascript_include_tag "tweets" %>
  4. <%= javascript_include_tag "//platform.twitter.com/widgets.js", charset: "utf-8", async: "async" %>
  5. <% end %>
  6. <% grouped_events = @agent.events.order("id desc").limit(2000).group_by {|e| e.payload[:filter] || e.payload[:match] }%>
  7. <% if grouped_events.length > 0 %>
  8. <% if @agent.options[:generate] == "events" %>
  9. <h3>Recent Tweets</h3>
  10. <% grouped_events.each do |filter, group| %>
  11. <div class="filter-group tweets">
  12. <div class='filter'><%= filter %></div>
  13. <% group.each do |event| %>
  14. <% tweet = event.payload %>
  15. <% text = tweet.dig(:extended_tweet, :full_text) %>
  16. <% next unless text.present? %>
  17. <% screen_name = tweet.dig(:user, :screen_name) %>
  18. <div class='tweet'><span class="tweet-body" data-tweet-id='<%= tweet[:id_str] %>'><span class="tweet-plain" title="Click to expand"><%= link_to "@#{screen_name}", "https://twitter.com/#{URI.encode(screen_name)}" %>: <%= text %> - <%= link_to l(Time.zone.parse(tweet[:created_at]), format: :long), "https://twitter.com/#{URI.encode(screen_name)}/status/#{URI.encode(tweet[:id_str])}" %></span></span> (<%= link_to 'event', event_path(id: event.id) %>)</div>
  19. <% end %>
  20. </div>
  21. <% end %>
  22. <% else %>
  23. <h3>Recent Tweet Trends</h3>
  24. <% grouped_events.each.with_index do |(filter, group), index| %>
  25. <div class="filter-group counts">
  26. <div class='filter'><%= link_to filter, "https://twitter.com/search?q=#{CGI::escape filter}", :target => "blank" %></div>
  27. <div class="chart-container group-<%= index.to_s %>">
  28. <div class="y-axis"></div>
  29. <div class="chart"></div>
  30. <div class="timeline"></div>
  31. </div>
  32. <script>
  33. $(function() {
  34. var $chart = $(".chart-container.group-<%= index.to_s %>").last();
  35. var data = <%= Utils.jsonify(group.select {|e| e.payload[:count].present? }.sort_by {|e| e.payload[:time] }.map {|e| { :x => e.payload[:time].to_i, :y => e.payload[:count].to_i } }) %>;
  36. var name = <%= Utils.jsonify(filter) %>;
  37. renderGraph($chart, data, [], name);
  38. });
  39. </script>
  40. </div>
  41. <% end %>
  42. <% end %>
  43. <% else %>
  44. <p>
  45. No recent tweets found.
  46. </p>
  47. <% end %>