diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb
index c8518e8a3..a77346d89 100644
--- a/app/controllers/boards_controller.rb
+++ b/app/controllers/boards_controller.rb
@@ -70,31 +70,16 @@ class BoardsController < ApplicationController
def show
# 讨论区消息状态更新(已读和未读)
if @project
- query_forge_messages = @board.messages
- query_forge_messages.each do |query_forge_message|
- query = query_forge_message.forge_messages
- query.each do |forge_message|
- if User.current.id == forge_message.user_id
- forge_message.update_attributes(:viewed => true)
- end
- end
- end
+ ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true)
# 更新@消息为已读
- @project.boards.each do |board|
- board.messages.each do |m|
- User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
- end
- end
+ # 注释掉这句是因为和上面的方法代码重复,一个类型的消息,已经更新就不需要再更新
+ # @project.boards.each do |board|
+ # board.messages.each do |m|
+ # User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
+ # end
+ # end
elsif @course
- query_course_messages = @board.messages
- query_course_messages.each do |query_course_message|
- query = query_course_message.course_messages
- query.each do |course_message|
- if User.current.id == course_message.user_id
- course_message.update_attributes(:viewed => true)
- end
- end
- end
+ CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true)
end
sort_init 'updated_on', 'desc'
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index b2a828768..113e37af3 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -308,7 +308,7 @@ class ProjectsController < ApplicationController
if User.current.member_of?(@project) || User.current.admin?
case params[:type]
when nil
- @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo', 'Attachment')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
+ @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'issue'
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
when 'news'
diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb
index a698823e5..71b23fdcf 100644
--- a/app/controllers/student_work_controller.rb
+++ b/app/controllers/student_work_controller.rb
@@ -230,12 +230,12 @@ class StudentWorkController < ApplicationController
render_403
return
end
-
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name).count
end
@score = @b_sort == "desc" ? "asc" : "desc"
-
+ # 消息传过来的ID
+ @message_student_work_id = params[:student_work_id]
respond_to do |format|
format.js
format.html
diff --git a/app/models/project.rb b/app/models/project.rb
index 32677143d..184b3c7af 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -108,7 +108,8 @@ class Project < ActiveRecord::Base
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
# 动态级联删除
- has_many :forge_activities, :class_name => 'ForgeActivity', :dependent => :destroy
+ has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
+ #has_many :forge_activities, :class_name => 'ForgeActivity', :as =>:forge_act, :dependent => :destroy
# 关联虚拟表
has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy
@@ -1212,9 +1213,7 @@ class Project < ActiveRecord::Base
# Author lizanle
# Description 新建项目要在ForgeActivities中加一条数据。
def acts_as_forge_activities
- fa = ForgeActivity.new(:user_id => User.current.id,:project_id => self.id,
- :forge_act_id => self.id,:forge_act_type => "ProjectCreateInfo")
- fa.save!
+ self.forge_acts << ForgeActivity.new(:user_id => User.current.id, :project_id => self.id)
end
diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb
index 5ad25d5bd..3af8f9212 100644
--- a/app/views/layouts/base_projects.html.erb
+++ b/app/views/layouts/base_projects.html.erb
@@ -44,8 +44,6 @@
-
- <%#= render :partial => 'layouts/new_header'%>
@@ -104,20 +102,6 @@
- <%# if User.current.member_of?(@project) %>
-
-
-
-
-
-
-
-
-
- <%# end %>
-
- <%#--project_new_type: 1为开发组;2为科研组;3为朋友圈子--%>
-
<% if @project.project_new_type == 1 || @project.project_new_type.nil? %>
<%= render :partial => 'projects/development_group', :locals => {:project => @project} %>
diff --git a/app/views/projects/_project_activities.html.erb b/app/views/projects/_project_activities.html.erb
index f9faa26d6..536921c13 100644
--- a/app/views/projects/_project_activities.html.erb
+++ b/app/views/projects/_project_activities.html.erb
@@ -73,12 +73,11 @@
<% case activity.forge_act_type %>
- <% when "ProjectCreateInfo" %>
+ <% when "Project" %>
<%= render :partial => 'projects/project_create', :locals => {:activity => activity, :user_activity_id => activity.id} %>
<% when "Issue" %>
<%= render :partial => 'users/project_issue', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %>
-
<% when "Message" %>
<%= render :partial => 'users/project_message', :locals => {:activity => activity.forge_act,:user_activity_id =>activity.id,:is_course=>1,:is_board=>0} %>
diff --git a/app/views/student_work/_student_work_list.html.erb b/app/views/student_work/_student_work_list.html.erb
index f9f55456b..0badbb192 100644
--- a/app/views/student_work/_student_work_list.html.erb
+++ b/app/views/student_work/_student_work_list.html.erb
@@ -47,42 +47,44 @@
\ No newline at end of file
diff --git a/app/views/users/_project_attachment.html.erb b/app/views/users/_project_attachment.html.erb
index deb0cb4c6..b3d904104 100644
--- a/app/views/users/_project_attachment.html.erb
+++ b/app/views/users/_project_attachment.html.erb
@@ -1,5 +1,3 @@
-
-
diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb
index e042cd738..5c05474a0 100644
--- a/app/views/users/_user_message_course.html.erb
+++ b/app/views/users/_user_message_course.html.erb
@@ -167,7 +167,7 @@
<% unless ma.content.nil? %>
- <%= link_to ma.content.html_safe, student_work_index_path(:homework => ma.course_message.student_work.homework_common_id),
+ <%= link_to ma.content.html_safe, student_work_index_path(:homework => ma.course_message.student_work.homework_common_id, :student_work_id => ma.course_message.student_work),
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}" %>
@@ -208,7 +208,7 @@
">回复了作品评论:
- <%= link_to ma.course_message.notes, student_work_index_path(:homework => ma.course_message.jour.student_work.homework_common_id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}" %>
+ <%= link_to ma.course_message.notes, student_work_index_path(:homework => ma.course_message.jour.student_work.homework_common_id, :student_work_id => ma.course_message.jour.student_work), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}" %>
diff --git a/db/migrate/20160324052634_change_project_create_type.rb b/db/migrate/20160324052634_change_project_create_type.rb
new file mode 100644
index 000000000..8beca180d
--- /dev/null
+++ b/db/migrate/20160324052634_change_project_create_type.rb
@@ -0,0 +1,8 @@
+class ChangeProjectCreateType < ActiveRecord::Migration
+ def up
+ execute("update forge_activities set forge_act_type = 'Project' where forge_act_type = 'ProjectCreateInfo'")
+ end
+
+ def down
+ end
+end
diff --git a/db/migrate/20160324074942_add_index_to_forge_activities.rb b/db/migrate/20160324074942_add_index_to_forge_activities.rb
new file mode 100644
index 000000000..5623e8056
--- /dev/null
+++ b/db/migrate/20160324074942_add_index_to_forge_activities.rb
@@ -0,0 +1,5 @@
+class AddIndexToForgeActivities < ActiveRecord::Migration
+ def change
+ add_index :forge_activities, [:project_id, :forge_act_id, :created_at]
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5eb9edd36..361752fa7 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20160321080825) do
+ActiveRecord::Schema.define(:version => 20160324052634) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -465,7 +465,6 @@ ActiveRecord::Schema.define(:version => 20160321080825) do
t.integer "status"
end
- add_index "course_messages", ["course_message_id"], :name => "index_course_messages_on_course_message_id"
add_index "course_messages", ["course_message_type"], :name => "index_course_messages_on_course_message_type"
add_index "course_messages", ["user_id", "course_id", "created_at"], :name => "index_course_messages_on_user_id_and_course_id_and_created_at"
@@ -1088,7 +1087,8 @@ ActiveRecord::Schema.define(:version => 20160321080825) do
t.datetime "updated_at", :null => false
end
- add_index "message_alls", ["message_id", "message_type", "created_at"], :name => "index_message_alls_on_message_id_and_message_type_and_created_at"
+ add_index "message_alls", ["message_type"], :name => "index_message_alls_on_message_type"
+ add_index "message_alls", ["user_id", "message_id", "created_at"], :name => "index_message_alls_on_user_id_and_message_id_and_created_at"
create_table "messages", :force => true do |t|
t.integer "board_id", :null => false