diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 148f45d2c..b0475097d 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -40,9 +40,10 @@ class BlogCommentsController < ApplicationController end def show @article = BlogComment.find(params[:id]) - all_comments = [] - @replies = get_all_children(all_comments, @article) + @replies = BlogComment.where("root_id = #{@article.id}").reorder("created_on desc") @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + @limit_count = @replies.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @replies = @replies[@page * @limit..@page * @limit + 9] diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0c7eb570f..51fcdcc2d 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -50,6 +50,8 @@ class MessagesController < ApplicationController all_comments = [] @replies = Message.where("root_id = #{@topic.id}").reorder("created_on desc") @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + @limit_count = @replies.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @replies = @replies[@page * @limit..@page * @limit + 9] @@ -171,9 +173,6 @@ class MessagesController < ApplicationController @reply.root_id = parent.root_id.nil? ? parent.id : parent.root_id # @reply.reply_id = params[:id] parent.children << @reply - @user_activity_id = params[:user_activity_id] if params[:user_activity_id] - @is_course = params[:is_course] if params[:is_course] - @is_board = params[:is_board] if params[:is_board] else @quote = params[:quote][:quote] @reply = Message.new @@ -207,8 +206,8 @@ class MessagesController < ApplicationController end if params[:user_activity_id] @user_activity_id = params[:user_activity_id] - @is_course = params[:is_course] - @is_board = params[:is_board] + @is_course = params[:is_course] if params[:is_course] + @is_board = params[:is_board] if params[:is_board] respond_to do |format| format.js end @@ -282,8 +281,8 @@ class MessagesController < ApplicationController @message.destroy @topic = Message.find(params[:activity_id].to_i) @user_activity_id = params[:user_activity_id] - @is_course = params[:is_course] - @is_board = params[:is_board] + @is_course = params[:is_course] if params[:is_course] + @is_board = params[:is_board] if params[:is_board] respond_to do |format| format.js end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 53afa50aa..aa037b8d5 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -172,6 +172,8 @@ class NewsController < ApplicationController @news = result[:news] @comments = result[:comments] @comments_count = @comments.count + @comments = get_no_children_comments_all @comments + @limit_count = @comments.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @comments = @comments[@page * @limit..@page * @limit + 9] diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 49e970af7..6b8d11479 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -41,8 +41,10 @@ class OrgDocumentCommentsController < ApplicationController @org_subfield = OrgSubfield.where(:id => @document.org_subfield_id).first @subfield_content = @organization.org_subfields.order("priority") all_comments = [] - @replies = get_all_children(all_comments, @document) + @replies = OrgDocumentComment.where("root_id = #{@document.id}").reorder("created_at desc") @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + @limit_count = @replies.count @page = params[:page] ? params[:page].to_i + 1 : 0 @limit = 10 @replies = @replies[@page * @limit..@page * @limit + 9] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 13a1a1e58..09cede45a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -601,6 +601,13 @@ class ProjectsController < ApplicationController def member_forked @forked_projects = Project.where(:forked_from_project_id => @project.id) + @limit = 20 + @is_remote = true + @forked_count = @project.forked_count + @forked_pages = Paginator.new @forked_count, @limit, params['page'] || 1 + @offset ||= @forked_pages.offset + @forked_projects = paginateHelper @forked_projects, @limit + # @forked_members = User.find_by_sql("SELECT u.* FROM `projects` p,`users` u where p.user_id = u.id and p.forked_from_project_id = #{@project.id} ;") end @@ -664,7 +671,13 @@ class ProjectsController < ApplicationController end def statistics - + @watchers = @project.watcher_users + @limit = 20 + @is_remote = true + @watchers_count = @watchers.count + @watcher_pages = Paginator.new @watchers_count, @limit, params['page'] || 1 + @offset ||= @watcher_pages.offset + @watchers = paginateHelper @watchers, 20 end #end @@ -972,14 +985,6 @@ class ProjectsController < ApplicationController else @users -= watched.watcher_users if @watched end - @watchers = @project.watcher_users - @limit = 20 - @is_remote = true - @watchers_count = @watchers.count - @watcher_pages = Paginator.new @watchers_count, @limit, params['page'] || 1 - @offset ||= @watcher_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @watchers = paginateHelper @watchers,20 end end diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index cad65f88d..13bacbd4b 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -92,7 +92,7 @@ class SyllabusesController < ApplicationController def destroy if @syllabus && @syllabus.courses.not_deleted.empty? @syllabus.destroy - redirect_to user_courselist_user_path(User.current.id) + redirect_to user_courselist_user_path(User.current) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 049789115..262c014d3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -171,7 +171,6 @@ class UsersController < ApplicationController else @user_activity_id = -1 end - @hw_status = params[:hw_status].to_i when 'JournalsForMessage' @reply = JournalsForMessage.find params[:reply_id] @user_activity_id = params[:user_activity_id] @@ -181,15 +180,11 @@ class UsersController < ApplicationController @reply = Message.find params[:reply_id] @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] - @is_course = params[:is_course] - @is_board = params[:is_board] @type = 'Message' when 'BlogComment' @reply = BlogComment.find params[:reply_id] @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] - @homepage = params[:homepage] - @user_id = params[:user_id] @type = 'BlogComment' when 'OrgDocumentComment' @reply = OrgDocumentComment.find params[:reply_id] @@ -215,6 +210,96 @@ class UsersController < ApplicationController end end + #叠层回复框中的回复 + def reply_to_comment + @type = params[:type] + @reply = get_reply_by_type @type, params[:reply_id] + @user_activity_id = params[:user_activity_id] + @is_project = params[:is_project] if params[:is_project] + respond_to do |format| + format.js + end + end + + #多级回复 + def reply_detail + @type = params[:type] + reply = get_reply_by_type @type, params[:reply_id] + @user_activity_id = params[:user_activity_id] + case params[:type] + when 'HomeworkCommon' + @root = HomeworkCommon.find reply.jour_id + options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id} + comment = HomeworkCommon.add_homework_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options) + @root.update_column('updated_at', Time.now) + @is_teacher = User.current.allowed_to?(:as_teacher, @root.course) || User.current.admin? + when 'JournalsForMessage' + options = {:user_id => User.current.id, + :status => true, + :m_parent_id => params[:reply_id], + :m_reply_id => params[:reply_id], + :reply_id => reply.user.id, + :notes => params[:reply_message], + :root_id => reply.root_id, + :is_readed => false} + @root = reply.root + comment = add_reply_adapter(@root, options) + @root.update_attribute(:updated_on,Time.now) + when 'Message' + @root = reply.root + comment = Message.new + comment.author = User.current + comment.board = reply.board + comment.content = params[:reply_message] + comment.subject = "RE: #{@root.subject}" + comment.reply_id = params[:reply_id] + comment.root_id = reply.root_id + reply.children << comment + @is_project = params[:is_project] if params[:is_project] + when 'BlogComment' + @root = reply.root + comment = BlogComment.new + comment.author = User.current + comment.blog = reply.blog + comment.title = "RE: #{@root.title}" + comment.content = params[:reply_message] + comment.reply_id = params[:reply_id] + comment.root_id = reply.root_id + reply.children << comment + when 'OrgDocumentComment' + @root = reply.root + comment = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:reply_id]) + comment.title = "RE:#{@root.title}" + comment.content = params[:reply_message] + comment.root_id = reply.root_id + reply.children << comment + when 'News' + @root = News.find reply.commented_id + comment = @root.comments.build(:author_id => User.current.id, :reply_id => params[:reply_id], :comments => params[:reply_message], :parent_id => reply.id) + comment.save + when 'Issue' + @root = reply.issue + comment = @root.journals.build(:user_id => User.current.id, :reply_id => params[:reply_id], :notes => params[:reply_message], :parent_id => reply.id) + comment.save + @is_project = params[:is_project] if params[:is_project] + when 'Syllabus' + @root = Syllabus.find reply.jour_id + options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id} + comment = Syllabus.add_syllabus_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options) + @root.update_column('updated_at', Time.now) + @count = @root.journals_for_messages.count + @comments = @root.journals_for_messages.reorder("created_on desc").limit(3) + end + update_course_activity(@root.class.to_s,@root.id) + update_user_activity(@root.class.to_s,@root.id) + update_forge_activity(@root.class.to_s,@root.id) + update_org_activity(@root.class.to_s,@root.id) + update_principal_activity(@root.class.to_s,@root.id) + respond_to do |format| + format.js + end + end + def refresh_changests if !(@user.nil?) && !(@user.memberships.nil?) @user.memberships.each do |member| @@ -3398,7 +3483,11 @@ class UsersController < ApplicationController @my_syllabuses = @user.syllabuses - my_syllabus_ids = @my_syllabuses.empty? ? "(-1)" : "(" + @my_syllabuses.map{|syllabus| syllabus.id}.join(',') + ")" + if @user == User.current + archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + end + sy_courses = @user.courses.visible.not_deleted syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" syllabus_members = SyllabusMember.where("user_id = #{@user.id}") @@ -3470,11 +3559,58 @@ class UsersController < ApplicationController end end + #归档班级列表 + def user_archive_courses + if User.current.logged? + @order, @c_sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end + + @user = User.current + sort_name = "updated_at" + archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + + if @order.to_i == 1 #根据 班级更新时间排序 + @archive_syllabuses = syllabus_course_list_sort @archive_syllabuses + @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}) + @type = 1 + elsif @order.to_i == 2 #根据 作业+资源数排序 + @type = 2 + @archive_syllabuses.each do |syllabus| + count = 0 + courses = syllabus.courses.not_deleted + courses.each do |c| + count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) + end + syllabus[:infocount] = count + end + @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @archive_syllabuses = sortby_time_countcommon_nosticky @archive_syllabuses,sort_name + else + @type = 1 + end + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + end + end + #展开课程下的班级 def expand_courses @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first unless @syllabus.nil? - @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + if params[:is_delete] && params[:is_delete] == '1' + @courses = @syllabus.courses.where("is_delete = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + else + @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + end respond_to do |format| format.js end @@ -3567,18 +3703,12 @@ class UsersController < ApplicationController if params[:type].present? case params[:type] when 'OrgDocumentComment' - #obj = OrgDocumentComment.where('id = ?', params[:id].to_i).first @user_activity_id = params[:div_id].to_i if params[:div_id] @type = 'OrgDocumentComment' - #comments = [] @journals = OrgDocumentComment.where("root_id = #{params[:id].to_i}").reorder("created_at desc") when 'Message','is_project_message' - #obj = Message.where('id = ?', params[:id].to_i).first @type = 'Message' - @is_course = params[:is_course] - @is_board = params[:is_board] @user_activity_id = params[:div_id].to_i if params[:div_id] - #comments = [] @journals = Message.where("root_id = #{params[:id].to_i}").reorder("created_on desc") when 'News' obj = News.where('id = ?', params[:id].to_i).first @@ -3591,8 +3721,6 @@ class UsersController < ApplicationController @type = 'Syllabus' @user_activity_id = params[:div_id].to_i if params[:div_id] when 'JournalsForMessage' - #obj = JournalsForMessage.where('id = ?', params[:id].to_i).first - #journals = [] @journals = JournalsForMessage.where("root_id = #{params[:id].to_i}").reorder("created_on desc") @type = 'JournalsForMessage' @user_activity_id = params[:div_id].to_i if params[:div_id] @@ -3609,20 +3737,17 @@ class UsersController < ApplicationController when 'BlogComment' obj = BlogComment.where('id = ?', params[:id].to_i).first @user_activity_id = params[:div_id].to_i if params[:div_id] - @homepage = params[:homepage].to_i @type = 'BlogComment' - @user_id = obj.author_id - #comments = [] @journals = BlogComment.where("root_id = #{params[:id].to_i}").reorder("created_on desc") when 'HomeworkCommon' obj = HomeworkCommon.where('id = ?', params[:id].to_i).first @type = 'HomeworkCommon' @journals = obj.journals_for_messages.reorder("created_on desc") - @hw_status = params[:hw_status].to_i if params[:hw_status] @is_teacher = User.current.allowed_to?(:as_teacher,obj.course) @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id] end end + @journals = get_no_children_comments_all @journals end def homepage diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index e4b480e2f..2ce505e15 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -116,7 +116,7 @@ class WordsController < ApplicationController else @user_activity_id = -1 end - @hw_status = params[:hw_status].to_i + @hw_status = params[:hw_status].to_i if @is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin? elsif @journal_destroyed.jour_type == 'Syllabus' @syllabus = Syllabus.find @journal_destroyed.jour_id @@ -315,7 +315,7 @@ class WordsController < ApplicationController respond_to do |format| format.js{ @user_activity_id = params[:user_activity_id].to_i - @hw_status = params[:hw_status].to_i + @hw_status = params[:hw_status].to_i if params[:hw_status] @is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin? } end @@ -349,7 +349,7 @@ class WordsController < ApplicationController respond_to do |format| format.js{ @user_activity_id = params[:user_activity_id].to_i - @hw_status = params[:hw_status].to_i + @hw_status = params[:hw_status].to_i if params[:hw_status] @is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin? } end @@ -454,45 +454,5 @@ class WordsController < ApplicationController end obj end - - def add_reply_adapter obj, options - #modify by nwb - #添加对课程留言的支持 - #留言回复应该不关系其所属的Class,而关心的是其所属的父留言 - case obj.jour_type - when 'Principal' - obj.jour.add_jour(nil, nil, nil, options) - when 'Project' - Project.add_new_jour(nil, nil, obj.jour_id, options) - when 'Course' - Course.add_new_jour(nil, nil, obj.jour_id, options) - when 'Bid' - obj.jour.add_jour(nil, nil, nil, options) - when 'Contest' - obj.jour.add_jour(nil, nil, obj.jour_id, options) - when 'Softapplication' - obj.jour.add_jour(nil, nil, obj.jour_id, options) - when 'HomeworkAttach' - obj.jour.add_jour(nil, nil, obj.jour_id, options) - end - # obj = obj_distinguish_url_origin || User.find_by_id(2) - # if obj.kind_of? User - # obj.add_jour(nil, nil, nil, options) - # elsif obj.kind_of? Project - # Project.add_new_jour(nil, nil, obj.id, options) - # elsif obj.kind_of? Course - # Course.add_new_jour(nil, nil, obj.id, options) - # elsif obj.kind_of? Bid - # obj.add_jour(nil, nil, nil, options) - # elsif obj.kind_of? Contest - # obj.add_jour(nil, nil, obj.id, options) #new added - # elsif obj.kind_of? Softapplication - # obj.add_jour(nil, nil, obj.id, options) #new added - # elsif obj.kind_of? HomeworkAttach - # obj.add_jour(nil, nil, obj.id, options) #new added - # else - # raise "create reply obj unknow type.#{obj.class}" - # end - end #######end of message end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c52182b01..ad3d2c61d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3394,6 +3394,61 @@ def secdomain_with_protocol secdomain return Setting.protocol + "://" + secdomain + ".trustie.net" end +#根据回复类型获取回复 +def get_reply_by_type type, reply_id + reply = nil + case type + when 'HomeworkCommon' + reply = JournalsForMessage.find reply_id + when 'JournalsForMessage' + reply = JournalsForMessage.find reply_id + when 'Message' + reply = Message.find reply_id + when 'BlogComment' + reply = BlogComment.find reply_id + when 'OrgDocumentComment' + reply = OrgDocumentComment.find reply_id + when 'News' + reply = Comment.find reply_id + when 'Issue' + reply = Journal.find reply_id + when 'Syllabus' + reply = JournalsForMessage.find reply_id + end + reply +end + +#获取不包含子节点的回复(前三个) +def get_no_children_comments comments + result = {} + no_children_comments = [] + count = 0 + three_more = false + comments.each do |comment| + if comment.children.blank? + count = count + 1 + if count > 3 + three_more = true + end + break if count > 3 + no_children_comments << comment + end + end + result[:three_more] = three_more + result[:no_children_comments] = no_children_comments + result +end + +#获取不包含子节点的回复(所有) +def get_no_children_comments_all comments + no_children_comments = [] + comments.each do |comment| + if comment.children.blank? + no_children_comments << comment + end + end + no_children_comments +end #获取回复的所有父节点 def get_reply_parents parents_rely, comment @@ -3746,3 +3801,43 @@ def homework_type_option type end +def add_reply_adapter obj, options + #modify by nwb + #添加对课程留言的支持 + #留言回复应该不关系其所属的Class,而关心的是其所属的父留言 + case obj.jour_type + when 'Principal' + obj.jour.add_jour(nil, nil, nil, options) + when 'Project' + Project.add_new_jour(nil, nil, obj.jour_id, options) + when 'Course' + Course.add_new_jour(nil, nil, obj.jour_id, options) + #when 'Bid' + # obj.jour.add_jour(nil, nil, nil, options) + #when 'Contest' + # obj.jour.add_jour(nil, nil, obj.jour_id, options) + #when 'Softapplication' + # obj.jour.add_jour(nil, nil, obj.jour_id, options) + #when 'HomeworkAttach' + # obj.jour.add_jour(nil, nil, obj.jour_id, options) + end + # obj = obj_distinguish_url_origin || User.find_by_id(2) + # if obj.kind_of? User + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Project + # Project.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Course + # Course.add_new_jour(nil, nil, obj.id, options) + # elsif obj.kind_of? Bid + # obj.add_jour(nil, nil, nil, options) + # elsif obj.kind_of? Contest + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? Softapplication + # obj.add_jour(nil, nil, obj.id, options) #new added + # elsif obj.kind_of? HomeworkAttach + # obj.add_jour(nil, nil, obj.id, options) #new added + # else + # raise "create reply obj unknow type.#{obj.class}" + # end +end + diff --git a/app/views/blog_comments/_blog_comment_show_replies.html.erb b/app/views/blog_comments/_blog_comment_show_replies.html.erb index ba33aaf5a..3a3e8ef81 100644 --- a/app/views/blog_comments/_blog_comment_show_replies.html.erb +++ b/app/views/blog_comments/_blog_comment_show_replies.html.erb @@ -10,7 +10,7 @@ <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 33, :height => 33, :alt => "用户头像"), user_url_in_org(comment.creator_user.id) %>
博客列表
diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index 6b40a23da..2b921c7a4 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -45,16 +45,15 @@
- <%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%> -+
<%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%>