From cd0752f5daa171c6c46fdab1fc622c8e8fd55204 Mon Sep 17 00:00:00 2001 From: yutao <283765470@qq.com> Date: Thu, 4 Jun 2015 15:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=AE=A8=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=B8=8E=E6=88=91=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity_notifys_controller.rb | 54 +++++++++++++++ app/controllers/boards_controller.rb | 43 +++++++++--- app/controllers/messages_controller.rb | 54 +++++++++++++++ app/models/activity_notify.rb | 3 + app/models/message.rb | 16 +++++ .../activity_notifys/chang_read_flag.html.erb | 1 + app/views/boards/_course_show.html.erb | 19 +++++- app/views/boards/show.html.erb | 2 + app/views/courses/show.html.erb | 64 ++++++++++++++++-- config/routes.rb | 6 ++ ...20150604153000_create_activity_notifies.rb | 17 +++++ public/images/new.png | Bin 0 -> 4196 bytes public/stylesheets/courses.css | 9 ++- 13 files changed, 270 insertions(+), 18 deletions(-) create mode 100644 app/controllers/activity_notifys_controller.rb create mode 100644 app/models/activity_notify.rb create mode 100644 app/views/activity_notifys/chang_read_flag.html.erb create mode 100644 db/migrate/20150604153000_create_activity_notifies.rb create mode 100644 public/images/new.png diff --git a/app/controllers/activity_notifys_controller.rb b/app/controllers/activity_notifys_controller.rb new file mode 100644 index 000000000..c696836b2 --- /dev/null +++ b/app/controllers/activity_notifys_controller.rb @@ -0,0 +1,54 @@ +class ActivityNotifysController < ApplicationController +# layout 'base_projects'#by young +# default_search_scope :messages + before_filter :find_project_by_project_id#, :find_board_if_available +# before_filter :authorize, :except => [:new, :show, :create, :index] +# accept_rss_auth :index, :show + + helper :activities + def index + query = nil + if @course + query = ActivityNotify.where('activity_container_id=? and activity_container_type=? and notify_to=?',@course.id,'Course',User.current.id); + else + @events_by_day = [] + end + + if( query != nil ) + logger.info('xxoo') + limit = 10; + @obj_count = query.count(); + @obj_pages = Paginator.new @obj_count,limit,params['page'] + list = query.order('id desc').limit(limit).offset(@obj_pages.offset).all(); + events=[]; + for item in list + event = item.activity; + event.set_notify_id(item.id) + event.set_notify_is_read(item.is_read) + events << event + end + @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} + @controller_name = 'ActivityNotifys' + logger.info('aavv') + end + respond_to do |format| + format.html {render :template => 'courses/show', :layout => 'base_courses'} + end + end + + def chang_read_flag + if @course + if(params[:an_id] != nil ) + query = ActivityNotify.where('id=? and notify_to=?',params[:an_id],User.current.id) + else + query = ActivityNotify.where('activity_container_id=? and activity_container_type=? and notify_to=? and is_read=0',@course.id,'Course',User.current.id) + end + @result = query.update_all('is_read=1'); + else + @result = false; + end + respond_to do |format| + format.html{render :layout => nil} + end + end +end \ No newline at end of file diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index db5bded55..6ff4d2f97 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -88,14 +88,40 @@ class BoardsController < ApplicationController preload(:author, {:last_reply => :author}). all elsif @course - board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc"). - includes(:last_reply). - # limit(@topic_pages.per_page). - # offset(@topic_pages.offset). - - preload(:author, {:last_reply => :author}). - all : [] - @topics = paginateHelper board_topics,10 + # + # board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc"). + # includes(:last_reply). + # # limit(@topic_pages.per_page). + # # offset(@topic_pages.offset). + # + # preload(:author, {:last_reply => :author}). + # all : [] + # @topics = paginateHelper board_topics,10 + if( @board ) + limit = 10; + pageno = params[:page]; + if(pageno == nil || pageno=='') + dw_topic = nil; + if( params[:parent_id]!=nil && params[:parent_id]!='' ) + dw_topic = @board.topics.where(id:params[:parent_id]).first(); + end + if( dw_topic != nil ) + dw_count = @board.topics.where('(sticky>?) or (sticky=? and created_on>?)',dw_topic.sticky,dw_topic.sticky,dw_topic.created_on).count(); + dw_count = dw_count+1; + pageno = dw_count%10==0 ? (dw_count/limit) : (dw_count/limit+1) + end + end + if(pageno == nil || pageno=='') + pageno=1; + end + @topic_count = @board.topics.count(); + @topic_pages = Paginator.new @topic_count, limit, pageno + @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc"). + limit(limit).offset(@topic_pages.offset).includes(:last_reply). + preload(:author, {:last_reply => :author}).all(); + else + @topics = []; + end end @message = Message.new(:board => @board) @@ -103,6 +129,7 @@ class BoardsController < ApplicationController if @project render :action => 'show', :layout => 'base_projects' elsif @course + @params=params render :action => 'show', :layout => 'base_courses' end } diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index e33eb8d75..9e36d15f4 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -31,6 +31,8 @@ class MessagesController < ApplicationController include AttachmentsHelper helper :project_score + include CoursesHelper + REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) # Show a topic and its replies @@ -91,6 +93,29 @@ class MessagesController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE end + # 与我相关动态的记录add start + if(@board.course_id>0) #项目的先不管 + teachers = searchTeacherAndAssistant(@board.course); + for teacher in teachers + if(teacher.user_id != User.current.id) + notify = ActivityNotify.new() + if(@board.course_id>0) + notify.activity_container_id = @board.course_id + notify.activity_container_type = 'Course' + else + notify.activity_container_id = @board.project_id + notify.activity_container_type = 'Project' + end + notify.activity_id = @message.id + notify.activity_type = 'Message' + notify.notify_to = teacher.user_id + notify.is_read = 0 + notify.save() + end + end + end + # 与我相关动态的记录add end + call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) render_attachment_warning_if_needed(@message) if params[:is_board] @@ -151,6 +176,35 @@ class MessagesController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@reply.id,OwnerTypeHelper::MESSAGE end + + # 与我相关动态的记录add start + if(@board.course_id>0) #项目的先不管 + notifyto_arr = {} + notifyto_arr[@topic.author_id] = @topic.author_id + if( params[:parent_topic] != nil && params[:parent_topic] != '') + parent_topic = Message.find(params[:parent_topic]) + notifyto_arr[parent_topic.author_id] = parent_topic.author_id + end + notifyto_arr.each do |k,user_id| + if(user_id != User.current.id) + notify = ActivityNotify.new() + if(@board.course_id>0) + notify.activity_container_id = @board.course_id + notify.activity_container_type = 'Course' + else + notify.activity_container_id = @board.project_id + notify.activity_container_type = 'Project' + end + notify.activity_id = @reply.id + notify.activity_type = 'Message' + notify.notify_to = user_id + notify.is_read = 0 + notify.save() + end + end + end + # 与我相关动态的记录add end + call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) attachments = Attachment.attach_files(@reply, params[:attachments]) render_attachment_warning_if_needed(@reply) diff --git a/app/models/activity_notify.rb b/app/models/activity_notify.rb new file mode 100644 index 000000000..0fbe1f6f1 --- /dev/null +++ b/app/models/activity_notify.rb @@ -0,0 +1,3 @@ +class ActivityNotify < ActiveRecord::Base + belongs_to :activity, polymorphic: true +end \ No newline at end of file diff --git a/app/models/message.rb b/app/models/message.rb index bbf62b5dc..15d358789 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -34,6 +34,8 @@ class Message < ActiveRecord::Base has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # end + has_many :ActivityNotifies,:as => :activity, :dependent => :destroy + acts_as_searchable :columns => ['subject', 'content'], :include => {:board => :project}, :project_key => "#{Board.table_name}.project_id", @@ -148,6 +150,19 @@ class Message < ActiveRecord::Base usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) end + def set_notify_id(notify_id) + @notify_id= notify_id + end + def get_notify_id() + return @notify_id + end + def set_notify_is_read(notify_is_read) + @notify_is_read = notify_is_read + end + def get_notify_is_read() + return @notify_is_read + end + private def add_author_as_watcher @@ -218,4 +233,5 @@ class Message < ActiveRecord::Base def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE end + end diff --git a/app/views/activity_notifys/chang_read_flag.html.erb b/app/views/activity_notifys/chang_read_flag.html.erb new file mode 100644 index 000000000..ca89a7e3f --- /dev/null +++ b/app/views/activity_notifys/chang_read_flag.html.erb @@ -0,0 +1 @@ +<%= @result == false ? 'false' : 'true' %> \ No newline at end of file diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 0d9d6a780..48e5a870d 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -109,6 +109,7 @@ :html => {:nhname=>"form",:multipart => true, :id => 'message_form' + topic.id.to_s, :name=>'message-form'} do |f| %> <%= render :partial => 'form_project', :locals => {:f => f, :replying => true} %> +
<%= l(:label_no_data) %>
<% end %><%= e.event_description.html_safe %>
@@ -28,7 +50,7 @@
<% end%>
<% end%>
<% end%>
-<% if @obj_pages.next_page.nil? %>
+<% if @obj_pages.next_page.nil? && @controller_name!='ActivityNotifys' %>