From 1da8288fe769938953b36b4551f181980b8b6c3e Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Fri, 29 Apr 2016 13:42:58 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/blogs_controller.rb | 5 +- app/controllers/boards_controller.rb | 5 +- app/controllers/news_controller.rb | 37 +++++++++++- app/controllers/users_controller.rb | 2 +- app/helpers/application_helper.rb | 23 ++++++++ app/views/blogs/_article.html.erb | 16 +++--- app/views/forums/_show_topics.html.erb | 17 +++--- app/views/news/_course_news_detail.html.erb | 37 +----------- app/views/news/index.js.erb | 2 +- app/views/users/_course_boardlist.html.erb | 16 +++--- app/views/users/_course_newslist.html.erb | 64 +++++++++++++++++++++ app/views/users/_intro_content_ex.html.erb | 17 ++---- app/views/users/_project_boardlist.html.erb | 16 +++--- app/views/users/_user_course_list.html.erb | 21 ++++--- app/views/users/_user_project_list.html.erb | 16 +++--- public/javascripts/application.js | 16 ++++++ public/stylesheets/courses.css | 2 +- public/stylesheets/new_user.css | 11 ++-- public/stylesheets/project.css | 2 +- 19 files changed, 217 insertions(+), 108 deletions(-) create mode 100644 app/views/users/_course_newslist.html.erb diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 63b0da009..6bb90afe1 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -24,8 +24,9 @@ class BlogsController < ApplicationController #根据 赞+回复数排序 if @order.to_i == 2 @type = 2 - @b_sort == 1 ? @topics = @topics.sort{|x,y| get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) <=> get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) } : @topics = @topics.sort{|x,y| get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) <=> get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) } - @topics = @topics.sort{|x,y| y.sticky <=> x.sticky} + @b_sort == 1 ? @topics = @topics.sort{|x,y| get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) <=> get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) } : @topics = @topics.sort{|x,y| get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) <=> get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) } + + @topics = sort_by_sticky @topics else @type = 1 end diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 2e499ea1d..0bccdd139 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -103,7 +103,6 @@ class BoardsController < ApplicationController @topic_count = @board ? @board.topics.count : 0 if @project if @board - limit = 10; @topic_count = @board.topics.count(); @topic_pages = 0#(params[:page] ? params[:page].to_i + 1 : 0) *10 @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}"). @@ -126,13 +125,13 @@ class BoardsController < ApplicationController if @order.to_i == 2 @type = 2 @b_sort == 1 ? @topics = @topics.sort{|x,y| get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) <=> get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) } : @topics = @topics.sort{|x,y| get_praise_num(y) + (y.parent ? y.parent.children.count : y.children.count) <=> get_praise_num(x) + (x.parent ? x.parent.children.count : x.children.count) } - @topics = @topics.sort{|x,y| y.sticky <=> x.sticky} + @topics = sort_by_sticky @topics else @type = 1 end #分页 - @limit = 10 + @limit = 15 @is_remote = true @atta_count = @topics.count @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index f45e1dbd7..d8e83de80 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -70,25 +70,56 @@ class NewsController < ApplicationController end elsif @course if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) + @order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type 1升序 2 降序 + if @order.to_i == @type.to_i + @b_sort = @b_sort.to_i == 1 ? 2 : 1 + else + @b_sort = 2 + end + + sort_name = "created_on" + + sort_type = @b_sort == 1 ? "asc" : "desc" + scope = @course ? @course.news.course_visible : News.course_visible news_arr = scope.map{|news| news.id} @page = params[:page] ? params[:page].to_i + 1 : 0 - news_page = @page *10 + news_page = 0 #@page *10 @news_count = scope.count @is_new = params[:is_new] @q = params[:subject] if params[:subject].nil? || params[:subject].blank? - scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all() + scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all() #all(:include => [:author, :course], #:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page) else - scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all() + scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all() #.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") end + #根据 赞+回复数排序 + if @order.to_i == 2 + @type = 2 + @b_sort == 1 ? scope_order = scope_order.sort{|x,y| get_praise_num(x) + x.comments.count <=> get_praise_num(y) + y.comments.count } : scope_order = scope_order.sort{|x,y| get_praise_num(y) + y.comments.count <=> get_praise_num(x) + x.comments.count } + scope_order = sort_by_sticky scope_order + else + @type = 1 + end + @newss = scope_order + + #分页 + @limit = 15 + @is_remote = true + @atta_count = @newss.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @newss = paginateHelper @newss,@limit + #@newss = paginateHelper scope_order,10 respond_to do |format| format.html { diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 774a8dabd..554afdb20 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2855,7 +2855,7 @@ class UsersController < ApplicationController @c_sort = 2 end - sort_name = "updated_at" + sort_name = "created_at" sort_type = @c_sort == 1 ? "asc" : "desc" if @user.courses.visible.count > 0 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d7c72b805..57faf739d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3065,3 +3065,26 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name end +#将有置顶属性的提到数组前面 +def sort_by_sticky topics + tmpTopics = [] + tmpIndex = 0 + topics.each do |topic| + if topic.sticky == 1 + tmpTopics[tmpIndex] = topic + tmpIndex = tmpIndex + 1 + end + end + + topics.each do |topic| + if topic.sticky == 0 + tmpTopics[tmpIndex] = topic + tmpIndex = tmpIndex + 1 + end + end + + topics = tmpTopics + + return topics +end + diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index ec6a6c7b5..ea494d0f9 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -66,11 +66,13 @@ \ No newline at end of file diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index dc3a20482..93df27e42 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -7,7 +7,15 @@ <%= link_to image_tag(url_to_avatar(topic.author), :width => 50,:height => 50,:alt => '贴吧图片'), user_path(topic.author) if topic.author%>
-
<%=topic.subject%>
+
+ <%=topic.subject%> +
+
+ + <%= link_to (topic.replies_count), forum_memo_path(topic.forum, topic),:target =>'_blank',:class=>'linkGrey2' %> + <%= get_praise_num(topic)%> +
+
<%= topic.content.html_safe%>
@@ -16,12 +24,7 @@
最后回复:<%= author.name%>
<%= format_date(topic.last_reply.created_at)%>
<% end%> - 更新时间:<%= format_date(topic.updated_at)%> -
-
- - <%= link_to (topic.replies_count), forum_memo_path(topic.forum, topic),:target =>'_blank',:class=>'linkGrey2' %> - <%= get_praise_num(topic)%> + 更新时间:<%= format_date(topic.updated_at)%>
diff --git a/app/views/news/_course_news_detail.html.erb b/app/views/news/_course_news_detail.html.erb index bd3215fb3..e20177536 100644 --- a/app/views/news/_course_news_detail.html.erb +++ b/app/views/news/_course_news_detail.html.erb @@ -4,41 +4,6 @@ <% end %> <% if newss%> - <% newss.each do |news| %> - - <% if news %> - <%= render :partial => 'users/course_news', :locals => {:activity => news, :user_activity_id => news.id} %> - <% end %> - <% end %> - - <% if newss.count == 10 %> - <%= link_to "点击展开更多",news_index_path(:course_id => @course.id ,:page => page),:id => "show_more_course_news",:remote => "true",:class => "loadMore mt10 f_grey"%> - <% end %> + <%= render :partial => 'users/course_newslist', :locals => {:topics => newss} %> <% end%> diff --git a/app/views/news/index.js.erb b/app/views/news/index.js.erb index d2cac877c..c5d5c84aa 100644 --- a/app/views/news/index.js.erb +++ b/app/views/news/index.js.erb @@ -1,5 +1,5 @@ <% if @project %> $("#show_more_project_news").replaceWith("<%= escape_javascript(render :partial => 'project_news_detail', :locals=>{ :all_news=>@newss,:page => @page})%>"); <% else %> - $("#show_more_course_news").replaceWith("<%= escape_javascript( render :partial => 'course_news_detail', :locals =>{:newss => @newss, :page => @page} )%>"); + $("#course-newslist").replaceWith('<%= escape_javascript( render :partial => 'users/course_newslist', :locals => {:topics => @newss}) %>'); <% end %> \ No newline at end of file diff --git a/app/views/users/_course_boardlist.html.erb b/app/views/users/_course_boardlist.html.erb index 2a00d69bf..d41d630ce 100644 --- a/app/views/users/_course_boardlist.html.erb +++ b/app/views/users/_course_boardlist.html.erb @@ -68,11 +68,13 @@ \ No newline at end of file diff --git a/app/views/users/_course_newslist.html.erb b/app/views/users/_course_newslist.html.erb new file mode 100644 index 000000000..5df06b16f --- /dev/null +++ b/app/views/users/_course_newslist.html.erb @@ -0,0 +1,64 @@ +
+
+
+

通知列表

+
+ 排序: + <%= link_to "时间", {:controller => 'news', :action => 'index', :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %> + <% if @type.to_i == 1 %> + <%= link_to "", {:controller => 'news', :action => 'index', :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %> + <% end %> + <%= link_to "人气", {:controller => 'news', :action => 'index', :type => @type, :sort => @b_sort, :order => 2 }, :class => "sortTxt", :remote => true %> + <% if @type.to_i == 2 %> + <%= link_to "", {:controller => 'news', :action => 'index', :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %> + <% end %> +
+
+
+ <% topics.each do |activity| %> +
+
+ <%= link_to activity.title.to_s, news_path(activity), :class => "list-title fl" %> + <% if activity.sticky == 1 %> + + <% end%> + <% u = User.where("id=?",activity.author_id).first%> + + 发布者: <%=(u.try(:realname) != " " ? u.lastname + u.firstname : u.try(:login)) %> + +
+
+
+

<%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>activity.description, :maxheight=>54} %>

+
+
+ 发布时间:<%= format_time(activity.created_on) %> + 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> + <% count=0 %> + <% count=activity.comments.count %> +

<%= count>0 ? "#{count}" : "0" %>回复|<%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %>

+
+
+
+ <% end %> +
+
    + <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %> +
+
+
+
+
+
+ \ No newline at end of file diff --git a/app/views/users/_intro_content_ex.html.erb b/app/views/users/_intro_content_ex.html.erb index d667845d0..ae88fc6ac 100644 --- a/app/views/users/_intro_content_ex.html.erb +++ b/app/views/users/_intro_content_ex.html.erb @@ -4,21 +4,14 @@ \ No newline at end of file diff --git a/app/views/users/_project_boardlist.html.erb b/app/views/users/_project_boardlist.html.erb index 9d25b7bd5..a36020e3d 100644 --- a/app/views/users/_project_boardlist.html.erb +++ b/app/views/users/_project_boardlist.html.erb @@ -68,11 +68,13 @@ \ No newline at end of file diff --git a/app/views/users/_user_course_list.html.erb b/app/views/users/_user_course_list.html.erb index 8d45510a1..610c16293 100644 --- a/app/views/users/_user_course_list.html.erb +++ b/app/views/users/_user_course_list.html.erb @@ -18,7 +18,7 @@