From 87b4c8324718d3874a1a6708f44405d1f8e398fe Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Tue, 20 Oct 2015 16:19:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8D=E8=83=BD=E5=8F=82?= =?UTF-8?q?=E4=B8=8E=E5=8C=BF=E8=AF=84=E6=B6=88=E6=81=AF=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=88=A0=E9=99=A4=EF=BC=9B=20=E7=9C=8B=E5=AE=8C?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=90=8E=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E5=AD=97=E6=AE=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 6 +++++- app/controllers/users_controller.rb | 2 +- app/models/student_work.rb | 6 ++++-- app/views/users/_user_message_course.html.erb | 20 +++++++++---------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9393339a8..e5e1bf391 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -63,7 +63,7 @@ class StudentWorkController < ApplicationController journal_for_teacher.update_attributes(:viewed => true) end #不能参与作业匿评消息状态更新 - no_evaluation = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @homework.course, "NoEvaluation", 0) + no_evaluation = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =? and status =?", User.current.id, @homework.course, "StudentWork", 0, 0) no_evaluation.update_all(:viewed => true) # 作品留言 # 消息end @@ -144,6 +144,10 @@ class StudentWorkController < ApplicationController end def new + #更新消息 + noEvaluation = @homework.course_messages.where("user_id =? and viewed =?", User.current.id, 0) + noEvaluation.update_all(:viewed => true) + if @homework.homework_type==2 redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) return diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ef3210719..7adba7cbf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -128,7 +128,7 @@ class UsersController < ApplicationController #课程相关消息 when 'homework' - @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','NoEvaluation') and user_id =?", @user).order("created_at desc") + @message_alls = CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork') and user_id =?", @user).order("created_at desc") when 'course_message' @message_alls = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") when 'course_news' diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 700613792..010ede635 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -8,6 +8,8 @@ class StudentWork < ActiveRecord::Base has_many :student_works_scores, :dependent => :destroy belongs_to :project has_many :student_work_tests, order: 'id desc' + # course's message + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy before_destroy :delete_praise before_save :set_program_score, :set_src @@ -138,10 +140,10 @@ class StudentWork < ActiveRecord::Base end end + # status == 0 : delay def act_as_message if self.created_at > self.homework_common.end_time + 1 - CourseMessage.create(:user_id => self.user_id, :course_id => self.homework_common.course_id, - :course_message_id => self.id, :course_message_type => 'NoEvaluation',:viewed => false) + self.course_messages << CourseMessage.new(:user_id => self.user_id, :course_id => self.homework_common.course_id, :viewed => false, :status => false) end end end diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index 6c22976fd..86b44f66d 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -37,7 +37,7 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> - <% if ma.course_message_type == "HomeworkCommon" && ma.status.nil? && !ma.course_message.nil? %> + <% if ma.course_message_type == "HomeworkCommon" %>