Skip to content

Commit

Permalink
refactor topics/index
Browse files Browse the repository at this point in the history
  • Loading branch information
xdite committed Feb 22, 2012
2 parents 404481c + 2989efd commit 00094d6
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -12,7 +12,7 @@ gem "mini_magick","3.3"
gem "devise", "1.5.2"
# 分页

gem "will_paginate", "~> 3.0"
gem "will_paginate", "3.0.pre4"

# 三方平台 OAuth 验证登陆

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -351,7 +351,7 @@ GEM
rack (>= 1.0.0)
warden (1.1.0)
rack (>= 1.0)
will_paginate (3.0.3)
will_paginate (3.0.pre4)
xml-simple (1.1.1)

PLATFORMS
Expand Down Expand Up @@ -415,4 +415,4 @@ DEPENDENCIES
state_machine
uglifier (>= 1.0.3)
unicorn
will_paginate (~> 3.0)
will_paginate (= 3.0.pre4)
2 changes: 1 addition & 1 deletion app/controllers/notifications_controller.rb
Expand Up @@ -4,7 +4,7 @@ class NotificationsController < ApplicationController
respond_to :html, :js, :only => [:destroy, :mark_all_as_read]

def index
@notifications = current_user.notifications.recent.paginate :page => params[:page], :per_page => 20
@notifications = current_user.notifications.recent.paginate( :page => params[:page], :per_page => 20)
current_user.read_notifications(@notifications)
set_seo_meta("提醒")
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/replies_controller.rb
Expand Up @@ -2,8 +2,8 @@
class RepliesController < ApplicationController

load_and_authorize_resource :reply

before_filter :find_topic

def create

@reply = @topic.replies.build(params[:reply])
Expand All @@ -12,7 +12,6 @@ def create
if @reply.save
current_user.read_topic(@topic)
@msg = t("topics.reply_success")

else
@msg = @reply.errors.full_messages.join("<br />")
end
Expand Down
40 changes: 16 additions & 24 deletions app/controllers/topics_controller.rb
Expand Up @@ -13,23 +13,31 @@ def index
@topics = Topic.last_actived.limit(15).includes(:node,:user).paginate(:page => params[:page], :per_page => 15)
set_seo_meta("","#{Setting.app_name}#{t("menu.topics")}")
drop_breadcrumb(t("topics.hot_topic"))
#render :stream => true
end

def feed
@topics = Topic.recent.limit(20).includes(:node,:user)
response.headers['Content-Type'] = 'application/rss+xml'
render :layout => false
end


def node
@node = Node.find(params[:id])
@topics = @node.topics.last_actived.paginate(:page => params[:page],:per_page => 50)
set_seo_meta("#{@node.name} &raquo; #{t("menu.topics")}","#{Setting.app_name}#{t("menu.topics")}#{@node.name}",@node.summary)
drop_breadcrumb("#{@node.name}")
render :action => "index" #, :stream => true
end


def recent
# TODO: 需要 includes :node,:user,但目前用了 paginate 似乎会使得 includes 没有效果
@topics = Topic.recent.paginate(:page => params[:page], :per_page => 50)
drop_breadcrumb(t("topics.topic_list"))
end


def feed
@topics = Topic.recent.limit(20).includes(:node,:user)
response.headers['Content-Type'] = 'application/rss+xml'
render :layout => false
end


def node_feed
@node = Node.find(params[:id])
@topics = @node.topics.recent.limit(20)
Expand All @@ -44,21 +52,6 @@ def node_feed
render :layout => false
end

def recent
# TODO: 需要 includes :node,:user,但目前用了 paginate 似乎会使得 includes 没有效果
@topics = Topic.recent.includes(:node,:user).paginate(:page => params[:page], :per_page => 50)
drop_breadcrumb(t("topics.topic_list"))
render :action => "index" #, :stream => true
end

def search
@topics = Topic.search_tank(params[:key])

set_seo_meta("#{t("common.search")}#{params[:s]} &raquo; #{t("menu.topics")}")
drop_breadcrumb("#{t("common.search")} #{params[:key]}")
render :action => "index" #, :stream => true
end

def show
@topic = Topic.includes(:user, :node).find(params[:id])
@node = @topic.node
Expand All @@ -72,7 +65,6 @@ def show
set_seo_meta("#{@topic.title} &raquo; #{t("menu.topics")}")
drop_breadcrumb("#{@node.name}", node_topics_path(@node.id))
drop_breadcrumb t("topics.read_topic")
# render :stream => true
end

def new
Expand Down
7 changes: 4 additions & 3 deletions app/views/topics/_topic.html.erb
Expand Up @@ -19,13 +19,14 @@
</div>
<div class="info leader">
<%= t("common.by") %> <%= user_name_tag(topic.user) %>
<%= t("common.at") %> <%= render_node_name(topic.node_name,topic.node_id) %> <%= t("common.create_item")%>
<%= t("common.at") %> <%= render_node_name(topic.node) %> <%= t("common.create_item")%>
</div>
<div class="info time">
<% if topic.last_reply_user_login.blank? %>
<% if topic.last_reply.blank? %>
<%= raw t("common.created_at", :time => timeago(topic.created_at))%>
<% else %>
<%= t("common.last_by")%> <%= user_name_tag(topic.last_reply_user_login) %> <%= raw t("common.reply_at", :time => timeago(topic.replied_at))%>
<%= t("common.last_by")%> <%= link_to(topic.last_reply.user_login, user_path(topic.last_reply.user_login)) %> <%= raw t("common.reply_at", :time => timeago(topic.replied_at))%>
<% end %>
</div>
Expand Down
33 changes: 8 additions & 25 deletions app/views/topics/index.html.erb
@@ -1,40 +1,23 @@
<%= render "base" %>

<div class="sidebar">
<%= render "sidebar_for_topic_index" if action_name == "index" %>
<%= render "sidebar_for_topic_recent" if action_name == "recent" %>
<%= render "sidebar_for_topic_node" if action_name == "node" %>
<%= render "sidebar_for_topic_index" %>
</div>

<div class="content">
<div class="box">
<div id="node_info">
<%= render "node_info", :node => @node %>
</div>

<div class="topics">
<%= render :partial => "topics/topic", :collection => @topics %>
<%= render :partial => "topics/topic", :collection => @topics, :as => :topic %>
</div>

<% if action_name == "index" %>
<div class="more">
<%= link_to(t("topics.check_recent_topics"), recent_topics_path)%>
</div>
<% else %>
<%= will_paginate @topics %>
<% end %>
<div class="more">
<%= link_to(t("topics.check_recent_topics"), recent_topics_path)%>
</div>

<% if action_name == "index" %>
<%= render_cell :topics, :index_sections %>
<%= render_cell :topics, :index_locations %>
<% end %>
<% if !@node.blank? %>
<% content_for :node_feed_link do %>
<%= auto_discovery_link_tag(:rss, feed_node_topics_url, :title => "#{@node.name}節點最新話題") %>
<% end %>
<% end %>
</div>

<%= render_cell :topics, :index_sections %>
<%= render_cell :topics, :index_locations %>

</div>

6 changes: 3 additions & 3 deletions app/views/topics/new.html.erb
@@ -1,12 +1,12 @@
<%= render 'base' %>
<%= render "base" %>
<% content_for :sitemap do %>
<li class="active">新建贴子</li>
<% end %>
<%= render 'sidebar_for_new_topic' %>
<%= render "sidebar_for_new_topic" %>

<div class="content">
<div class="box">
<%= render 'form' %>
<%= render "form" %>
</div>
</div>
24 changes: 24 additions & 0 deletions app/views/topics/node.html.erb
@@ -0,0 +1,24 @@
<%= render "base" %>

<div class="sidebar">
<%= render "sidebar_for_topic_node" %>
</div>

<div class="content">
<div class="box">
<div id="node_info">
<%= render "node_info", :node => @node %>
</div>

<div class="topics">
<%= render :partial => "topics/topic", :collection => @topics, :as => :topic %>
</div>
<%= will_paginate @topics %>

</div>

</div>

<% content_for :node_feed_link do %>
<%= auto_discovery_link_tag(:rss, feed_node_topics_url, :title => "#{@node.name}節點最新話題") %>
<% end %>
20 changes: 20 additions & 0 deletions app/views/topics/recent.html.erb
@@ -0,0 +1,20 @@
<%= render "base" %>

<div class="sidebar">
<%= render "sidebar_for_topic_recent" %>
</div>

<div class="content">
<div class="box">
<div id="node_info">
<%= render "node_info", :node => @node %>
</div>

<div class="topics">
<%= render :partial => "topics/topic", :collection => @topics, :as => :topic %>
</div>

<%= will_paginate @topics %>

</div>

10 changes: 5 additions & 5 deletions app/views/users/_info.html.erb
Expand Up @@ -11,21 +11,21 @@
<ul>
<li style="text-align:right;"><%= @user.id %><%= t("menu.users")%></li>
<li> <span>ID:</span><strong><%= @user.login %></strong></li>
<% if !@user.location.blank? %>
<% if @user.location.present? %>
<li><span><%= t("users.city")%>:</span><%= render_user_location(@user) %></li>
<% end %>

<li><span><%= t("users.join_time")%>:</span><%= render_user_join_time(@user) %></li>

<% if !@user.tagline.blank? %>
<% if @user.tagline.present? %>
<li><span><%= t("users.signature")%>:</span><%= render_user_tagline(@user) %></li>
<% end %>
<% if !@user.github.blank? %>
<% if @user.github.present? %>
<li><span>Github:</span><%= render_user_github_url(@user) %> </li>
<% end %>
<% if !@user.website.blank? %>
<% if @user.website..present? %>
<li><span><%= t("users.personal_website")%>:</span><%= render_user_personal_website(@user)%></li>
<% end %>
</ul>
Expand All @@ -34,7 +34,7 @@

</div>

<% if !@user.bio.blank? %>
<% if @user.bio.present? %>
<div class="bio box">
<h5>個人介绍</h5>
<p><%= auto_link(simple_format(@user.bio)) %></p>
Expand Down

0 comments on commit 00094d6

Please sign in to comment.