diff --git a/Gemfile b/Gemfile index 87cd6dba2..3027c16cd 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/ gem 'iconv' end -gem 'grack', path:'./lib/grack' +gem 'grack', path:'lib/grack' gem 'gitlab', path: 'lib/gitlab-cli' gem 'rest-client' gem "mysql2", "= 0.3.18" diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 95790a68d..42f1e2f20 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -60,10 +60,16 @@ class BlogCommentsController < ApplicationController @article.children.delete @article.delete redirect_to user_blogs_path(:user_id=>User.current) - else - root = @article.root - @article.delete - redirect_to user_blog_blog_comment_path(:user_id=>root.author_id,:blog_id=>root.blog_id,:id=>root.id) + else#如果是回复被删, + if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + @article.delete + redirect_to show_course_outline_course_path(:id=>params[:course_id]) + else + root = @article.root + @article.delete + redirect_to user_blog_blog_comment_path(:user_id=>root.author_id,:blog_id=>root.blog_id,:id=>root.id) + end + end end @@ -81,6 +87,7 @@ class BlogCommentsController < ApplicationController @content = "> #{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}\n> " @temp = BlogComment.new + @course_id = params[:course_id] @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}".html_safe respond_to do | format| format.js @@ -89,6 +96,9 @@ class BlogCommentsController < ApplicationController #回复 def reply + if params[:in_user_center] + @in_user_center = true + end @article = BlogComment.find(params[:id]).root @quote = params[:quote][:quote] @blogComment = BlogComment.new @@ -101,13 +111,24 @@ class BlogCommentsController < ApplicationController @blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title] @article.children << @blogComment @user_activity_id = params[:user_activity_id] - + user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first + if user_activity + user_activity.updated_at = Time.now + user_activity.save + end attachments = Attachment.attach_files(@blogComment, params[:attachments]) render_attachment_warning_if_needed(@blogComment) #@article.save # redirect_to user_blogs_path(:user_id=>params[:user_id]) respond_to do |format| - format.html { redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article)} + format.html { + if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + redirect_to show_course_outline_course_path(:id=>params[:course_id]) + else + redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article) + end + + } format.js end rescue Exception => e #如果上面的代码执行发生异常就捕获 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c8c482f81..3c211b361 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -711,6 +711,39 @@ class CoursesController < ApplicationController end end + #从课程创建的老师那里选择课程大纲 + def course_outline + @teacher = User.find(@course.tea_id) + @blog_articles = @teacher.blog.articles + respond_to do |format| + format.js + end + end + + #根据关键字搜索,查找方法一样的,但返回内容不一样 + def search_course_outline + @article_title = params[:title] + @teacher = User.find(@course.tea_id) + @blog_articles = @teacher.blog.articles.like(@article_title) + render :json=>@blog_articles.to_json + end + + #设置或者更改课程的大纲 + def set_course_outline + @course.outline = params[:outline_id] + @course.save + respond_to do |format| + format.js + end + end + + #显示课程大纲 + def show_course_outline + @article = BlogComment.find(@course.outline) + respond_to do |format| + format.html {render :layout => 'base_courses'} + end + end #删除课程 #删除课程只是将课程的is_delete状态改为false,is_delete为false状态的课程只有管理员可以看到 def destroy diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 7793ef097..55807886b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -217,7 +217,12 @@ class HomeworkCommonController < ApplicationController #评分设置 def score_rule_set - + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] end private diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 6bb61e6a1..4dc2c52f5 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -159,6 +159,14 @@ class MembersController < ApplicationController if role && (role.name == "学生" || role.name == "Student") StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id) end + + #给新成员和老师发送加入课程的消息,发送者id放在CourseMessage的course_message_id字段中 + #course_message_type设置为JoinCourse + #status = 0 表示给学生发,status = 1表示给老师发 + course_join = CourseMessage.new(:user_id =>user_id, :course_message_id=>User.current.id,:course_id => @course.id,:course_message_type=>"JoinCourse", :content => role, :viewed => false, :status => 0) + course_join.save + CourseMessage.create(:user_id => User.current.id, :course_message_id => user_id, :course_id => @course.id, :course_message_type => "JoinCourse",:content => role, :viewed => false, :status => 1) + members << member #user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id) if (params[:membership][:role_ids]) @@ -305,7 +313,8 @@ class MembersController < ApplicationController grade.destroy end end - ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id) + #移出项目发送消息 + ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id) end respond_to do |format| format.html { redirect_to_settings_in_projects } @@ -333,6 +342,8 @@ class MembersController < ApplicationController end @roles = Role.givable.all[3..5] @members = @course.member_principals.includes(:roles, :principal).all.sort + #移出课程发送消息 + CourseMessage.create(:user_id => @member.user_id, :course_id => @course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => User.current.id) end respond_to do |format| format.html { redirect_to_settings_in_courses } diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 742a02337..f41dbe6c7 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -252,9 +252,12 @@ update else #Modified by young # (show_error_not_found; return) unless @entries - @changesets = @repository.latest_changesets(@path, @rev) - @changesets_count = @repository.latest_changesets(@path, @rev).count - @changesets_latest_coimmit = @changesets.first + g = Gitlab.client + @changesets = g.get ("/projects/#{@project.gpid}/repository/commits") + # @changesets = @repository.latest_changesets(@path, @rev) + # @changesets_count = @repository.latest_changesets(@path, @rev).count + @changesets_count = @changesets.count + @changesets_latest_coimmit = @changesets[0] @properties = @repository.properties(@path, @rev) @repositories = @project.repositories @course_tag = params[:course] @@ -280,7 +283,9 @@ update def changes @entry = @repository.entry(@path, @rev) (show_error_not_found; return) unless @entry - @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) + g = Gitlab.client + @changesets = g.get ("/projects/#{@project.gpid}/repository/commits?#{@rev}") + #@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) @properties = @repository.properties(@path, @rev) @changeset = @repository.find_changeset_by_name(@rev) render :layout => 'base_projects' diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 529c5ea72..25782ec4b 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -108,6 +108,7 @@ class StudentWorkController < ApplicationController else @stundet_works = [] end + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else if @is_teacher || @homework.homework_detail_manual.nil? #老师 || 超级管理员 显示所有列表 @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name @@ -128,6 +129,7 @@ class StudentWorkController < ApplicationController else @stundet_works = [] end + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name).count end @score = @b_sort == "desc" ? "asc" : "desc" @@ -456,14 +458,14 @@ class StudentWorkController < ApplicationController student_work.save end end - respond_to do |format| - format.html{ - if params[:student_path] - redirect_to student_work_index_url(:homework => @homework.id) - else - redirect_to user_homeworks_user_path(User.current.id) - end - } + if params[:student_path] + redirect_to student_work_index_url(:homework => @homework.id) + else + @user_activity_id = params[:user_activity_id] + @is_in_course = params[:is_in_course] + respond_to do |format| + format.js + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6d049783e..7c41dd038 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -949,10 +949,19 @@ class UsersController < ApplicationController 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}) or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + @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}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").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})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").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) + blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + @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}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7289d534b..84364b4f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2355,16 +2355,16 @@ module ApplicationHelper else #学生显示提交作品、修改作品等按钮 work = cur_user_works_for_homework homework if work.nil? - link_to "提交作品", new_student_work_path(:homework => homework.id),:class => 'c_blue' + link_to "提交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' else if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前 link_to "作品匿评", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品" elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 link_to "匿评结束", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "匿评已结束" elsif homework.homework_type == 2 #编程作业不能修改作品 - link_to "修改作品", new_student_work_path(:homework => homework.id),:class => 'c_blue' + link_to "修改作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue' else - link_to "修改作品", edit_student_work_path(work.id),:class => 'c_blue' + link_to "修改作品(#{homework.student_works.count})", edit_student_work_path(work.id),:class => 'c_blue' end end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index f9fb31969..a5acc4523 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -628,10 +628,10 @@ module CoursesHelper #重启、关闭课程按钮 def set_course_time course - id = "finish_course_#{course.id}" - linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js) - desc = course_endTime_timeout?(course) ? l(:label_course_reload) : l(:label_course_closed) - link_to "#{desc}".html_safe, linkPath, :remote => true, :method => :post, :id => id, :confirm => l(:label_course_closed_tips, :desc => desc), :class => "pr_join_a" + # id = "finish_course_#{course.id}" + # linkPath = course_endTime_timeout?(course) ? restartcourse_course_path(course) : finishcourse_course_path(course, format: :js) + # desc = course_endTime_timeout?(course) ? l(:label_course_reload) : l(:label_course_closed) + # link_to "#{desc}".html_safe, linkPath, :remote => true, :method => :post, :id => id, :confirm => l(:label_course_closed_tips, :desc => desc), :class => "pr_join_a" end #加入课程、退出课程按钮 diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 92970b663..27da33121 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -7,7 +7,8 @@ class BlogComment < ActiveRecord::Base acts_as_tree :counter_cache => :comments_count, :order => "#{BlogComment.table_name}.sticky desc ,#{BlogComment.table_name}.created_on ASC" acts_as_attachable belongs_to :last_reply, :class_name => 'BlogComment', :foreign_key => 'last_comment_id' - + # 虚拟关联 + has_many :user_acts, :class_name => 'UserAcivity',:as =>:act acts_as_watchable validates_presence_of :title, :content @@ -15,6 +16,40 @@ class BlogComment < ActiveRecord::Base #validate :cannot_reply_to_locked_comment, :on => :create safe_attributes 'title', 'content',"sticky", "locked" + after_save :add_user_activity + before_destroy :destroy_user_activity + + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where(" LOWER(title) LIKE :p ", :p => pattern) + end + } + + #在个人动态里面增加当前动态 + def add_user_activity + if self.parent_id.nil? #只有发博文才插入动态 + user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first + if user_activity + user_activity.save + else + user_activity = UserActivity.new + user_activity.act_id = self.id + user_activity.act_type = self.class.to_s + user_activity.container_type = "Blog" + user_activity.container_id = self.blog_id + user_activity.user_id = self.author_id + user_activity.save + end + end + end + + def destroy_user_activity + user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'") + user_activity.destroy_all + end def deleted_attach_able_by? user (user && user.logged? && (self.author == user) ) || user.admin? end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 807a26232..8092bee88 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -327,7 +327,7 @@ class CoursesService end else if params[:course_password] == course.password - if params[:role] == "10" + if params[:role] == "10" || params[:role] == nil members = [] members << Member.new(:role_ids => [10], :user_id => current_user.id) course.members << members diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index fa7ff0c4a..d65dd3faa 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -17,6 +17,9 @@
#{@blogComment.content.html_safe}