diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3de491421..90fdbe837 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -883,6 +883,7 @@ class UsersController < ApplicationController user_course_ids = @user.courses.visible.empty? ? "(-1)" : "(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll')" project_types = "('Message','Issue')" + principal_types = "JournalsForMessage" if params[:type].present? case params[:type] when "course_homework" @@ -897,13 +898,15 @@ class UsersController < ApplicationController @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page * 10) when "project_message" @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + when "user_journals" + @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10) when "current_user" @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) else - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) end else - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index a59f507df..6304055ed 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -76,7 +76,8 @@ class WordsController < ApplicationController # render 'test/index' # } format.js { - @user_activity_id = params[:user_activity_id] if + @reply_type = params[:reply_type] + @user_activity_id = params[:user_activity_id] @activity = JournalsForMessage.find(parent_id) } end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 72ef9ee88..faab129a6 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -64,7 +64,7 @@ class JournalsForMessage < ActiveRecord::Base has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy validates :notes, presence: true, if: :is_homework_jour? - after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -136,7 +136,11 @@ class JournalsForMessage < ActiveRecord::Base #用户动态公共表记录 def act_as_principal_activity - self.principal_acts << PrincipalActivity.new(:user_id => self.id,:principal_id => self.id) + if self.jour_type == 'Principal' + unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id != 0 + self.principal_acts << PrincipalActivity.new(:user_id => self.user_id, :principal_id => self.jour_id) + end + end end def reset_counters! diff --git a/app/models/principal_activity.rb b/app/models/principal_activity.rb index 877492d91..bdd7cd60e 100644 --- a/app/models/principal_activity.rb +++ b/app/models/principal_activity.rb @@ -28,7 +28,7 @@ class PrincipalActivity < ActiveRecord::Base end def destroy_user_activity - user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'") + user_activity = UserActivity.where("act_type = '#{self.principal_act_type.to_s}' and act_id = '#{self.principal_act_id}'") user_activity.destroy_all end end diff --git a/app/models/user.rb b/app/models/user.rb index e1dc45669..d66785460 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -212,7 +212,7 @@ class User < Principal before_save :update_hashed_password before_destroy :remove_references_before_destroy # added by fq - after_create :act_as_activity, :add_onclick_time + after_create :act_as_activity, :add_onclick_time, :act_as_principal_activity # end # 更新邮箱用户或用户名的同事,同步更新邀请信息 after_update :update_invite_list diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index 29752121f..2f10e6f1c 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -83,6 +83,13 @@ <%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:first_user_activity =>first_user_activity,:page => page} %> <% end %> <% end %> + <% when 'Principal' %> + <% if act %> + <% case user_activity.act_type.to_s %> + <% when 'JournalsForMessage' %> + <%= render :partial => 'user_journalsformessage', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> + <% end %> + <% end %> <% end %> <% end %> <% end %> diff --git a/app/views/users/_user_journalsformessage.html.erb b/app/views/users/_user_journalsformessage.html.erb index 1e925d7c4..691911008 100644 --- a/app/views/users/_user_journalsformessage.html.erb +++ b/app/views/users/_user_journalsformessage.html.erb @@ -5,23 +5,17 @@
- <% if activity.try(:user).try(:realname) == ' ' %> - <%= link_to activity.try(:user), user_path(activity.user_id), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:user).try(:realname), user_path(activity.user_id), :class => "newsBlue mr15" %> - <% end %> TO - <% if @user.try(:realname) == ' '%> - <% name = @user.login.to_s %> - <% else %> - <% name = @user.try(:realname).to_s %> + <%= link_to activity.user.show_name, user_path(activity.user_id), :class => "newsBlue mr15" %> + TO + <% if activity.jour %> + <%= link_to activity.jour.show_name+"("+(activity.jour.login ? activity.jour.login : activity.jour.show_name ).to_s+")的留言", feedback_path(activity.jour, :host=> Setting.host_user), :class => "newsBlue ml15" %> <% end %> - <%= link_to name+"("+@user.login.to_s+")的留言", feedback_path(@user, :host=> Setting.host_user), :class => "newsBlue ml15" %>
<% if activity.parent %> - <%= link_to activity.parent.notes.html_safe, feedback_path(@user, :host=> Setting.host_user), :class => "postGrey" %> + <%= link_to activity.parent.notes.html_safe, feedback_path(activity.jour, :host=> Setting.host_user), :class => "postGrey" %> <% else %> - <%= link_to activity.notes.html_safe, feedback_path(@user, :host=> Setting.host_user), :class => "postGrey" %> + <%= link_to activity.notes.html_safe, feedback_path(activity.jour, :host=> Setting.host_user), :class => "postGrey" %> <% end %>
@@ -67,7 +61,8 @@ <%= format_time(comment.created_on) %>
- <%= comment.notes.html_safe %>
+ <%= comment.notes.html_safe %> +
<% end %>
@@ -86,6 +81,7 @@ <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => activity.id %> <%= hidden_field_tag 'show_name',params[:show_name],:value =>true %> <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> + <%= hidden_field_tag 'reply_type',params[:reply_type],:value =>'user' %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index de166b4e7..fc87bd3a0 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -29,6 +29,7 @@
  • diff --git a/app/views/words/create_reply.js.erb b/app/views/words/create_reply.js.erb index d91ce08ce..db645f011 100644 --- a/app/views/words/create_reply.js.erb +++ b/app/views/words/create_reply.js.erb @@ -1,6 +1,10 @@ <% if @save_succ %> <% if @user_activity_id %> - $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_journalsformessage', :locals => {:activity => @activity,:user_activity_id =>@user_activity_id}) %>"); + <% if @reply_type == 'user' %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_journalsformessage', :locals => {:activity => @activity,:user_activity_id =>@user_activity_id}) %>"); + <% else %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_journalsformessage', :locals => {:activity => @activity,:user_activity_id =>@user_activity_id}) %>"); + <% end %> init_activity_KindEditor_data('<%= @user_activity_id%>', "", "87%"); <% else %> <% if !@jfm.nil? && @jfm.jour_type == 'Principal' %> diff --git a/db/migrate/20151013091057_update_principal_activity.rb b/db/migrate/20151013091057_update_principal_activity.rb new file mode 100644 index 000000000..bfcf9ccd9 --- /dev/null +++ b/db/migrate/20151013091057_update_principal_activity.rb @@ -0,0 +1,15 @@ +class UpdatePrincipalActivity < ActiveRecord::Migration + def up + User.all.each do |user| + transaction do + user.principal_acts << PrincipalActivity.new(:user_id => user.id,:principal_id => user.id) + user.journals_for_messages.each do |jour| + jour.principal_acts << PrincipalActivity.new(:user_id => jour.user_id,:principal_id => user.id) + end + end + end + end + + def down + end +end diff --git a/db/migrate/20151013092356_update_principal_activity_time.rb b/db/migrate/20151013092356_update_principal_activity_time.rb new file mode 100644 index 000000000..8c1e5bd79 --- /dev/null +++ b/db/migrate/20151013092356_update_principal_activity_time.rb @@ -0,0 +1,43 @@ +class UpdatePrincipalActivityTime < ActiveRecord::Migration + def up + count = PrincipalActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + PrincipalActivity.page(i).per(30).each do |activity| + if activity.principal_act + if activity.principal_act.respond_to?("created_on") + activity.created_at = activity.principal_act.created_on + activity.updated_at = activity.principal_act.created_on + elsif activity.principal_act.respond_to?("created_at") + activity.created_at = activity.principal_act.created_at + activity.updated_at = activity.principal_act.created_at + end + activity.save + + user_activity = UserActivity.where("act_type = '#{activity.principal_act_type.to_s}' and act_id = '#{activity.principal_act_id}'").first + user_activity.created_at = activity.created_at + user_activity.updated_at = activity.created_at + if user_activity.act_type == 'JournalsForMessage' + if user_activity.act + unless user_activity.act.m_parent_id.nil? + parent_act = UserActivity.where("act_id = #{user_activity.act.m_parent_id} and act_type='JournalsForMessage' and container_type='Principal'").first + if parent_act + parent_act.created_at = user_activity.act.parent.children.maximum("created_on") + parent_act.save + user_activity.destroy + end + end + else + user_activity.destroy + end + end + user_activity.save + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20151014013243_update_user_activity_updated_at.rb b/db/migrate/20151014013243_update_user_activity_updated_at.rb new file mode 100644 index 000000000..6678e07e1 --- /dev/null +++ b/db/migrate/20151014013243_update_user_activity_updated_at.rb @@ -0,0 +1,16 @@ +class UpdateUserActivityUpdatedAt < ActiveRecord::Migration + def up + count = UserActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + UserActivity.page(i).per(30).each do |activity| + activity.updated_at = activity.created_at + activity.save + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index b03813032..3c1271dfb 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 => 20151013081912) do +ActiveRecord::Schema.define(:version => 20151014013243) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index bb556240a..9d45ff753 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -624,6 +624,7 @@ a.homepagePostTypeQuiz {background:url(../images/homepage_icon.png) -90px -124px a.homepagePostTypeQuestion {background:url(../images/homepage_icon.png) -10px -273px no-repeat; padding-left:23px;} a.homepagePostTypeMine {background:url(../images/homepage_icon.png) -187px -277px no-repeat; padding-left:23px;} a.homepagePostTypeAll {background:url(../images/homepage_icon.png) -185px -308px no-repeat; padding-left:23px;} +a.homepagePostTypeMessage {background:url(images/homepage_icon.png) -3px -518px no-repeat; padding-left:23px;} .homepagePostTypeMore {width:180px; border-top:1px dashed #dddddd; margin-top:5px;} .w100 {width:100px;} a.homepageTypeUnread {background:url(../images/homepage_icon.png) -6px -579px no-repeat; padding-left:23px;}