relative timestamps
This commit is contained in:
31
app/assets/javascripts/ago.js
Normal file
31
app/assets/javascripts/ago.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
$.fn.ago = function(callback) {
|
||||||
|
units = [
|
||||||
|
['m', 60],
|
||||||
|
['h', 3600],
|
||||||
|
['d', 86400],
|
||||||
|
['w', 604800],
|
||||||
|
['y', 31536000]
|
||||||
|
];
|
||||||
|
this.each(function() {
|
||||||
|
ago_date = callback ? callback(this) : new Date($(this).text());
|
||||||
|
ago_time = Math.floor((new Date().getTime() - ago_date.getTime())/1000);
|
||||||
|
ago_unit = null;
|
||||||
|
units.forEach(function(time, i) {
|
||||||
|
if (Math.abs(ago_time) >= time[1]) {
|
||||||
|
ago_unit = i;
|
||||||
|
} else {
|
||||||
|
// we found the greatest unit
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ago_unit !== null) {
|
||||||
|
unit = units[ago_unit];
|
||||||
|
ago_str = Math.abs(Math.floor(ago_time/unit[1])).toString() + unit[0] + (ago_time < 0 ? " ahead" : " ago");
|
||||||
|
} else {
|
||||||
|
ago_str = "just now";
|
||||||
|
}
|
||||||
|
|
||||||
|
$(this).text(ago_str);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -8,7 +8,7 @@ $(function(){
|
|||||||
height: 0
|
height: 0
|
||||||
}, 'slow', function(){
|
}, 'slow', function(){
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@@ -19,7 +19,7 @@ $(function(){
|
|||||||
height: 0
|
height: 0
|
||||||
}, 'slow', function(){
|
}, 'slow', function(){
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}, 4000);
|
}, 4000);
|
||||||
var pressed = new Array(10);
|
var pressed = new Array(10);
|
||||||
@@ -37,7 +37,15 @@ $(function(){
|
|||||||
if ($(this).attr("class")) {
|
if ($(this).attr("class")) {
|
||||||
$(this).parent().attr("lang", $(this).attr("class").replace("hljs", "").trim());
|
$(this).parent().attr("lang", $(this).attr("class").replace("hljs", "").trim());
|
||||||
} else {
|
} else {
|
||||||
$(this).parent().attr("lang", "(language unknown)")
|
$(this).parent().attr("lang", "(language unknown)");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
updateTimestamps();
|
||||||
|
setInterval(updateTimestamps, 1000*10);
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateTimestamps() {
|
||||||
|
$('time').ago(function(elem){
|
||||||
|
return new Date($(elem).attr('datetime'));
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -12,6 +12,5 @@
|
|||||||
//= require jquery
|
//= require jquery
|
||||||
//= require jquery_ujs
|
//= require jquery_ujs
|
||||||
//= require app
|
//= require app
|
||||||
//= require moment
|
//= require ago
|
||||||
//= require highlight
|
//= require highlight
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -57,6 +57,21 @@ class ForumsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if admin?
|
||||||
|
if @forum.destroy
|
||||||
|
flash[:notice] = "Forum deleted."
|
||||||
|
else
|
||||||
|
flash[:alert] = "Something went wrong"
|
||||||
|
render :new
|
||||||
|
return
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash[:alert] = "You are not allowed to delete a forum."
|
||||||
|
end
|
||||||
|
redirect_to forums_path
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="item-group with-avatar" id="post-<%= p.id %>">
|
<div class="item-group with-avatar" id="post-<%= p.id %>">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<%= link_to(p.author.avatar(64), p.author, title: p.author.ign) %>
|
<%= link_to(p.author.avatar(64), p.author, title: p.author.ign) %>
|
||||||
<%= render partial: "users/username", locals: { user: p.author } %> <time><%= link_to p.created_at.strftime("%e. %b %Y, %H:%M"), p %></time>
|
<%= render partial: "users/username", locals: { user: p.author } %> <%= link_to p do %><time datetime="<%= p.created_at.to_datetime.rfc3339 %>"><%= p.created_at.strftime("%e %b %Y, %H:%M") %></time><% end %>
|
||||||
<span class="comment-counter">
|
<span class="comment-counter">
|
||||||
<%= link_to pluralize(p.comments.count, "Comment"), p %>
|
<%= link_to pluralize(p.comments.count, "Comment"), p %>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="item-group post with-avatar" id="post-<%= @post.id %>">
|
<div class="item-group post with-avatar" id="post-<%= @post.id %>">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<%= link_to(@post.author.avatar(64), @post.author, title: @post.author.ign) %>
|
<%= link_to(@post.author.avatar(64), @post.author, title: @post.author.ign) %>
|
||||||
<%= render partial: "users/username", locals: { user: @post.author } %> <time><%= link_to @post.created_at.strftime("%e. %b %Y, %H:%M"), p %></time>
|
<%= render partial: "users/username", locals: { user: @post.author } %> <%= link_to p do %><time datetime="<%= @post.created_at.to_datetime.rfc3339 %>"><%= @post.created_at.strftime("%e %b %Y, %H:%M") %></time><% end %>
|
||||||
<%= link_to "edit", edit_blogpost_path(@post.id), class: "editlink" if mod? %>
|
<%= link_to "edit", edit_blogpost_path(@post.id), class: "editlink" if mod? %>
|
||||||
<div class="clear-right"></div>
|
<div class="clear-right"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="header <%= "op" if c.author.is?(c.blogpost.author) %>">
|
<div class="header <%= "op" if c.author.is?(c.blogpost.author) %>">
|
||||||
<%= link_to(c.author.avatar(64), c.author, title: c.author.ign) %>
|
<%= link_to(c.author.avatar(64), c.author, title: c.author.ign) %>
|
||||||
<%= render partial: "users/username", locals: { user: c.author } %>
|
<%= render partial: "users/username", locals: { user: c.author } %>
|
||||||
<time><%= link_to c.created_at.strftime("%e. %b %Y, %H:%M"), "#comment-#{c.id}" %></time>
|
<%= link_to "#comment-#{c.id}" do %><time datetime="<%= c.created_at.to_datetime.rfc3339 %>"><%= c.created_at.strftime("%e %b %Y, %H:%M") %></time><% end %>
|
||||||
|
|
||||||
<%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c), class: "editlink" if (mod? || c.author.is?(current_user)) %>
|
<%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c), class: "editlink" if (mod? || c.author.is?(current_user)) %>
|
||||||
<div class="clear-right"></div>
|
<div class="clear-right"></div>
|
||||||
|
|||||||
@@ -22,5 +22,5 @@
|
|||||||
</table>
|
</table>
|
||||||
<p><%= f.submit "Update forum", class: "btn blue left" %></p>
|
<p><%= f.submit "Update forum", class: "btn blue left" %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%# TODO delete %>
|
<p><%= button_to "Delete forum", @forum, method: "delete", data: {confirm: "Delete forum forever?\nThreads won't be accessible!"}, class: "btn red right" %></p>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<div class="item-group with-avatar" id="thread-<%= thread.id %>">
|
<div class="item-group with-avatar" id="thread-<%= thread.id %>">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %>
|
<%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %>
|
||||||
<%= render partial: "users/username", locals: { user: thread.author } %> <time><%= link_to thread.created_at.strftime("%e. %b %Y, %H:%M"), thread %></time>
|
<%= render partial: "users/username", locals: { user: thread.author } %> <%= link_to thread do %><time datetime="<%= thread.created_at.to_datetime.rfc3339 %>"><%= thread.created_at.strftime("%e %b %Y, %H:%M") %></time><% end %>
|
||||||
<span class="comment-counter">
|
<span class="comment-counter">
|
||||||
<%= link_to pluralize(thread.replies.count, "Reply"), thread %>
|
<%= link_to pluralize(thread.replies.count, "Reply"), thread %>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
<div class="item-group thread with-avatar" id="thread-<%= @thread.id %>">
|
<div class="item-group thread with-avatar" id="thread-<%= @thread.id %>">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<%= link_to(@thread.author.avatar(64), @thread.author, title: @thread.author.ign) %>
|
<%= link_to(@thread.author.avatar(64), @thread.author, title: @thread.author.ign) %>
|
||||||
<%= render partial: "users/username", locals: { user: @thread.author } %> <time><%= link_to @thread.created_at.strftime("%e. %b %Y, %H:%M"), p %></time>
|
<%= render partial: "users/username", locals: { user: @thread.author } %> <%= link_to p do %><time datetime="<%= @thread.created_at.to_datetime.rfc3339 %>"><%= @thread.created_at.strftime("%e %b %Y, %H:%M") %></time><% end %>
|
||||||
<%= link_to "edit", edit_forumthread_path( @thread), class: "editlink" if (@thread.author.is?(current_user) || mod?) %>
|
<%= link_to "edit", edit_forumthread_path( @thread), class: "editlink" if (@thread.author.is?(current_user) || mod?) %>
|
||||||
<div class="clear-right"></div>
|
<div class="clear-right"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="items">
|
<div class="items">
|
||||||
<% if @thread.edited? %>
|
<% if @thread.edited? %>
|
||||||
<div class="item edited">
|
<div class="item edited">
|
||||||
Last edited <time><%= @thread.updated_at.strftime("%e. %b %Y, %H:%M") %></time> by <%= link_to @thread.editor.name, @thread.editor %>.
|
Last edited <time datetime="<%= @thread.updated_at.to_datetime.rfc3339 %>"><%= @thread.updated_at.strftime("%e %b %Y, %H:%M") %></time> by <%= link_to @thread.editor.name, @thread.editor %>.
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="item content">
|
<div class="item content">
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border:1px solid black;">Time</td>
|
<td style="border:1px solid black;">Time</td>
|
||||||
<td style="border:1px solid black;"><%= @user.created_at.strftime("%e. %b %Y, %H:%M") %></td>
|
<td style="border:1px solid black;"><%= @user.created_at.strftime("%e %b %Y, %H:%M") %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border:1px solid black;">Role</td>
|
<td style="border:1px solid black;">Role</td>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="header">
|
<div class="header">
|
||||||
<%= link_to(reply.author.avatar(64), reply.author, title: reply.author.ign) %>
|
<%= link_to(reply.author.avatar(64), reply.author, title: reply.author.ign) %>
|
||||||
<%= render partial: "users/username", locals: { user: reply.author } %>
|
<%= render partial: "users/username", locals: { user: reply.author } %>
|
||||||
<time><%= link_to reply.created_at.strftime("%e. %b %Y, %H:%M"), "#reply-#{reply.id}" %></time>
|
<%= link_to "#reply-#{reply.id}" do %><time datetime="<%= reply.created_at.to_datetime.rfc3339 %>"><%= reply.created_at.strftime("%e %b %Y, %H:%M") %></time><% end %>
|
||||||
|
|
||||||
<%= link_to "edit", edit_forumthread_threadreply_path(reply.thread, reply), class: "editlink" if mod? || reply.thread.author.is?(current_user) %>
|
<%= link_to "edit", edit_forumthread_threadreply_path(reply.thread, reply), class: "editlink" if mod? || reply.thread.author.is?(current_user) %>
|
||||||
<div class="clear-right"></div>
|
<div class="clear-right"></div>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Joined</td>
|
<td>Joined</td>
|
||||||
<td><%= @user.created_at.strftime("%e. %b %Y, %H:%M") %></td>
|
<td><%= @user.created_at.strftime("%e %b %Y, %H:%M") %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% if mod? || @user.is?(current_user) %>
|
<% if mod? || @user.is?(current_user) %>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Last seen</td>
|
<td>Last seen</td>
|
||||||
<td><%= @user.last_seen.strftime("%e. %b %Y, %H:%M") %></td>
|
<td><%= @user.last_seen.strftime("%e %b %Y, %H:%M") %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user