diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 6b421bf2a..8a64918ae 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -49,9 +49,16 @@ class CommentsController < ApplicationController # end # # ������ض�̬�ļ�¼add end flash[:notice] = l(:label_comment_added) + course_activity = CourseActivity.where("course_act_type='News' and course_act_id =#{@news.id}").first + if course_activity + course_activity.updated_at = Time.now + course_activity.save + end user_activity = UserActivity.where("act_type='News' and act_id =#{@news.id}").first - user_activity.updated_at = @comment.created_on - user_activity.save + if user_activity + user_activity.updated_at = Time.now + user_activity.save + end end if params[:user_activity_id] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b30715a1f..e12d4886a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -8,7 +8,7 @@ class CoursesController < ApplicationController helper :attachments helper :activity_notifys - before_filter :auth_login1, :only => [:show, :feedback] + before_filter :auth_login1, :only => [:show, :course_activity, :feedback] menu_item :overview menu_item :feedback, :only => :feedback menu_item :homework, :only => :homework @@ -610,11 +610,37 @@ class CoursesController < ApplicationController end end + def course_activity + redirect_to course_url(@course, type: params[:type], page: params[:page]) + end + def show - course_activities = @course.course_activities.order("created_at desc") + course_activities = @course.course_activities @canShowRealName = User.current.member_of_course? @course - @course_activities = paginateHelper course_activities,10 + @page = params[:page] ? params[:page].to_i + 1 : 0 + if params[:type].present? + case params[:type] + when "homework" + @course_activities = course_activities.where("course_act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10) + when "news" + @course_activities = course_activities.where("course_act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10) + when "message" + @course_activities = course_activities.where("course_act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10) + when "poll" + @course_activities = course_activities.where("course_act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10) + when "attachment" + @course_activities = course_activities.where("course_act_type = 'Attachment'").order('updated_at desc').limit(10).offset(@page * 10) + when "journalsForMessage" + @course_activities = course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10) + else + @course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10) + end + else + @course_activities = course_activities.order('updated_at desc').limit(10).offset(@page * 10) + end + @type = params[:type] respond_to do |format| + format.js format.html{render :layout => 'base_courses'} format.api end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 7b81d12db..0f8330afe 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -176,12 +176,6 @@ class FilesController < ApplicationController def index @flag = params[:flag] || false - #sort_init 'filename', 'asc' - # sort_init 'created_on', 'desc' - # sort_update 'created_on' => "#{Attachment.table_name}.created_on", - # 'filename' => "#{Attachment.table_name}.filename", - # 'size' => "#{Attachment.table_name}.filesize", - # 'downloads' => "#{Attachment.table_name}.downloads" sort = "" @sort = "" @order = "" diff --git a/app/controllers/git_usage_controller.rb b/app/controllers/git_usage_controller.rb deleted file mode 100644 index 56aaa56f1..000000000 --- a/app/controllers/git_usage_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -#added by baiyu -class GitUsageController < ApplicationController - layout "new_base" - def ch_usage - - end - - def en_usage - - end -end -#end \ No newline at end of file diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 00d814bd3..9e3a4b836 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -11,11 +11,16 @@ class HomeworkCommonController < ApplicationController before_filter :member_of_course, :only => [:index] def index - homeworks = @course.homework_commons.order("created_at desc") + @new_homework = HomeworkCommon.new + @new_homework.homework_detail_manual = HomeworkDetailManual.new + @new_homework.course = @course + @page = params[:page] ? params[:page].to_i + 1 : 0 + @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) - @homeworks = paginateHelper homeworks,20 + @is_new = params[:is_new] respond_to do |format| + format.js format.html end end @@ -32,7 +37,7 @@ class HomeworkCommonController < ApplicationController def edit @user = User.current - @is_in_course = params[:is_in_course] + @is_in_course = params[:is_in_course].to_i respond_to do |format| format.html{render :layout => 'new_base_user'} end @@ -148,9 +153,9 @@ class HomeworkCommonController < ApplicationController # 开启/关闭匿评消息通知 def send_message_anonymous_comment(homework, m_status ) # status 标记匿评状态 1为关闭 0为开启 - course = @homework.course - course.student.each do |st| - @homework.course_messages << CourseMessage.new(:user_id => st.student_id, :course_id => course.id, :viewed => false, :status => m_status) + course = homework.course + course.members.each do |m| + @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) end end #提示 diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 2c7df84cf..4f3f3ec0d 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -162,9 +162,16 @@ class MessagesController < ApplicationController @reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] # @reply.reply_id = params[:id] @topic.children << @reply + course_activity = CourseActivity.where("course_act_type='Message' and course_act_id =#{@topic.id}").first + if course_activity + course_activity.updated_at = Time.now + course_activity.save + end user_activity = UserActivity.where("act_type='Message' and act_id =#{@topic.id}").first - user_activity.updated_at = Time.now - user_activity.save + if user_activity + user_activity.updated_at = Time.now + user_activity.save + end #@topic.update_attribute(:updated_on, Time.now) if !@reply.new_record? if params[:asset_id] diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d5c248f77..5d83c1320 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -175,19 +175,19 @@ class NewsController < ApplicationController update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS end # ������ض�̬�ļ�¼add start - teachers = searchTeacherAndAssistant(@course) - for teacher in teachers - if(teacher.user_id != User.current.id) - notify = ActivityNotify.new() - notify.activity_container_id = @course.id - notify.activity_container_type = 'Course' - notify.activity_id = @news.id - notify.activity_type = 'News' - notify.notify_to = teacher.user_id - notify.is_read = 0 - notify.save() - end - end + # teachers = searchTeacherAndAssistant(@course) + # for teacher in teachers + # if(teacher.user_id != User.current.id) + # notify = ActivityNotify.new() + # notify.activity_container_id = @course.id + # notify.activity_container_type = 'Course' + # notify.activity_id = @news.id + # notify.activity_type = 'News' + # notify.notify_to = teacher.user_id + # notify.is_read = 0 + # notify.save() + # end + # end # ������ض�̬�ļ�¼add end render_attachment_warning_if_needed(@news) flash[:notice] = l(:notice_successful_create) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 2d7bf02b1..17f179492 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -173,6 +173,16 @@ class StudentWorkController < ApplicationController end if student_work.save + course_activity = CourseActivity.where("course_act_type='HomeworkCommon' and course_act_id =#{@homework.id}").first + if course_activity + course_activity.updated_at = Time.now + course_activity.save + end + user_activity = UserActivity.where("act_type='HomeworkCommon' and act_id =#{@homework.id}").first + if user_activity + user_activity.updated_at = Time.now + user_activity.save + end respond_to do |format| format.html { flash[:notice] = l(:notice_successful_create) @@ -261,6 +271,7 @@ class StudentWorkController < ApplicationController end @is_new = false else + @is_last_a = @work.student_works_scores.empty? @score = StudentWorksScore.new @score.score = params[:score] if params[:score] @score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0ffa334c2..6b03cff1e 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -244,10 +244,11 @@ class TagsController < ApplicationController @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - #看重命名后的tag是否存在。如果存在的话,只需要更改taggings里边的id即可 + #看重命名后的tag是否存在。如果存在的话,只需要更改taggings里边的id, if @rename_tag - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) - @taggings.update_attributes({:tag_id=>@rename_tag.id}) + @taggings = ActsAsTaggableOn::Tagging.where(" `taggings`.`tag_id` = #{ @tag_id} AND `taggings`.`taggable_type` = 'Attachment' ")#find_by_tag_id_and_taggable_type(@tag_id,@taggable_type) + @taggings.each { |t| t.update_attributes({:tag_id=> @rename_tag.id}) if t.tag_id != @rename_tag.id } + ActsAsTaggableOn::Tag.find(@tag_id).update_attributes(:name=>@rename_tag_name)#并且将该tag改名 else #如果不存在,那么就直接更新该tag名称为新的名称 (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).update_attributes(:name=>@rename_tag_name) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9a6f72e2e..73a26b52c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -346,6 +346,7 @@ class UsersController < ApplicationController user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + @is_in_course = params[:is_in_course].to_i || 0 respond_to do |format| format.js format.html {render :layout => 'new_base_user'} @@ -357,6 +358,7 @@ class UsersController < ApplicationController #导入作业 def user_import_homeworks + @select_course = params[:select_course] ? 1 : 0 @user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc") respond_to do |format| format.js @@ -376,6 +378,7 @@ class UsersController < ApplicationController homework = HomeworkCommon.find_by_id params[:checkMenu] homework_detail_programing = homework.homework_detail_programing @homework = HomeworkCommon.new + @select_course = params[:select_course] || 0 if homework @homework.name = homework.name @homework.description = homework.description @@ -508,7 +511,13 @@ class UsersController < ApplicationController if homework.save homework_detail_manual.save if homework_detail_manual homework_detail_programing.save if homework_detail_programing - redirect_to user_homeworks_user_path(User.current.id) + + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => homework.course_id) + else + redirect_to user_homeworks_user_path(User.current.id) + end + end end else diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 77304c1b1..a59f507df 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -53,7 +53,19 @@ class WordsController < ApplicationController :notes => content, :is_readed => false} @jfm = add_reply_adapter options - + @save_succ = true if @jfm.errors.empty? + if @save_succ + course_activity = CourseActivity.where("course_act_type='JournalsForMessage' and course_act_id =#{parent_id}").first + if course_activity + course_activity.updated_at = Time.now + course_activity.save + end + user_activity = UserActivity.where("act_type='JournalsForMessage' and act_id =#{parent_id}").first + if user_activity + user_activity.updated_at = Time.now + user_activity.save + end + end respond_to do |format| # format.html { # if @jfm.errors.empty? @@ -63,10 +75,12 @@ class WordsController < ApplicationController # end # render 'test/index' # } - format.js{ - @save_succ = true if @jfm.errors.empty? + format.js { + @user_activity_id = params[:user_activity_id] if + @activity = JournalsForMessage.find(parent_id) } end + end def destroy diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index 1a0b9ca0d..3591a0168 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -119,7 +119,7 @@ module JournalsHelper content << textAreailizable(journal, :notes) css_classes = "wiki" css_classes << " editable" if editable - content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes ,:style => "width:510px") + content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes) end def link_to_in_place_notes_editor(text, field_id, url, options={}) diff --git a/app/models/course_message.rb b/app/models/course_message.rb index eae880380..65e91141c 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,4 +1,7 @@ class CourseMessage < ActiveRecord::Base + # status说明: status在课程不同的类型,区分不同的功能 + # HomeworkCommon:status: + # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败 attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status # 多态 虚拟关联 diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 0dce57598..8bf754719 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -1,14 +1,7 @@ class ForgeMessage < ActiveRecord::Base - # 公共表中活动类型,命名规则:TYPE_OF_{类名}_ACT - TYPE_OF_ISSUE_ACT = "Issue" - TYPE_OF_MESSAGE_ACT = "Message" - TYPE_OF_ATTACHMENT_ACT = "Attachment" - TYPE_OF_DOCUMENT_ACT = "Document" - TYPE_OF_JOURNAL_ACT = "Journal" - TYPE_OF_WIKI_ACT = "Wiki" - TYPE_OF_NEWS_ACT = "News" - - attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key + # status在不同的类中,作用不同 + # Isseu: satus nil:发布了缺陷;:1:缺陷计划完成日志到了提醒 + attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key, :status belongs_to :forge_message ,:polymorphic => true belongs_to :project diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c1e5666ac..796080645 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -40,9 +40,9 @@ class HomeworkCommon < ActiveRecord::Base def act_as_course_message if self.course self.course.members.each do |m| - if m.user_id != self.user_id + # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - end + # end end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 81ada2f80..dde34abfd 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -185,7 +185,7 @@ class JournalsForMessage < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity - if self.jour_type == 'Course' + if self.jour_type == 'Course' && self.m_parent_id.nil? self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.jour_id) end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index b820e6d54..39e709beb 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -51,8 +51,8 @@ class Mailer < ActionMailer::Base def send_mail_anonymous_comment_open(homework_common) course = homework_common.course recipients ||= [] - course.student.each do |student| - user = User.find(student.student_id) + course.members.each do |member| + user = User.find(member.user_id) @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" @token = Token.get_token_from_user(user, 'autologin') @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) @@ -69,9 +69,9 @@ class Mailer < ActionMailer::Base def send_mail_anonymous_comment_close(homework_common) course = homework_common.course recipients ||= [] - course.student.each do |student| - user = User.find(student.student_id) - @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}" + course.members.each do |member| + user = User.find(member.user_id) + @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_close)}" @token = Token.get_token_from_user(user, 'autologin') @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) @anonymous_comment_close_name = homework_common.name @@ -83,6 +83,27 @@ class Mailer < ActionMailer::Base :subject => @subject end + # 匿评失败给老师发送邮件通知 + def send_mail_anonymous_comment_fail(homework_common) + course = homework_common.course + recipients ||= [] + # 只给该课程的老师发送邮件提醒 + course.members.each do |member| + if member.user.allowed_to?(:as_teacher,course) + user = User.find(member.user_id) + @subject = "[#{l(:mail_homework)} #{homework_common.name}] #{l(:mail_anonymous_comment_failed)}" + @token = Token.get_token_from_user(user, 'autologin') + @anonymous_comment_fail_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value)) + @anonymous_comment_fail_name = homework_common.name + @author = homework_common.user + #收件人邮箱 + recipients << user.mail + end + end + mail :to => recipients, + :subject => @subject + end + # author: alan # 邀请未注册用户加入项目 # 功能: 在加入项目的同时自动注册用户 @@ -247,6 +268,7 @@ class Mailer < ActionMailer::Base has_content = [@issues,@issues_journals,@course_messages,@project_messages,@course_news,@course_news_comments,@project_news,@project_news_comments,@project_attachments, @course_journal_messages,@user_journal_messages,@project_journal_messages,@forums,@memos,@attachments,@bids,@wiki_contents].any? {|o| !o.empty?} + mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}" #有内容才发,没有不发 mail :to => user.mail,:subject => subject if has_content @@ -263,7 +285,7 @@ class Mailer < ActionMailer::Base #收件人邮箱 recipient = user.mail mail :to => recipient, - :subject => "#{l(:mail_homework)}#{homework_common.name}#{l(:mail_homework_endtime)} " + :subject => @subject end # 公共讨论区发帖、回帖添加邮件发送信息 diff --git a/app/models/memo.rb b/app/models/memo.rb index c30616558..33b24db50 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -79,7 +79,7 @@ class Memo < ActiveRecord::Base receivers << self.forum.creator end # 添加发帖人 - if self.author_id != self.parent.author_id + if self.author_id != self.parent.author_id && self.parent.author_id != self.forum.creator_id receivers << self.parent.author end end diff --git a/app/models/message.rb b/app/models/message.rb index 2c46857f8..7af59815b 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -194,7 +194,7 @@ class Message < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity - if self.course + if self.course && self.parent_id.nil? self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.board.course_id) end end diff --git a/app/views/avatar/_new_avatar_form.html.erb b/app/views/avatar/_new_avatar_form.html.erb index 64abfbc30..2593bf1f5 100644 --- a/app/views/avatar/_new_avatar_form.html.erb +++ b/app/views/avatar/_new_avatar_form.html.erb @@ -2,10 +2,10 @@ <%= image_tag(url_to_avatar(source), id: "avatar_image", :width =>"60", :height =>"60",:alt=>"上传图片")%> <%#= link_to l(:button_delete_file),{:controller => :avatar,:action => :delete_image,:remote=>true,:source_type=> source.class,:source_id=>source.id},:confirm => l(:text_are_you_sure), :method => :post, :class => "upbtn fl" %> -<%= l(:button_upload_photo) %> +<%= l(:button_upload_photo) %> <%= file_field_tag 'avatar[image]', - :id => nil, - :class => 'upload_file', + :id => 'upload_course_logo', + :class => 'undis upload_file', :size => "1", :multiple => true, :data => { diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb new file mode 100644 index 000000000..e2e1dcfc2 --- /dev/null +++ b/app/views/courses/_course_activity.html.erb @@ -0,0 +1,127 @@ +<%= javascript_include_tag "/assets/kindeditor/kindeditor", '/assets/kindeditor/pasteimg', "init_activity_KindEditor" %> + +<% course_activities.each do |activity| if course_activities %> + + <% if activity %> + <% act = activity.course_act %> + <% case activity.course_act_type.to_s %> + <% when 'HomeworkCommon' %> + <%= render :partial => 'users/course_homework', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% when 'News' %> + <%= render :partial => 'users/course_news', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% when 'Message' %> + <%= render :partial => 'users/course_message', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% when 'Poll' %> + <%= render :partial => 'users/course_poll', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% when 'JournalsForMessage' %> + <%= render :partial => 'users/course_journalsformessage', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% when 'Attachment' %> + <%= render :partial => 'users/course_attachment', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% when 'Course' %> + <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => activity.id} %> + <% end %> + <% end %> + <% end %> +<% end %> + +<% if course_activities.count == 10 %> +
- <%= course_activity_desc activity%>
-
-
+ <%= course_activity_desc activity%>
+
+