implemented last-forum-read-at

This commit is contained in:
albert
2011-08-23 17:11:21 -04:00
parent e3a9614930
commit 124403a921
12 changed files with 51 additions and 16 deletions

View File

@@ -25,4 +25,3 @@ gem "nokogiri"
gem "meta_search", :git => "git://github.com/ernie/meta_search.git"
gem "silent-postgres"
gem "whenever", :require => false
gem "bourbon"

View File

@@ -48,8 +48,6 @@ GEM
multi_json (~> 1.0)
arel (2.1.4)
bcrypt-ruby (2.1.4)
bourbon (0.1.5)
sass (>= 3.1)
builder (3.0.0)
daemons (1.1.4)
delayed_job (2.1.4)
@@ -105,7 +103,6 @@ GEM
thor (~> 0.14.6)
rake (0.9.2)
rdoc (3.9.1)
sass (3.1.7)
shoulda (2.11.3)
silent-postgres (0.0.8)
simple_form (1.4.2)
@@ -137,7 +134,6 @@ PLATFORMS
ruby
DEPENDENCIES
bourbon
delayed_job
factory_girl
ffaker!

View File

@@ -5,6 +5,19 @@
$("#c-forum-topics #preview").hide();
this.initialize_preview_link();
this.initialize_last_forum_read_at();
}
Danbooru.ForumPost.initialize_last_forum_read_at = function() {
var last_forum_read_at = Date.parse(Danbooru.meta("last-forum-read-at"));
$("#c-forum-topics #a-index time").each(function(i, x) {
var $x = $(x);
var $date = Date.parse($x.attr("datetime"));
if (Date.parse($x.attr("datetime")) > last_forum_read_at) {
$x.closest("tr").addClass("new-topic");
}
});
}
Danbooru.ForumPost.initialize_preview_link = function() {

View File

@@ -1,5 +1,4 @@
/*= require "smoothness/jquery-ui-1.8.5.custom.css" */
@import 'bourbon';
$link_color: #006FFA;
$link_hover_color: #9093FF;
@@ -897,6 +896,10 @@ div#c-forum-topics {
color: #AAA;
}
tr.new-topic {
font-weight: bold;
}
div#form-content {
float: left;
width: 450px;

View File

@@ -2,6 +2,7 @@ class ForumTopicsController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show]
before_filter :normalize_search, :only => :index
before_filter :update_last_forum_read_at, :only => [:index, :show]
rescue_from User::PrivilegeError, :with => "static/access_denied"
def new
@@ -56,6 +57,12 @@ private
forum_topic.is_sticky = params[:forum_topic][:is_sticky]
end
def update_last_forum_read_at
return if CurrentUser.last_forum_read_at.present? && CurrentUser.last_forum_read_at > 1.day.ago
CurrentUser.update_column(:last_forum_read_at, Time.now)
end
def normalize_search
if params[:title_matches]
params[:search] ||= {}

View File

@@ -6,6 +6,7 @@ class SessionsController < ApplicationController
def create
if User.authenticate(params[:name], params[:password])
@user = User.find_by_name(params[:name])
@user.update_column(:last_logged_in_at, Time.now)
session[:user_id] = @user.id
redirect_to(params[:url] || session[:previous_uri] || posts_path, :notice => "You are now logged in.")
else

View File

@@ -23,13 +23,20 @@ module ApplicationHelper
end
end
def time_tag(content = nil, time)
zone = time.strftime("%z")
datetime = time.strftime("%Y-%m-%dT%H:%M" + zone[0, 3] + ":" + zone[3, 2])
content_tag(:time, content || datetime, :datetime => datetime)
end
def compact_time(time)
if time > Time.now.beginning_of_day
time.strftime("%H:%M")
time_tag(time.strftime("%H:%M"), time)
elsif time > Time.now.beginning_of_year
time.strftime("%b %e")
time_tag(time.strftime("%b %e"), time)
else
time.strftime("%b %e, %Y")
time_tag(time.strftime("%b %e, %Y"), time)
end
end

View File

@@ -112,6 +112,13 @@ class AnonymousUser
[]
end
def last_forum_read_at
Time.now
end
def update_column(*params)
end
%w(member banned privileged contributor janitor moderator admin).each do |name|
define_method("is_#{name}?") do
false

View File

@@ -5,8 +5,4 @@ class ForumTopicPresenter < Presenter
@forum_posts = forum_posts
@forum_topic = forum_topic
end
def pagination_html(template)
Paginators::ForumTopic.new(forum_topic, forum_posts).numbered_pagination_html(template)
end
end

View File

@@ -1 +0,0 @@
<%= @forum_topic.presenter(@forum_posts).pagination_html(self) %>

View File

@@ -22,7 +22,13 @@
<% end %>
</tbody>
</table>
<%= numbered_paginator(@forum_topics) %>
</div>
</div>
<%= render "secondary_links" %>
<%= render "secondary_links" %>
<%= content_for(:html_header) do %>
<meta name="last-forum-read-at" content="<%= CurrentUser.last_forum_read_at.to_date %>">
<% end %>

View File

@@ -7,7 +7,8 @@
<% end %>
<%= render "forum_posts/listing", :forum_posts => @forum_posts %>
<%= render "paginator" %>
<%= numbered_paginator(@forum_posts) %>
</div>
</div>