课程讨论区动态与我相关
This commit is contained in:
parent
a45240b602
commit
cd0752f5da
|
@ -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
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class ActivityNotify < ActiveRecord::Base
|
||||
belongs_to :activity, polymorphic: true
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%= @result == false ? 'false' : 'true' %>
|
|
@ -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} %>
|
||||
<input name="parent_topic" type="hidden" value=""/>
|
||||
<div class="fl" style="padding-top:5px;" nhname="toolbar_container"></div>
|
||||
<div style="padding-top:5px;" class="fr">
|
||||
<a href="javascript:void(0)" nhname="cancelbtn" class="grey_btn fr ml10" style=""><%= l(:button_cancel)%></a>
|
||||
|
@ -127,7 +128,7 @@
|
|||
<ul>
|
||||
<% replies_all.each do |message| %>
|
||||
<% replies_all_i=replies_all_i+1 %>
|
||||
<li nhname="reply_rec" style="display:<%= replies_all_i>2?'none':'' %>">
|
||||
<li nhname="reply_rec" style="display:<%= replies_all_i>2?'none':'' %>" id="topic<%=message.id%>">
|
||||
<%= link_to image_tag(url_to_avatar(message.author), :width => '34',:height => '34'), user_path(message.author), :class =>'Msg_pic' %>
|
||||
<div class="Msg_txt">
|
||||
<%= link_to_user_header message.author,false,:class => 'fl c_orange ' %>
|
||||
|
@ -151,6 +152,7 @@
|
|||
:nhname =>'showbtn_child_reply',
|
||||
:class => ' c_dblue fr',
|
||||
:style => 'margin-right: 10px;',
|
||||
'data-topic-id' =>message.id,
|
||||
:title => l(:button_reply)) if !topic.locked? && authorize_for('messages', 'reply') %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
|
@ -172,7 +174,8 @@
|
|||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
<ul class="wlist">
|
||||
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
|
||||
<%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
|
||||
<%= pagination_links_full @topic_pages, @topic_count, :per_page_links => false, :remote => false, :flag => true %>
|
||||
</ul>
|
||||
<%# other_formats_links do |f| %>
|
||||
<%#= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
|
||||
|
@ -255,6 +258,18 @@
|
|||
}
|
||||
nh_init_board(params);
|
||||
});
|
||||
|
||||
<% if( @params[:topic_id]!=nil && @params[:topic_id]!='' && @params[:page]==nil ) %>
|
||||
var nh_dw_html = $("#topic<%=@params[:topic_id]%>");
|
||||
if(nh_dw_html!=undefined && nh_dw_html.length!=0){
|
||||
if(nh_dw_html.is(':hidden')){
|
||||
$("a[nhname='reply_ex_btn']",nh_dw_html.parent('ul').parent('div').parent('div')).click();
|
||||
}
|
||||
$("#nhjump").attr('href','#'+nh_dw_html.attr('id'));
|
||||
$("#nhjump")[0].click();
|
||||
|
||||
}
|
||||
<% end %>
|
||||
<% if(!@flag.nil? && @flag=='true') %>
|
||||
if($("#new_topic_btn")!=undefined)$("#new_topic_btn").click();
|
||||
<% end %>
|
||||
|
|
|
@ -201,6 +201,8 @@ function nh_init_board(params){
|
|||
params.cancelbtn.click();
|
||||
}
|
||||
}
|
||||
var parent_topic_id = $(this).data('topic-id');
|
||||
if(parent_topic_id!=undefined)$("input[name='parent_topic']",params.form).val(parent_topic_id);
|
||||
var ref_str = params.get_ref_str_call($(this));
|
||||
params.quote_show.html(ref_str);
|
||||
params.quote_input.html(ref_str);
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
<div class="project_r_h">
|
||||
<h2 class="project_h2"><%= l(:label_activity)%></h2>
|
||||
<% if @controller_name=='ActivityNotifys' %>
|
||||
<a class="fl about_me" href="<%=course_path(@course)%>"><%= l(:label_activity)%></a>
|
||||
<h2 class="fl project_h2">与我相关</h2>
|
||||
<div class="fr mt10 mr5 c_grey02">
|
||||
<label class="mr5" style="cursor:pointer;" data-href="<%= course_activity_notifys_path(@course) %>/chang_read_flag" nhname='nh_act_link_all'>全部标为已读</label>
|
||||
</div>
|
||||
<% else %>
|
||||
<h2 class="fl project_h2"><%= l(:label_activity)%></h2>
|
||||
<% if User.current.logged? %>
|
||||
<a class="fl about_me" href="<%=course_activity_notifys_path(@course)%>">与我相关</a>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @events_by_day != nil && @events_by_day.size >0 %>
|
||||
<% @events_by_day.keys.sort.reverse.each do |day| %>
|
||||
<% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%>
|
||||
<div class="problem_main">
|
||||
<div class="problem_main" nhname="container">
|
||||
<a class="problem_pic fl">
|
||||
<%= image_tag(url_to_avatar(e.event_author), :width => "42", :height => "42") %>
|
||||
</a>
|
||||
|
@ -14,8 +25,19 @@
|
|||
<%= link_to_user_header("(#{e.event_author})", @canShowRealName,:class => 'problem_name c_orange fl') if @canShowRealName && e.respond_to?(:event_author) %>
|
||||
<span class="fl"> </span>
|
||||
<span class="fl"> <%= l(:label_new_activity) %>:</span>
|
||||
<%= link_to "#{eventToLanguageCourse(e.event_type, @course)} "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) :
|
||||
(e.event_type.eql?("bid") ? homework_course_path(@course) : (e.event_type.eql?("message") || e.event_type.eql?("reply") ? course_boards_path(@course,:topic_id => e.id) : e.event_url)),:class => "problem_tit c_dblue fl fb"%>
|
||||
<%
|
||||
link = (e.event_type.eql?("attachment")&&e.container.kind_of?(Course)) ? course_files_path(e.container) :
|
||||
(e.event_type.eql?("bid") ? homework_course_path(@course) :
|
||||
(e.event_type.eql?("message") || e.event_type.eql?("reply") ?
|
||||
course_boards_path(@course,:topic_id => e.id,:parent_id=>(e.parent_id ? e.parent_id : e.id)) : e.event_url))
|
||||
%>
|
||||
<%= link_to "#{eventToLanguageCourse(e.event_type, @course)} "<< format_activity_title(e.event_title), link,
|
||||
:class => "problem_tit c_dblue fl fb",'data-type'=>e.event_type,
|
||||
'data-notify-id'=>(e.respond_to?('get_notify_id') ? e.get_notify_id : ''),:nhname=>"nh_act_link",
|
||||
'data-href'=>(course_activity_notifys_path(@course)+"/chang_read_flag?an_id="+(e.respond_to?('get_notify_id') ? e.get_notify_id : '').to_s)%>
|
||||
<%if @controller_name=='ActivityNotifys' && !e.get_notify_is_read%>
|
||||
<span nhname="nh_act_flag" class="ml10 fl"><img src="/images/new.png" width="35" height="15"/></span>
|
||||
<%end%>
|
||||
<br />
|
||||
<p class="mt5 break_word"><%= e.event_description.html_safe %>
|
||||
<br />
|
||||
|
@ -28,7 +50,7 @@
|
|||
<% end%>
|
||||
<% end%>
|
||||
<% end%>
|
||||
<% if @obj_pages.next_page.nil? %>
|
||||
<% if @obj_pages.next_page.nil? && @controller_name!='ActivityNotifys' %>
|
||||
<div class="problem_main">
|
||||
<a class="problem_pic fl">
|
||||
<%= image_tag(url_to_avatar(@user), :width => "42", :height => "42") %>
|
||||
|
@ -51,3 +73,35 @@
|
|||
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("div[nhname='container']").each(function(){
|
||||
var container = $(this);
|
||||
var btn = $("a[nhname='nh_act_link']",container);
|
||||
if(btn.data('notify-id')>0){
|
||||
btn.attr('target','_blank');
|
||||
btn.click(function(){
|
||||
var flag = $("span[nhname='nh_act_flag']",container);
|
||||
if(flag!=undefined){
|
||||
var url = $(this).data('href');
|
||||
$.ajax({url:url,dataType:'text',success:function(data){
|
||||
if(data == 'true'){
|
||||
flag.remove();
|
||||
}
|
||||
}});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
$("label[nhname='nh_act_link_all']").click(function(){
|
||||
var url = $(this).data('href');
|
||||
$.ajax({url:url,dataType:'text',success:function(data){
|
||||
if(data == 'true'){
|
||||
$("span[nhname='nh_act_flag']").remove();
|
||||
}
|
||||
}});
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -710,6 +710,12 @@ RedmineApp::Application.routes.draw do
|
|||
resources :news, :except => [:show, :edit, :update, :destroy]
|
||||
resources :boards
|
||||
match '/homework', :to => 'courses#homework', :as => 'homework', :via => :get
|
||||
resources :activity_notifys do
|
||||
collection do
|
||||
match 'chang_read_flag', :via => :get
|
||||
end
|
||||
end
|
||||
|
||||
end # end of resources :courses
|
||||
match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback'
|
||||
match '/courses/search', :via => [:get, :post]
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
class CreateActivityNotifies < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :activity_notifies do |t|
|
||||
t.integer :activity_container_id
|
||||
t.string :activity_container_type
|
||||
t.integer :activity_id
|
||||
t.string :activity_type
|
||||
t.integer :notify_to
|
||||
t.datetime :created_on
|
||||
t.integer :is_read
|
||||
|
||||
end
|
||||
add_index "activity_notifies", ["notify_to"], :name => "index_an_notify_to"
|
||||
add_index "activity_notifies", ["created_on"], :name => "index_an_created_on"
|
||||
add_index "activity_notifies", ["activity_container_id","activity_container_type"], :name => "index_an_activity_container_id"
|
||||
end
|
||||
end
|
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
|
@ -53,9 +53,9 @@ a:hover.problem_new_btn{ background:#ff7143; color:#fff;}
|
|||
a.problem_pic{ display:block; width:42px; height:42px; padding:3px; border:1px solid #e3e3e3;}
|
||||
a:hover.problem_pic{border:1px solid #64bdd9;}
|
||||
.problem_txt{ width:610px; margin-left:10px; color:#777777;word-break: break-all;word-wrap: break-word;}
|
||||
a.problem_name{ color:#ff5722;}
|
||||
a.problem_name{ color:#ff5722;max-width:60px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
|
||||
a:hover.problem_name{ color:#d33503;}
|
||||
a.problem_tit{ color:#0781b4; max-width:430px; display:block; overflow:hidden; white-space: nowrap; text-overflow:ellipsis;}
|
||||
a.problem_tit{ color:#0781b4; max-width:410px; display:block; overflow:hidden; white-space: nowrap; text-overflow:ellipsis;}
|
||||
a:hover.problem_tit{ color:#09658c; }
|
||||
.problem_main{ border-bottom:1px dashed #d4d4d4; padding-bottom:10px; margin-bottom:10px;}
|
||||
/****翻页***/
|
||||
|
@ -672,7 +672,10 @@ input#score{ width:40px;}
|
|||
|
||||
.filename { background: url(../images/pic_file.png) 0 -25px no-repeat;color: #3ca5c6;max-width: 150px;border: none; padding-left: 20px;margin-right: 10px;margin-bottom: 5px;}
|
||||
|
||||
|
||||
/* 与我相关 */
|
||||
.new_icon{background:url(../images/new_icon.png) 0px 0px no-repeat; width:35px; height:15px; display:block;}
|
||||
a.about_me{ width:80px;text-align:center;font-size:16px; color:#64bdd9; margin:10px 0 0 10px;}
|
||||
a:hover.about_me{ color:#0781b4;}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue