diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index ba7b6284d..53090121e 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -96,38 +96,74 @@ class ForumsController < ApplicationController end def index - @offset, @limit = api_offset_and_limit({:limit => 10}) - @forums = Memo.all - + order = "" + @order_str = "" if(params[:reorder_complex]) - @type="reorder_complex" - @str=params[:reorder_complex] - @forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}") + order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" + @order_str = "reorder_complex="+params[:reorder_complex] elsif(params[:reorder_popu]) - @type="reorder_popu" - @str=params[:reorder_popu] - @forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}") + order = "replies_count #{params[:reorder_popu]}" + @order_str = "reorder_popu="+params[:reorder_popu] elsif(params[:reorder_time]) - @type="reorder_time" - @str=params[:reorder_time] - @forums_all = Forum.reorder("updated_at #{params[:reorder_time]}") + order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}" + @order_str = "reorder_time="+params[:reorder_time] else - params[:reorder_complex] = "desc" - @type="reorder_complex" - @str=params[:reorder_complex] - @forums_all = Forum.reorder("topic_count desc,updated_at desc") + order = "#{Memo.table_name}.updated_at desc" + @order_str = "reorder_time=desc" end - @forums_count = @forums_all.count - @forums_pages = Paginator.new @forums_count, @limit, params['page'] - - @offset ||= @forums_pages.offset - @forums = @forums_all.offset(@offset).limit(@limit).all - #@forums = Forum.all + @memo = Memo.new(:forum => @forum) + @topic_count = Memo.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = Memo.includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + reorder(order). + preload(:author, {:last_reply => :author}). + all + @forums = Forum.includes(:memos).preload(:topics) + @my_topic_count = Memo.where("author_id = #{User.current.id} and parent_id is null").count + @my_replies_count = Memo.where("author_id = #{User.current.id} and parent_id is not null").count + @errors = params[:errors] respond_to do |format| - format.html{render :layout => 'base_new_forum'} format.js - format.json { render json: @forums } + format.html { + render :layout => 'base_new_forum' + }# show.html.erb + format.json { render json: @forum } end + + # @offset, @limit = api_offset_and_limit({:limit => 10}) + # @forums = Memo.all + # + # if(params[:reorder_complex]) + # @type="reorder_complex" + # @str=params[:reorder_complex] + # @forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}") + # elsif(params[:reorder_popu]) + # @type="reorder_popu" + # @str=params[:reorder_popu] + # @forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}") + # elsif(params[:reorder_time]) + # @type="reorder_time" + # @str=params[:reorder_time] + # @forums_all = Forum.reorder("updated_at #{params[:reorder_time]}") + # else + # params[:reorder_complex] = "desc" + # @type="reorder_complex" + # @str=params[:reorder_complex] + # @forums_all = Forum.reorder("topic_count desc,updated_at desc") + # end + # @forums_count = @forums_all.count + # @forums_pages = Paginator.new @forums_count, @limit, params['page'] + # + # @offset ||= @forums_pages.offset + # @forums = @forums_all.offset(@offset).limit(@limit).all + # #@forums = Forum.all + # respond_to do |format| + # format.html{render :layout => 'base_new_forum'} + # format.js + # format.json { render json: @forums } + # end end # GET /forums/1 @@ -161,7 +197,7 @@ class ForumsController < ApplicationController reorder(order). preload(:author, {:last_reply => :author}). all - @memos + @forums = Forum.includes(:memos).preload(:topics) @my_topic_count = Memo.where("author_id = #{User.current.id} and parent_id is null").count @my_replies_count = Memo.where("author_id = #{User.current.id} and parent_id is not null").count @errors = params[:errors] @@ -200,18 +236,17 @@ class ForumsController < ApplicationController # Author lizanle # Description after save后需要进行资源记录的更新 # owner_type = 2 对应的是 forum - @save_flag=true + @save_flag = true if params[:asset_id] ids = params[:asset_id].split(',') - update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM + update_kindeditor_assets_owner ids, @forum.id, OwnerTypeHelper::FORUM end #end respond_to do |format| - format.js + format.js{ redirect_to forums_path, notice: l(:label_forum_create_succ)} format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } format.json { render json: @forum, status: :created, location: @forum } end - else @save_flag=false respond_to do |format| diff --git a/app/views/forums/_new.html.erb b/app/views/forums/_new.html.erb index d195168f6..2feb28eb6 100644 --- a/app/views/forums/_new.html.erb +++ b/app/views/forums/_new.html.erb @@ -5,21 +5,30 @@
- <%= labelled_form_for(@memo, :url => forum_memos_path(@forum),:remote=>true) do |f| %> + <%= form_tag({:controller => 'forums', :action => 'create'}, :method => 'post', :id => "forum_new") do |f| %>
- - + 取消 + 确定
<% end %>
- \ No newline at end of file + + + \ No newline at end of file diff --git a/app/views/forums/_right_bar.html.erb b/app/views/forums/_right_bar.html.erb index c1832b291..056cbd1ba 100644 --- a/app/views/forums/_right_bar.html.erb +++ b/app/views/forums/_right_bar.html.erb @@ -1,41 +1,21 @@

问吧

- 新建贴吧 -
-
-

新手讨论吧

- - -
-
-

新手讨论吧新手讨论吧新手讨论吧

- - -
-
-

新手讨论吧

- - + <%= link_to "新建贴吧", new_forum_path, :class => "btn-blue btn fr mt5 mr5", :remote => true %>
+ <% @forums.each do |forum| %> +
+

<%= link_to forum.name, forum_path(forum), :class => "" %>

+ + +
+ <% end %> 点击展开更多
\ No newline at end of file diff --git a/app/views/forums/create.js.erb b/app/views/forums/create.js.erb index ee8172cbd..39bebe20a 100644 --- a/app/views/forums/create.js.erb +++ b/app/views/forums/create.js.erb @@ -1,7 +1,5 @@ <%if @save_flag%> -//$('#new_forum_div').slideToggle();$('#create_btn').parent().slideToggle(); -//$('#reorder_time').click(); - window.location.href= "<%= host_with_protocol %>"+"/forums/" + "<%= @forum.id%>" +$("#forum_right_bar").html('<%= escape_javascript( render :partial => 'forums/right_bar') %>'); <%else%> $("#error").html("<%= @forum.errors.full_messages[0]%>").show(); <%end %> diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 4de6e4fab..5028f4131 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -1,179 +1,164 @@ -<%= javascript_include_tag 'new_user' %> -<%= stylesheet_link_tag 'css/common','css/public'%> - -
-
-
- -
- <%= render :partial => 'post_banner' ,:locals => {:order_type=>@type,:order_str=>@str}%> - - - - - +
+ + -
-
- <%= render :partial => 'forum_list',:locals => {:forums=>@forums}%> -
-
    - <%= pagination_links_full @forums_pages, @forums_count ,:per_page_links => true,:remote =>true,:flag=>true%> -
+ + +
+ <%= link_to "发布新帖", new_forum_path(@forums), :class => "c_white db creatPostIcon bBlue", :remote => true %> + +
-
-
- <%= render :partial => "forums/right_bar" %> -
-
+
+
+ <%= render :partial => 'show_topics',:locals => {:memos=>@memos}%> +
+ + + + + + + + + + +
+ +
+
<%= link_to image_tag(url_to_avatar(User.current),:width=>50,:height => 50,:alt=>'贴吧图像' ), user_path( User.current) %>
+
+
我在贴吧
+ +
+
+
<%= @my_topic_count %>
+
发帖
+
+
+
+
+ +
+ <%= render :partial => "forums/right_bar" %> +
+ \ No newline at end of file diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index f5451c95a..94dd52318 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -28,6 +28,9 @@ <% end %> + + +
时间
人气
@@ -55,7 +58,25 @@
-
+ +
+
<%= link_to image_tag(url_to_avatar(User.current),:width=>50,:height => 50,:alt=>'贴吧图像' ), user_path( User.current) %>
+
+
我在贴吧
+ +
+
+
<%= @my_topic_count %>
+
发帖
+
+
+
+
+ +
<%= render :partial => "forums/right_bar" %>