thingspeak/app/views/status/_recent.html.erb

48 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

<html>
<head>
<%= stylesheet_link_tag 'application' %>
2014-08-02 04:10:21 +02:00
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<%= javascript_include_tag 'application' %>
</head>
<body>
<div class="recent_status">
<% @statuses.each do |r| %>
2014-03-14 00:16:35 +01:00
<div ><span class="status_messages" id="<%= r.entry_id %>"><%= r.status %><br><abbr class="timeago" title="<%= r.created_at %>"><%= r.created_at %></abbr></div>
<br>
<% end %>
<div>
<script>
2014-08-01 21:57:02 +02:00
$(document).on('page:load ready', function() {
$(".timeago").timeago();
var refreshInterval = setInterval(refreshStatus, 1 * 60 * 1000);
2014-08-01 21:57:02 +02:00
});
function refreshStatus() {
2014-08-01 21:57:02 +02:00
$.getJSON("/channels/<%= @channel_id %>/status/recent", function(data){
//look for most recent status and only append if the new status has a greater entry_id
var firstId = $(".status_messages").first().attr('id');
for(var i in data) {
if (data[i].entry_id > firstId) {
2014-08-01 21:57:02 +02:00
$(".recent_status").prepend("<div><span class=\"status_messages\" id=\"" +
data[i].entry_id + "\">"+
data[i].status +
2014-08-01 21:57:02 +02:00
"</span><br><abbr class=\"timeago\" title=\"" +
data[i].created_at + "\">" +
data[i].created_at + "</abbr></div></br>");
}
2014-08-01 21:57:02 +02:00
}
$(".timeago").timeago();
});
}
</script>
</body>
</html>
2014-08-01 21:57:02 +02:00