From 124403a9216a455f79372468a7a86614dd3922f7 Mon Sep 17 00:00:00 2001 From: albert Date: Tue, 23 Aug 2011 17:11:21 -0400 Subject: [PATCH] implemented last-forum-read-at --- Gemfile | 1 - Gemfile.lock | 4 ---- app/assets/javascripts/forum_posts.js | 13 +++++++++++++ app/assets/stylesheets/application.css.scss | 5 ++++- app/controllers/forum_topics_controller.rb | 7 +++++++ app/controllers/sessions_controller.rb | 1 + app/helpers/application_helper.rb | 13 ++++++++++--- app/logical/anonymous_user.rb | 7 +++++++ app/presenters/forum_topic_presenter.rb | 4 ---- app/views/forum_topics/_paginator.html.erb | 1 - app/views/forum_topics/index.html.erb | 8 +++++++- app/views/forum_topics/show.html.erb | 3 ++- 12 files changed, 51 insertions(+), 16 deletions(-) delete mode 100644 app/views/forum_topics/_paginator.html.erb diff --git a/Gemfile b/Gemfile index f140d19f0..c79bcabcd 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index b482da19f..352b3e780 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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! diff --git a/app/assets/javascripts/forum_posts.js b/app/assets/javascripts/forum_posts.js index 6caf4e4f2..0ec5b9a10 100644 --- a/app/assets/javascripts/forum_posts.js +++ b/app/assets/javascripts/forum_posts.js @@ -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() { diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 164835f74..229215959 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -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; diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 5668dfdad..7f2f7b335 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -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] ||= {} diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index de0478d9d..310758350 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 95304d0cc..254503f97 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index eb352dac4..1faf5b95e 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -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 diff --git a/app/presenters/forum_topic_presenter.rb b/app/presenters/forum_topic_presenter.rb index 538a0a751..a10593cbc 100644 --- a/app/presenters/forum_topic_presenter.rb +++ b/app/presenters/forum_topic_presenter.rb @@ -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 diff --git a/app/views/forum_topics/_paginator.html.erb b/app/views/forum_topics/_paginator.html.erb deleted file mode 100644 index 67bc366e6..000000000 --- a/app/views/forum_topics/_paginator.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @forum_topic.presenter(@forum_posts).pagination_html(self) %> diff --git a/app/views/forum_topics/index.html.erb b/app/views/forum_topics/index.html.erb index f1ed11ebc..131270f18 100644 --- a/app/views/forum_topics/index.html.erb +++ b/app/views/forum_topics/index.html.erb @@ -22,7 +22,13 @@ <% end %> + + <%= numbered_paginator(@forum_topics) %> -<%= render "secondary_links" %> \ No newline at end of file +<%= render "secondary_links" %> + +<%= content_for(:html_header) do %> + +<% end %> diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index 41a8d4a96..8eca7f10b 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -7,7 +7,8 @@ <% end %> <%= render "forum_posts/listing", :forum_posts => @forum_posts %> - <%= render "paginator" %> + + <%= numbered_paginator(@forum_posts) %>