From be531d6abd73b89a62163cad94797790d074ce90 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 13 Jan 2017 11:13:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 26 +++++++++------------- app/views/users/_new_user_message.html.erb | 3 ++- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0811eab7a..ee9be0d69 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1994,25 +1994,19 @@ end # 系统消息总显示在最前面,显示周期30天 @system_messages = SystemMessage.where("created_at > ?", Time.now - 86400 * 30) # 自己的主页显示消息 - @message_alls = [] + messages_all = MessageAll.where(:user_id => @user.id) + @message_count = messages_all.count + # REDO:已删除的内容应该在页面中显示不点击 + @message_all_pages = Paginator.new @message_count, per_page_option, params['page'] + @message_alls = messages_all.includes(:message). + limit(@message_all_pages.per_page). + offset(@message_all_pages.offset). + reorder("#{MessageAll.table_name}.created_at desc") - messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" , @user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc") - - messages.each do |message_all| - mess = message_all.message - unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) - if (message_all.message_type =="SystemMessage" && !many_days_ago(mess.created_at, 30)) - next - else - @message_alls << mess - end - end - end - @message_count = @message_alls.count - @message_alls = paginateHelper @message_alls, 20 @unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).count # 用户待完成的作业 - my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")" + my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course). + where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")" homeworks = HomeworkCommon.where("course_id in #{my_course_ids} and publish_time <= '#{Date.today}'") homework_ids = homeworks.blank? ? "(-1)" : "(" + homeworks.map{|homework| homework.id}.join(",") + ")" student_works = StudentWork.where("user_id = #{@user.id} and homework_common_id in #{homework_ids} and work_status != 0") diff --git a/app/views/users/_new_user_message.html.erb b/app/views/users/_new_user_message.html.erb index 7ae194d83..e7e41fcda 100644 --- a/app/views/users/_new_user_message.html.erb +++ b/app/views/users/_new_user_message.html.erb @@ -2,6 +2,7 @@ <%= render :partial => 'users/user_message_system' %> <% message_alls.each do |ma| %> + <% ma = ma.try(:message) %> <% if ma.class == AtMessage && ma.at_valid? && ma.at_message %> <%= render :partial => 'users/user_at_message', :locals => {:ma => ma} %> <% end %> @@ -42,7 +43,7 @@ <% end %>