diff --git a/app/assets/javascripts/training_tasks.js.coffee b/app/assets/javascripts/training_tasks.js.coffee index 761567942..b3f5f376b 100644 --- a/app/assets/javascripts/training_tasks.js.coffee +++ b/app/assets/javascripts/training_tasks.js.coffee @@ -1,3 +1,3 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/training_tasks.css.scss b/app/assets/stylesheets/training_tasks.css.scss index 8a97abb85..5a071ec72 100644 --- a/app/assets/stylesheets/training_tasks.css.scss +++ b/app/assets/stylesheets/training_tasks.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the training_tasks controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ +// Place all the styles related to the training_tasks controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 6e91035d0..9d8a5ecc5 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -42,7 +42,7 @@ class AccountController < ApplicationController redirect_to user_path(User.current) end else - render :layout => 'login' + render :layout => 'login' end else authenticate_user diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index ece68733b..c2499e824 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -783,8 +783,8 @@ class AdminController < ApplicationController begin #更新消息表的status applied_message_id = aas.school_id - applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools") - applied_message.update_all(:status => 2) + #applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools") + #applied_message.update_all(:status => 2) aas.update_attribute(:status, 2) AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddSchools", :name => school[0].name ) users = UserExtensions.where("school_id = #{aas.school_id}") diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index b2dd971bb..88d4c4d53 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -39,6 +39,9 @@ class BlogCommentsController < ApplicationController end end def show + # 更新博客消息为已读 + update_messsages_to_viewed("BlogMessage", params[:blog_id]) + @article = BlogComment.find(params[:id]) @replies = BlogComment.where("root_id = #{@article.id}").reorder("created_on desc") @reply_count = @replies.count diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index e6fb49ec7..30072bc2d 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -7,7 +7,8 @@ class ContestsController < ApplicationController helper :attachments helper :files include AvatarHelper - + include ApplicationHelper + before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :private_or_public, :switch_role, :set_invite_code_halt, :renew, :member, :export_all_members, :feedback] before_filter :is_logged, :only => [:index, :new, :create] @@ -18,8 +19,7 @@ class ContestsController < ApplicationController def show #更新创建课程消息状态 - contest_request_messages = ContestMessage.where("user_id = #{User.current.id} and contest_id = #{@contest.id} and contest_message_type in ('ContestRequestDealResult', 'JoinContest', 'RemoveFromContest') and viewed = 0") - contest_request_messages.update_all(:viewed => true) + update_messsages_to_viewed("ContestMessage", @contest) @left_nav_type = 1 respond_to do |format| diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2f47fb808..b5b405d02 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -9,6 +9,7 @@ class CoursesController < ApplicationController helper :attachments helper :files helper :activity_notifys + include ApplicationHelper before_filter :auth_login1, :only => [:show, :course_activity, :feedback] menu_item :overview @@ -354,6 +355,44 @@ class CoursesController < ApplicationController #search_group_members group end + def change_manager + if params[:chooseteacher] + man_member = Member.where(:course_id => @course.id, :user_id => @course.tea_id).first + cha_member = Member.find params[:chooseteacher] + if man_member && cha_member + cha_member.member_roles.where("role_id = 9 || role_id = 7").first.update_attributes(:role_id => 3, :is_current => 1) + if cha_member.member_roles.where("role_id = 10").count > 0 + cha_member.member_roles.where("role_id = 10").first.destroy + StudentsForCourse.where(:course_id => @course.id, :student_id => cha_member.user_id).destroy_all + end + @course.update_attributes(:tea_id => cha_member.user_id) + man_member.member_roles.first.update_attributes(:role_id => 9) + course_act = CourseActivity.where(:course_id => @course.id, :course_act_id => @course.id, :course_act_type => 'Course').first + course_act.update_column('user_id', cha_member.user_id) + UserActivity.where(:act_id => @course.id, :container_type => 'Course', :act_type => 'Course', :container_id => @course.id).first.update_column('user_id', cha_member.user_id) + ws = WechatService.new + title = "您已成为班级管理员" + ws.create_class_notice cha_member.user_id, "create_course_notice", @course.id,title, @course.name, man_member.user.show_name, @course.members.count, "点击查看班级详情。" + end + end + end + + def search_course_teacher_list + q = params[:search] ? "#{params[:search].strip}" : "" + @members = searchTeacherAndAssistantNoManager(@course) + if q.nil? || q == "" + else + members = [] + @members.each do |m| + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if m && m.user && (m.user[:login].to_s.downcase.include?(q) || m.user[:mail].to_s.downcase.include?(q) || username.include?(q)) + members << m + end + end + @members = members + end + end + #查找未分班的学生 def search_not_group_member @group = CourseGroup.find params[:group_id] @@ -454,6 +493,8 @@ class CoursesController < ApplicationController end def member + # 当前用户查看班级消息时,设置消息为已读 + update_messsages_to_viewed("CourseMessage", @course) ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @render_file = 'new_member_list' @@ -1388,11 +1429,19 @@ class CoursesController < ApplicationController @members = @course.course_homework_statisticss.reorder("#{@type} #{@order}, total_score #{@order}") elsif params[:tab] == "3" + @homework_id = params[:homework_id] ? params[:homework_id].to_i : 0 @type = params[:type] ? params[:type] : 'project_act_score' - sql = "SELECT (IFNULL(changeset_num, 0)*4 + issue_num*4 + issue_journal_num*1 + attach_num*5 + board_num*2 + board_message_num*1) AS project_act_score, + if @homework_id == 0 + sql = "SELECT (IFNULL(changeset_num, 0)*4 + issue_num*4 + issue_journal_num*1 + attach_num*5 + board_num*2 + board_message_num*1) AS project_act_score, changeset_num, issue_num, issue_journal_num, attach_num, board_num, board_message_num, pss.project_id FROM project_scores pss JOIN student_work_projects ON student_work_projects.project_id = pss.project_id AND student_work_projects.course_id = #{@course.id} GROUP BY pss.project_id ORDER BY #{@type} #{@order}, project_act_score #{@order}" + else + sql = "SELECT (IFNULL(changeset_num, 0)*4 + issue_num*4 + issue_journal_num*1 + attach_num*5 + board_num*2 + board_message_num*1) AS project_act_score, + changeset_num, issue_num, issue_journal_num, attach_num, board_num, board_message_num, pss.project_id FROM project_scores pss + JOIN student_work_projects ON student_work_projects.project_id = pss.project_id AND student_work_projects.course_id = #{@course.id} AND student_work_projects.homework_common_id = #{@homework_id} + GROUP BY pss.project_id ORDER BY #{@type} #{@order}, project_act_score #{@order}" + end @members = ProjectScore.find_by_sql(sql) end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index d5511cb44..7d6539e8d 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -150,6 +150,7 @@ class HomeworkCommonController < ApplicationController end elsif @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 homework_detail_manual.comment_status = 1 + create_works_list @homework status = true #更新CourseHomeworkStatistics中每个学生的未交作品数 @homework.course.student.each do |student| diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 136915bbd..a60b85b90 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -1,168 +1,168 @@ -class PraiseTreadController < ApplicationController - - accept_api_auth :tread_plus,:praise_plus - # before_filter :require_login,:only => [:praise_plus,:tread_plus] - before_filter :user_unlogged_check,:only => [:praise_plus,:tread_plus,:praise_minus] - - def praise_plus - @obj = nil - @activity = false - if request.get? - @obj_id = params[:obj_id] - @obj_type = params[:obj_type] - if !params[:user_activity_id].nil? && !params[:type].nil? - @user_activity_id = params[:user_activity_id] - @type = params[:type] - @activity = true - end - # @is_in_list = nil - @obj = find_object_by_type_and_id(@obj_type,@obj_id) - pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id) - unless pts.empty? - respond_to do |format| - format.js - end - return - end - @horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal] - # if @obj.respond_to?("author_id") - # author_id = @obj.author_id - # elsif @obj.respond_to?("user_id") - # author_id = @obj.user_id - # end - # unless author_id == User.current.id - praise_tread_plus(@obj_type,@obj_id,1) - # end - respond_to do |format| - format.js - end - end - end - - def praise_minus - @obj = nil - @activity = false - if request.get? - #@obj = params[:obj] # 传的是对象,最后变成id了 - #首先更新praise_tread 表 删除关注记录 - #@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") - @obj_id = params[:obj_id] - @obj_type = params[:obj_type] - if !params[:user_activity_id].nil? && !params[:type].nil? - @user_activity_id = params[:user_activity_id] - @type = params[:type] - @activity = true - end - @obj = find_object_by_type_and_id(@obj_type,@obj_id) - @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first - if @pt.nil? - respond_to do |format| - format.js - end - return - end - @pt.delete if !@pt.nil? - #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 - @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first - @ptc.minus(1) if !@ptc.nil? - if @ptc.praise_num == 0 - @ptc.delete - end - - end - #@obj = User.find_by_id(@obj) - respond_to do |format| - format.js - end - end - - def tread_plus - @obj = nil - # @is_in_list = nil - if request.get? - @obj_id = params[:obj_id] - @obj_type = params[:obj_type] - #@horizontal = params[:horizontal].downcase == "false" ? false:true - @obj = find_object_by_type_and_id(@obj_type,@obj_id) - unless @obj.author_id == User.current.id - praise_tread_plus(@obj_type,@obj_id,0) - end - - end - end - - def tread_minus - respond_to do |format| - format.html - format.js - end - end - - private - - def find_object_by_type_and_id(type,id) - @obj = nil - case type - when 'Memo' - @obj = Memo.find_by_id(id) - when 'Message' - @obj = Message.find_by_id(id) - when 'HomeworkCommon' - @obj = HomeworkCommon.find_by_id(id) - when 'JournalsForMessage' - @obj = JournalsForMessage.find_by_id(id) - when 'News' - @obj = News.find_by_id(id) - when 'Comment' - @obj = Comment.find_by_id(id) - when 'Journal' - @obj = Journal.find_by_id(id) - when 'BlogComment' - @obj = BlogComment.find_by_id(id) - when 'OrgDocumentComment' - @obj = OrgDocumentComment.find_by_id(id) - when 'User' - @obj = User.find_by_id(id) - when 'Issue' - @obj = Issue.find_by_id(id) - when 'TrainingTask' - @obj = TrainingTask.find_by_id(id) - when 'Project' - @obj = Project.find_by_id(id) - when 'Bid' - @obj = Bid.find_by_id(id) - when 'Contest' - @obj = Contest.find_by_id(id) - when 'Syllabus' - @obj = Syllabus.find_by_id(id) - when 'Work' - @obj = Work.find_by_id(id) - else - @obj = nil - end - return @obj - end - - def praise_tread_plus(type,id,flag) - unless id.nil? and type.nil? - #首先创建或更新praise_tread 表 - @pt = PraiseTread.new - @pt.user_id = User.current.id - @pt.praise_tread_object_id = id.to_i - @pt.praise_tread_object_type = type - @pt.praise_or_tread = flag - @pt.save - # end - - #再创建或更新praise_tread_cache表 - #@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) - @ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first - @ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc - @ptc.object_id = id.to_i - @ptc.object_type = type - @ptc.save - @ptc.plus(flag,1) - end - end - -end +class PraiseTreadController < ApplicationController + + accept_api_auth :tread_plus,:praise_plus + # before_filter :require_login,:only => [:praise_plus,:tread_plus] + before_filter :user_unlogged_check,:only => [:praise_plus,:tread_plus,:praise_minus] + + def praise_plus + @obj = nil + @activity = false + if request.get? + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] + if !params[:user_activity_id].nil? && !params[:type].nil? + @user_activity_id = params[:user_activity_id] + @type = params[:type] + @activity = true + end + # @is_in_list = nil + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id) + unless pts.empty? + respond_to do |format| + format.js + end + return + end + @horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal] + # if @obj.respond_to?("author_id") + # author_id = @obj.author_id + # elsif @obj.respond_to?("user_id") + # author_id = @obj.user_id + # end + # unless author_id == User.current.id + praise_tread_plus(@obj_type,@obj_id,1) + # end + respond_to do |format| + format.js + end + end + end + + def praise_minus + @obj = nil + @activity = false + if request.get? + #@obj = params[:obj] # 传的是对象,最后变成id了 + #首先更新praise_tread 表 删除关注记录 + #@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] + if !params[:user_activity_id].nil? && !params[:type].nil? + @user_activity_id = params[:user_activity_id] + @type = params[:type] + @activity = true + end + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first + if @pt.nil? + respond_to do |format| + format.js + end + return + end + @pt.delete if !@pt.nil? + #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 + @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first + @ptc.minus(1) if !@ptc.nil? + if @ptc.praise_num == 0 + @ptc.delete + end + + end + #@obj = User.find_by_id(@obj) + respond_to do |format| + format.js + end + end + + def tread_plus + @obj = nil + # @is_in_list = nil + if request.get? + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] + #@horizontal = params[:horizontal].downcase == "false" ? false:true + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + unless @obj.author_id == User.current.id + praise_tread_plus(@obj_type,@obj_id,0) + end + + end + end + + def tread_minus + respond_to do |format| + format.html + format.js + end + end + + private + + def find_object_by_type_and_id(type,id) + @obj = nil + case type + when 'Memo' + @obj = Memo.find_by_id(id) + when 'Message' + @obj = Message.find_by_id(id) + when 'HomeworkCommon' + @obj = HomeworkCommon.find_by_id(id) + when 'JournalsForMessage' + @obj = JournalsForMessage.find_by_id(id) + when 'News' + @obj = News.find_by_id(id) + when 'Comment' + @obj = Comment.find_by_id(id) + when 'Journal' + @obj = Journal.find_by_id(id) + when 'BlogComment' + @obj = BlogComment.find_by_id(id) + when 'OrgDocumentComment' + @obj = OrgDocumentComment.find_by_id(id) + when 'User' + @obj = User.find_by_id(id) + when 'Issue' + @obj = Issue.find_by_id(id) + when 'TrainingTask' + @obj = TrainingTask.find_by_id(id) + when 'Project' + @obj = Project.find_by_id(id) + when 'Bid' + @obj = Bid.find_by_id(id) + when 'Contest' + @obj = Contest.find_by_id(id) + when 'Syllabus' + @obj = Syllabus.find_by_id(id) + when 'Work' + @obj = Work.find_by_id(id) + else + @obj = nil + end + return @obj + end + + def praise_tread_plus(type,id,flag) + unless id.nil? and type.nil? + #首先创建或更新praise_tread 表 + @pt = PraiseTread.new + @pt.user_id = User.current.id + @pt.praise_tread_object_id = id.to_i + @pt.praise_tread_object_type = type + @pt.praise_or_tread = flag + @pt.save + # end + + #再创建或更新praise_tread_cache表 + #@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) + @ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first + @ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc + @ptc.object_id = id.to_i + @ptc.object_type = type + @ptc.save + @ptc.plus(flag,1) + end + end + +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index cfe4a6cd8..f3f91d558 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -72,6 +72,7 @@ class ProjectsController < ApplicationController include UsersHelper ### added by william include ActsAsTaggableOn::TagsHelper + include ApplicationHelper # 仅仅为了转换Gitlab地址 def project_home @@ -575,7 +576,7 @@ class ProjectsController < ApplicationController if params[:message_id] message_invite(params[:message_id], params[:key]) end - update_message_status(User.current, @project) + update_messsages_to_viewed("ForgeMessage", @project) # params[:login]为邮箱邀请用户加入,主要功能: # 1、自动注册 # 2、加入项目、创建角色 diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index c27eade85..8d70980c8 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1253,7 +1253,7 @@ class StudentWorkController < ApplicationController def appeal_anonymous_score @student_work_score = StudentWorksScore.where("id = #{params[:score_id].to_i}").first - @is_last = params[:is_last] + @is_last = params[:is_last] == "true" ? true : false if @student_work_score @student_work_score.update_column('appeal_status', 1) score_appeal = StudentWorksScoresAppeal.create(:user_id => User.current.id, :student_works_score_id => @student_work_score.id, :comment => params[:appeal][:comment], :appeal_status => 1) @@ -1274,8 +1274,8 @@ class StudentWorkController < ApplicationController def deal_appeal_score @student_work_score = StudentWorksScore.where("id = #{params[:score_id].to_i}").first - @is_last = params[:is_last] - if @student_work_score + @is_last = params[:is_last] == "true" ? true : false + if @student_work_score && @student_work_score.appeal_status == 1 @student_work_score.update_column('appeal_status', params[:status].to_i) score_appeal = @student_work_score.student_works_scores_appeal score_appeal.applied_messages.update_all(:status => params[:status].to_i == 2 ? 3 : (params[:status].to_i == 3 ? 1 : 2)) @@ -1306,11 +1306,11 @@ class StudentWorkController < ApplicationController CourseMessage.create(:user_id => @student_work_score.user_id, :course_id => course.id, :viewed => false,:course_message_id=> score_appeal.id,:course_message_type=>'StudentWorksScoresAppeal',:status=>params[:status].to_i,:apply_result =>User.current.id) CourseMessage.create(:user_id => score_appeal.user_id, :course_id => course.id, :viewed => false,:course_message_id=> score_appeal.id,:course_message_type=>'StudentWorksScoresAppeal',:status=>params[:status].to_i,:apply_result =>User.current.id) end - @homework = @student_work_score.student_work.homework_common - @is_teacher = User.current.allowed_to?(:as_teacher, course) || User.current.admin? - @work = @student_work_score.student_work - @is_group_leader = !@work.student_work_projects.empty? end + @homework = @student_work_score.student_work.homework_common + @is_teacher = User.current.allowed_to?(:as_teacher, course) || User.current.admin? + @work = @student_work_score.student_work + @is_group_leader = !@work.student_work_projects.empty? end def forbidden_anonymous_comment diff --git a/app/controllers/training_tasks_controller.rb b/app/controllers/training_tasks_controller.rb index 467701e2a..aa716cf5c 100644 --- a/app/controllers/training_tasks_controller.rb +++ b/app/controllers/training_tasks_controller.rb @@ -1,800 +1,800 @@ -# encoding: utf-8 -class TrainingTasksController < ApplicationController - - layout 'base_projects' - before_filter :allow_manager, :only => [] - before_filter :allow_members, :only => [:new, :create] - before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] - before_filter :find_training_task, :only => [:show, :edit, :update, :add_journal, :complete_training_task] - - # before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] - before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete] - # before_filter :authorize, :except => [:index, :show] - # before_filter :authorize, :except => [:new, :index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply, :issue_commits, :commit_for_issue, :issue_commit_delete] - - before_filter :check_for_default_issue_status, :only => [:new, :create] - before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] - accept_rss_auth :index, :show - accept_api_auth :index, :show, :create, :update, :destroy - - rescue_from Query::StatementInvalid, :with => :query_statement_invalid - - helper :journals - helper :projects - include ProjectsHelper - helper :custom_fields - include CustomFieldsHelper - helper :issue_relations - include IssueRelationsHelper - helper :watchers - include WatchersHelper - helper :attachments - include AttachmentsHelper - helper :queries - include QueriesHelper - helper :repositories - include RepositoriesHelper - helper :sort - include SortHelper - include IssuesHelper - helper :timelog - include Redmine::Export::PDF - helper :project_score - include ApplicationHelper - - def issue_commit_delete - commit_id = params[:commit_id].split(",") - issue_commit_ids = params[:issue_commit_ids] - # issue_id存在则为issue详情或者编辑的时候,否则为新建Issue - # 编辑和详情的时候需要在数据库中删除记录,新建的时候在内存中删除 - if params[:issue_id] - commit_issue = CommitIssues.where(:commit_id => commit_id, :issue_id => params[:issue_id], :project_id => @project.id).first - commit_issue.delete if commit_issue - end - @issue_commit_ids = issue_commit_ids - commit_id - end - # over - - def index - # 顶部导航 - @project_menu_type = 11 - @training_tasks = TrainingTask.where(:project_id => @project.id).order('updated_at desc') - @training_tasks_count = @training_tasks.count - @limit = 10 - @is_remote = true - @training_tasks_pages = Paginator.new @training_tasks_count, @limit, params['page'] || 1 - @offset ||= @training_tasks_pages.offset - @training_tasks = paginateHelper @training_tasks, @limit - respond_to do |format| - format.js - format.html - end - rescue ActiveRecord::RecordNotFound - render_404 - end - - def show - # 顶部导航 - @project_menu_type = 11 - # 打开编辑内容 - @is_edit = true unless params[:edit].nil? - @jour_reply = Journal.new - @journals = @training_task.journals.includes(:user, :details).reorder("#{Journal.table_name}.id desc").all - @journals = get_no_children_comments_all @journals - @journals.each_with_index {|j,i| j.indice = i+1} - @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @training_task.project) - @journals.reverse! if User.current.wants_comments_in_reverse_order? - @journal = Journal.new(:journalized => @training_task) - respond_to do |format| - format.html - end - end - - # Add a new issue - # The new issue will be created from an existing one if copy_from parameter is given - def new - # 顶部导航 - @project_menu_type = 11 - respond_to do |format| - format.html { render :action => 'new', :layout => 'base_projects' } - end - end - - # 用户发布新任务 - def create - @training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads])) - @training_task.subject = params[:training_task][:subject] - @training_task.description = params[:training_task][:description] - @training_task.tracker_id = params[:training_task][:tracker_id] - if @training_task.save - respond_to do |format| - format.html { - render_attachment_warning_if_needed(@training_task) - redirect_to training_task_url(@training_task) - } - end - return - else - respond_to do |format| - format.html { render :action => 'new' } - end - end - end - - def complete_training_task - taskId = @training_task.position - end - - def edit - # 修改实例变量的值 - return unless update_issue_from_params - # issue 关联的commit - commit_issues = CommitIssues.where(:issue_id => @issue.id, :project_id => @issue.project_id) - @issue_commit_ids = commit_issues.map{|commit_issue| commit_issue.commit_id} - - respond_to do |format| - format.html {render :layout => 'base_projects' }#added by young - format.xml { } - end - end - - # 用户编辑更改issue - def update - # params[:assigned_to_id] = nil if params[:assigned_to_id].to_i == 0 - # params[:fixed_version_id] = nil if params[:fixed_version_id].to_i == 0 - if params[:issue_detail] - issue = Issue.find(params[:id]) - issue = update_user_issue_detail(issue, params) - @saved = update_user_issue_detail(issue, params) - return - else - # 修改实例变量的值 - return unless update_issue_from_params - @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) - @issue.assigned_to_id = nil if @issue.assigned_to_id == 0 - @issue.fixed_version_id = nil if @issue.fixed_version_id == 0 - saved = false - begin - @saved = @issue.save_issue_with_child_records(params, @time_entry) - rescue ActiveRecord::StaleObjectError - @conflict = true - if params[:last_journal_id] - @conflict_journals = @issue.journals_after(params[:last_journal_id]).all - @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) - end - end - end - if @saved - # 更新commit关联情况 - update_issue_commit params[:commit_ids] - #修改界面增加跟踪者 - watcherlist = @issue.watcher_users - select_users = [] - if params[:issue] - if params[:issue][:watcher_user_ids] - params[:issue][:watcher_user_ids].each do |user_id| - select_users << User.find(user_id) - end - end - end - select_users.each do |user| - if watcherlist.include? user - else - @issue.add_watcher user - end - end - watcherlist.each do |user| - if select_users.include? user - else - @issue.remove_watcher user - end - end - - render_attachment_warning_if_needed(@issue) - reply_id = params[:reference_user_id].to_i - if reply_id > 0 - JournalReply.add_reply(@issue.current_journal.id, reply_id, User.current.id) - end - #flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? 去掉这个notice,因为现在更新都是ajax操作 - respond_to do |format| - format.js - format.html { redirect_to issue_url(@issue.id) } - format.api { render_api_ok } - end - else - respond_to do |format| - - format.js - format.html { render :action => 'edit' } - format.api { render_validation_errors(@issue) } - end - end - end - - def update_user_issue_detail(issue, params) - case params[:type] - when "status" - issue.update_attribute(:status_id, params[:status_id]) - when "assigned" - issue.update_attribute(:assigned_to_id, params[:assigned_to_id]) - when "ratio" - issue.update_attribute(:done_ratio, params[:done_ratio]) - when "prior" - issue.update_attribute(:priority_id, params[:priority_id]) - end - end - - # Updates the issue form when changing the project, status or tracker - # on issue creation/update - def update_form - end - - # Bulk edit/copy a set of issues - def bulk_edit - @issues.sort! - @copy = params[:copy].present? - @notes = params[:notes] - - if User.current.allowed_to?(:move_issues, @projects) - @allowed_projects = Issue.allowed_target_projects_on_move - if params[:issue] - @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} - if @target_project - target_projects = [@target_project] - end - end - end - target_projects ||= @projects - - if @copy - @available_statuses = [IssueStatus.default] - else - @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) - end - @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) - @assignables = target_projects.map(&:assignable_users).reduce(:&) - @trackers = target_projects.map(&:trackers).reduce(:&) - @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) - @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) - if @copy - @attachments_present = @issues.detect {|i| i.attachments.any?}.present? - @subtasks_present = @issues.detect {|i| !i.leaf?}.present? - end - - @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) - render :layout => false if request.xhr? - end - - def bulk_update - @issues.sort! - @copy = params[:copy].present? - attributes = parse_params_for_bulk_issue_attributes(params) - - unsaved_issue_ids = [] - moved_issues = [] - - if @copy && params[:copy_subtasks].present? - # Descendant issues will be copied with the parent task - # Don't copy them twice - @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} - end - - @issues.each do |issue| - issue.reload - if @copy - issue = issue.copy({}, - :attachments => params[:copy_attachments].present?, - :subtasks => params[:copy_subtasks].present? - ) - end - journal = issue.init_journal(User.current, params[:notes]) - issue.safe_attributes = attributes - call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) - if issue.save - moved_issues << issue - else - # Keep unsaved issue ids to display them in flash error - unsaved_issue_ids << issue.id - end - end - set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) - - if params[:follow] - if @issues.size == 1 && moved_issues.size == 1 - redirect_to issue_url(moved_issues.first) - elsif moved_issues.map(&:project).uniq.size == 1 - redirect_to project_issues_url(moved_issues.map(&:project).first) - end - else - redirect_back_or_default _project_issues_path(@project) - end - end - - def destroy - # 增加删除页面类型,如果是个人主页,则返回该主页,项目动态则返回项目动态页眉 - page_classify = params[:page_classify] unless params[:page_classify].nil? - page_id = params[:page_id] unless params[:page_id].nil? - @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f - if @hours > 0 - case params[:todo] - when 'destroy' - # nothing to do - when 'nullify' - TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) - when 'reassign' - reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) - if reassign_to.nil? - flash.now[:error] = l(:error_issue_not_found_in_project) - return - else - TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) - end - else - # display the destroy form if it's a user request - return unless api_request? - end - end - @issues.each do |issue| - begin - issue.reload.destroy - rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists - # nothing to do, issue was already deleted (eg. by a parent) - end - end - respond_to do |format| - if page_classify - format.html { redirect_back_or_default _project_issues_path(@project, page_classify, page_id) } - else - format.html { redirect_back_or_default _project_issues_path(@project) } - end - format.api { render_api_ok } - end - end - - def add_journal - if User.current.logged? - jour = Journal.new - jour.user_id = User.current.id - jour.notes = params[:notes] - jour.journalized = @issue - jour.save_attachments(params[:attachments]) - jour.save - update_user_activity(@issue.class,@issue.id) - update_forge_activity(@issue.class,@issue.id) - @allowed_statuses = @issue.new_statuses_allowed_to(User.current) - @user_activity_id = params[:user_activity_id] - @priorities = IssuePriority.active - - respond_to do |format| - # Issue详情单独处理 - if params[:is_issue_show] - format.js{redirect_to issue_path(@issue)} - else - format.js - end - end - end - end - - def add_journal_in_org - if User.current.logged? - jour = Journal.new - jour.user_id = User.current.id - jour.notes = params[:notes] - jour.journalized = @issue - jour.save - org_activity = OrgActivity.where("org_act_type='Issue' and org_act_id =#{@issue.id}").first - org_activity.updated_at = jour.created_on - org_activity.save - @user_activity_id = params[:user_activity_id] - respond_to do |format| - format.js - end - end - end - - #对某个journ回复,显示回复框 - def reply - @issue = Issue.find(params[:id]) - @jour = Journal.find(params[:journal_id]) - respond_to do |format| - format.js - end - end - - #给issue添加journ。回复内容包含 对某个被回复的journ的内容 - def add_reply - if User.current.logged? - jour = Journal.find(params[:journal_id]) - @issue = Issue.find params[:id] - @project = @issue.project - @allowed_statuses = @issue.new_statuses_allowed_to(User.current) - @priorities = IssuePriority.active - new_jour = Journal.new - new_jour.user_id = User.current.id - new_jour.reply_id = params[:journal_id] - new_jour.parent_id = jour.id - new_jour.notes = params[:content] - new_jour.journalized = @issue - new_jour.save_attachments(params[:attachments]) - # new_jour = @issue.journals.build(:user_id => User.current.id, :reply_id => params[:journal_id], :notes => params[:content], :parent_id => jour.id) - @user_activity_id = params[:user_activity_id] - if new_jour.save - update_user_activity(@issue.class,@issue.id) - update_forge_activity(@issue.class,@issue.id) - respond_to do |format| - if params[:is_issue_show] - format.js{redirect_to issue_path(@issue)} - else - format.js - end - end - end - end - end - - # 需要刷新详情页面,代码同步一致 - # 获取project和issue状态是为了刷新页面 - # 值所以用delete是因为issue和journal在act_as_attachment中是同一个类型 - # 非动态页面直接刷新,动态页面手动刷新 - def delete_journal - @is_project = params[:is_project] - @issue = Issue.find(params[:id]) - begin - forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]) - forge_acts.destroy_all unless forge_acts.empty? - at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]) - at_message.destroy_all unless at_message.empty? - Journal.delete(params[:journal_id]) - rescue Exception => e - puts e - end - @user_activity_id = params[:user_activity_id] - respond_to do |format| - if @user_activity_id - format.js - else - format.js{ redirect_to issue_url(@issue)} - end - end - end - - def statistics - @project = Project.find(params[:id]) - params[:author_id].to_i != 0 ? (@author = User.find(params[:author_id].to_i).show_name) : @author = 0 - case params[:tracker_id].to_i - when 1 - @tracker = "缺陷" - when 2 - @tracker = "功能" - when 3 - @tracker = "支持" - when 4 - @tracker = "任务" - when 5 - @tracker = "周报" - when 0 - @tracker = 0 - end - params[:subject].blank? ? @search = 0 : @search = params[:subject] - params[:assigned_to_id].to_i != 0 ? (@assigned = User.find(params[:assigned_to_id].to_i).show_name) : @assigned = 0 - params[:fixed_version_id].to_i != 0 ? (@version = Version.find(params[:fixed_version_id].to_i).name) : @version = 0 - params[:done_ratio].to_i != -1 ? (@done = params[:done_ratio].to_i) : @done = -1 - case params[:priority_id].to_i - when 1 - @prior = "低" - when 2 - @prior = "正常" - when 3 - @prior = "高" - when 4 - @prior = "紧急" - when 5 - @prior = "立刻" - when 0 - @prior = 0 - end - case params[:status_id].to_i - when 1 - @status = "新增" - when 2 - @status = "正在解决" - when 3 - @status = "已解决" - when 4 - @status = "反馈" - when 5 - @status = "关闭" - when 6 - @status = "拒绝" - when 0 - @status = 0 - end - params[:issue_create_date_start].blank? ? @start_time = 0 : @start_time = params[:issue_create_date_start] - params[:issue_create_date_end].blank? ? @end_time = 0 : @end_time = params[:issue_create_date_end] - @filter_condition = true - @filter_condition = false if (@author == 0 && @tracker == 0 && @search == 0 && @assigned == 0 && @version == 0 && @done == -1 && @prior ==0 && @status == 0 && @start_time ==0 && @end_time) - if @project.nil? - render_404 - end - retrieve_query - sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) - sort_update(@query.sortable_columns) - @query.sort_criteria = sort_criteria.to_a - @project_base_tag = 'base_projects' - if @query.valid? - @tracker_id = params[:tracker_id] - @assign_to_id = params[:assigned_to_id] - @author_id = params[:author_id] - @priority_id = params[:priority_id] - @status_id = params[:status_id] - @subject = params[:subject] - @done_ratio = params[:done_ratio] - @fixed_version_id = params[:fixed_version_id] - @issue_count = @query.issue_count - @test = params[:test] - @project_sort = 'issues.updated_on desc' - if params[:test] != "0" - case @test - when "1" - @project_sort = 'issues.created_on desc' - when "2" - @project_sort = 'issues.created_on asc' - when "3" - @project_sort = 'issues.updated_on desc' - when "4" - @project_sort = 'issues.updated_on asc' - end - end - # 搜索结果 - # SELECT assigned_to_id, count(*) as ac FROM `issues` where project_id = @project.id group by assigned_to_id order by ac desc; - @issues_filter = @query.issues.sort_by{ |i| Issue.where(:project_id => @project.id , :assigned_to_id => i.assigned_to_id).count }.reverse - # @issues_filter = @query.issues(:order => @project_sort) - - # if params[:type] == 1 || params[:type].nil? - # @results = @issues_filter - # elsif params[:type] == "2" - # @results = @issues_filter.collect{|result| result.status_id !=5 } - # elsif params[:type] == "3" - # @results = @issues_filter.collect{|result| result.status_id !=5 } - # end - - #统计 - @results = {} - - #统计total - @alltotal = {} - for i in 0..5 do - @alltotal[i] = 0 - end - - @opentotal = {} - for i in 0..5 do - @opentotal[i] = 0 - end - - @closetotal = {} - for i in 0..5 do - @closetotal[i] = 0 - end - - #开启关闭 - @issue_open_count = 0 - @issue_close_count = 0 - - @issues_filter.each do |issue| - @alltotal[0] = @alltotal[0] + 1 - @alltotal[issue.tracker_id.to_i] = @alltotal[issue.tracker_id.to_i] + 1 - user_id = issue.assigned_to_id - if issue.assigned_to_id.nil? - user_id = 0 - end - - if !@results[user_id].nil? - @results[user_id][0] = @results[user_id][0] + 1 - @results[user_id][issue.tracker_id.to_i] = @results[user_id][issue.tracker_id.to_i] + 1 - - if issue.status_id.to_i == 5 - @issue_close_count = @issue_close_count + 1 - @results[user_id][12] = @results[user_id][12]+1 - @results[user_id][12+issue.tracker_id.to_i] = @results[user_id][12+issue.tracker_id.to_i]+1 - - @closetotal[0] = @closetotal[0] + 1 - @closetotal[issue.tracker_id.to_i] = @closetotal[issue.tracker_id.to_i] + 1 - else - @issue_open_count = @issue_open_count + 1 - @results[user_id][6] = @results[user_id][6]+1 - @results[user_id][6+issue.tracker_id.to_i] = @results[user_id][6+issue.tracker_id.to_i]+1 - - @opentotal[0] = @opentotal[0] + 1 - @opentotal[issue.tracker_id.to_i] = @opentotal[issue.tracker_id.to_i] + 1 - end - else - - @results[user_id] = {} - - tmpuser = User.find(user_id) - - @results[user_id][:name] = tmpuser.nil? ? "" : tmpuser.show_name - #所有的 - @results[user_id][0] = 1 - for i in 1..17 do - @results[user_id][i] = 0 - end - # @results[user_id][1] = 0 - # @results[user_id][2] = 0 - # @results[user_id][3] = 0 - # @results[user_id][4] = 0 - # @results[user_id][5] = 0 - @results[user_id][issue.tracker_id.to_i] = 1 - - #开启的 status_id = 12346 - # @results[user_id][6] = 0 - # @results[user_id][7] = 0 - # @results[user_id][8] = 0 - # @results[user_id][9] = 0 - # @results[user_id][10] = 0 - # @results[user_id][11] = 0 - - #关闭的 status_id = 5 - # @results[user_id][12] = 0 - # @results[user_id][13] = 0 - # @results[user_id][14] = 0 - # @results[user_id][15] = 0 - # @results[user_id][16] = 0 - # @results[user_id][17] = 0 - - if issue.status_id.to_i == 5 - @results[user_id][12] = 1 - @results[user_id][12+issue.tracker_id.to_i] = 1 - @issue_close_count = @issue_close_count+1 - - @closetotal[0] = @closetotal[0] + 1 - @closetotal[issue.tracker_id.to_i] = @closetotal[issue.tracker_id.to_i] + 1 - else - @issue_open_count = @issue_open_count+1 - @results[user_id][6] = 1 - @results[user_id][6+issue.tracker_id.to_i] = 1 - - @opentotal[0] = @opentotal[0] + 1 - @opentotal[issue.tracker_id.to_i] = @opentotal[issue.tracker_id.to_i] + 1 - end - - end - end - - respond_to do |format| - format.js - end - - else - render_404 - end - end - - private - - def find_project - project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) - @project = Project.find(project_id) - rescue ActiveRecord::RecordNotFound - render_404 - end - - def allow_members - if !(User.current.member_of?(@project) || User.current.admin?) - render_403 - end - end - - def retrieve_previous_and_next_issue_ids - retrieve_query_from_session - if @query - sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) - sort_update(@query.sortable_columns, 'issues_index_sort') - limit = 500 - issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) - if (idx = issue_ids.index(@issue.id)) && idx < limit - if issue_ids.size < 500 - @issue_position = idx + 1 - @issue_count = issue_ids.size - end - @prev_issue_id = issue_ids[idx - 1] if idx > 0 - @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) - end - end - end - - # Used by #edit and #update to set some common instance variables - # from the params - # TODO: Refactor, not everything in here is needed by #edit - def update_issue_from_params - @edit_allowed = User.current.allowed_to?(:edit_issues, @project) - @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) - @time_entry.attributes = params[:time_entry] - - # 更新issue状态时,journal表产生记录,返回@current_journal - @issue.init_journal(User.current) - issue_attributes = params[:issue] - if issue_attributes && params[:conflict_resolution] - case params[:conflict_resolution] - when 'overwrite' - issue_attributes = issue_attributes.dup - issue_attributes.delete(:lock_version) - when 'add_notes' - issue_attributes = issue_attributes.slice(:notes) - when 'cancel' - redirect_to issue_url(@issue) - return false - end - end - - if params[:action] == "update" - senduser = User.find(params[:issue][:assigned_to_id]) - if senduser.id != User.current.id && @issue.assigned_to_id != params[:issue][:assigned_to_id].to_i - issue_id = @issue.id - issue_title = params[:issue][:subject] - priority_id = params[:issue][:priority_id] - ps = ProjectsService.new - ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id - end - end - - @issue.safe_attributes = issue_attributes - @priorities = IssuePriority.active - @allowed_statuses = @issue.new_statuses_allowed_to(User.current) - true - end - - # TODO: Refactor, lots of extra code in here - # TODO: Changing tracker on an existing issue should not trigger this - def build_new_task_from_params - if params[:id].blank? - @training_task = TrainingTask.new - @training_task.project = @project - else - @training_task = @project.training_tasks.visible.find(params[:id]) - end - - @training_task.project = @project - @training_task.author ||= User.current - # Tracker must be set before custom field values - @training_task.tracker ||= @project.trackers.find((params[:training_task] && params[:training_task][:tracker_id]) || params[:tracker_id] || :first) - if @training_task.tracker.nil? - render_error l(:error_no_tracker_in_project) - return false - end - end - - def check_for_default_issue_status - if IssueStatus.default.nil? - render_error l(:error_no_default_issue_status) - return false - end - end - - def parse_params_for_bulk_issue_attributes(params) - attributes = (params[:issue] || {}).reject {|k,v| v.blank?} - attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} - if custom = attributes[:custom_field_values] - custom.reject! {|k,v| v.blank?} - custom.keys.each do |k| - if custom[k].is_a?(Array) - custom[k] << '' if custom[k].delete('__none__') - else - custom[k] = '' if custom[k] == '__none__' - end - end - end - attributes - end - - # Find the issue whose id is the :id parameter - # Raises a Unauthorized exception if the issue is not visible - def find_training_task - @training_task = TrainingTask.find(params[:id]) - @project = @training_task.project - rescue ActiveRecord::RecordNotFound - render_404 - end -end +# encoding: utf-8 +class TrainingTasksController < ApplicationController + + layout 'base_projects' + before_filter :allow_manager, :only => [] + before_filter :allow_members, :only => [:new, :create] + before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] + before_filter :find_training_task, :only => [:show, :edit, :update, :add_journal, :complete_training_task] + + # before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] + before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete] + # before_filter :authorize, :except => [:index, :show] + # before_filter :authorize, :except => [:new, :index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply, :issue_commits, :commit_for_issue, :issue_commit_delete] + + before_filter :check_for_default_issue_status, :only => [:new, :create] + before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] + accept_rss_auth :index, :show + accept_api_auth :index, :show, :create, :update, :destroy + + rescue_from Query::StatementInvalid, :with => :query_statement_invalid + + helper :journals + helper :projects + include ProjectsHelper + helper :custom_fields + include CustomFieldsHelper + helper :issue_relations + include IssueRelationsHelper + helper :watchers + include WatchersHelper + helper :attachments + include AttachmentsHelper + helper :queries + include QueriesHelper + helper :repositories + include RepositoriesHelper + helper :sort + include SortHelper + include IssuesHelper + helper :timelog + include Redmine::Export::PDF + helper :project_score + include ApplicationHelper + + def issue_commit_delete + commit_id = params[:commit_id].split(",") + issue_commit_ids = params[:issue_commit_ids] + # issue_id存在则为issue详情或者编辑的时候,否则为新建Issue + # 编辑和详情的时候需要在数据库中删除记录,新建的时候在内存中删除 + if params[:issue_id] + commit_issue = CommitIssues.where(:commit_id => commit_id, :issue_id => params[:issue_id], :project_id => @project.id).first + commit_issue.delete if commit_issue + end + @issue_commit_ids = issue_commit_ids - commit_id + end + # over + + def index + # 顶部导航 + @project_menu_type = 11 + @training_tasks = TrainingTask.where(:project_id => @project.id).order('updated_at desc') + @training_tasks_count = @training_tasks.count + @limit = 10 + @is_remote = true + @training_tasks_pages = Paginator.new @training_tasks_count, @limit, params['page'] || 1 + @offset ||= @training_tasks_pages.offset + @training_tasks = paginateHelper @training_tasks, @limit + respond_to do |format| + format.js + format.html + end + rescue ActiveRecord::RecordNotFound + render_404 + end + + def show + # 顶部导航 + @project_menu_type = 11 + # 打开编辑内容 + @is_edit = true unless params[:edit].nil? + @jour_reply = Journal.new + @journals = @training_task.journals.includes(:user, :details).reorder("#{Journal.table_name}.id desc").all + @journals = get_no_children_comments_all @journals + @journals.each_with_index {|j,i| j.indice = i+1} + @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @training_task.project) + @journals.reverse! if User.current.wants_comments_in_reverse_order? + @journal = Journal.new(:journalized => @training_task) + respond_to do |format| + format.html + end + end + + # Add a new issue + # The new issue will be created from an existing one if copy_from parameter is given + def new + # 顶部导航 + @project_menu_type = 11 + respond_to do |format| + format.html { render :action => 'new', :layout => 'base_projects' } + end + end + + # 用户发布新任务 + def create + @training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads])) + @training_task.subject = params[:training_task][:subject] + @training_task.description = params[:training_task][:description] + @training_task.tracker_id = params[:training_task][:tracker_id] + if @training_task.save + respond_to do |format| + format.html { + render_attachment_warning_if_needed(@training_task) + redirect_to training_task_url(@training_task) + } + end + return + else + respond_to do |format| + format.html { render :action => 'new' } + end + end + end + + def complete_training_task + taskId = @training_task.position + end + + def edit + # 修改实例变量的值 + return unless update_issue_from_params + # issue 关联的commit + commit_issues = CommitIssues.where(:issue_id => @issue.id, :project_id => @issue.project_id) + @issue_commit_ids = commit_issues.map{|commit_issue| commit_issue.commit_id} + + respond_to do |format| + format.html {render :layout => 'base_projects' }#added by young + format.xml { } + end + end + + # 用户编辑更改issue + def update + # params[:assigned_to_id] = nil if params[:assigned_to_id].to_i == 0 + # params[:fixed_version_id] = nil if params[:fixed_version_id].to_i == 0 + if params[:issue_detail] + issue = Issue.find(params[:id]) + issue = update_user_issue_detail(issue, params) + @saved = update_user_issue_detail(issue, params) + return + else + # 修改实例变量的值 + return unless update_issue_from_params + @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) + @issue.assigned_to_id = nil if @issue.assigned_to_id == 0 + @issue.fixed_version_id = nil if @issue.fixed_version_id == 0 + saved = false + begin + @saved = @issue.save_issue_with_child_records(params, @time_entry) + rescue ActiveRecord::StaleObjectError + @conflict = true + if params[:last_journal_id] + @conflict_journals = @issue.journals_after(params[:last_journal_id]).all + @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) + end + end + end + if @saved + # 更新commit关联情况 + update_issue_commit params[:commit_ids] + #修改界面增加跟踪者 + watcherlist = @issue.watcher_users + select_users = [] + if params[:issue] + if params[:issue][:watcher_user_ids] + params[:issue][:watcher_user_ids].each do |user_id| + select_users << User.find(user_id) + end + end + end + select_users.each do |user| + if watcherlist.include? user + else + @issue.add_watcher user + end + end + watcherlist.each do |user| + if select_users.include? user + else + @issue.remove_watcher user + end + end + + render_attachment_warning_if_needed(@issue) + reply_id = params[:reference_user_id].to_i + if reply_id > 0 + JournalReply.add_reply(@issue.current_journal.id, reply_id, User.current.id) + end + #flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? 去掉这个notice,因为现在更新都是ajax操作 + respond_to do |format| + format.js + format.html { redirect_to issue_url(@issue.id) } + format.api { render_api_ok } + end + else + respond_to do |format| + + format.js + format.html { render :action => 'edit' } + format.api { render_validation_errors(@issue) } + end + end + end + + def update_user_issue_detail(issue, params) + case params[:type] + when "status" + issue.update_attribute(:status_id, params[:status_id]) + when "assigned" + issue.update_attribute(:assigned_to_id, params[:assigned_to_id]) + when "ratio" + issue.update_attribute(:done_ratio, params[:done_ratio]) + when "prior" + issue.update_attribute(:priority_id, params[:priority_id]) + end + end + + # Updates the issue form when changing the project, status or tracker + # on issue creation/update + def update_form + end + + # Bulk edit/copy a set of issues + def bulk_edit + @issues.sort! + @copy = params[:copy].present? + @notes = params[:notes] + + if User.current.allowed_to?(:move_issues, @projects) + @allowed_projects = Issue.allowed_target_projects_on_move + if params[:issue] + @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} + if @target_project + target_projects = [@target_project] + end + end + end + target_projects ||= @projects + + if @copy + @available_statuses = [IssueStatus.default] + else + @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) + end + @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) + @assignables = target_projects.map(&:assignable_users).reduce(:&) + @trackers = target_projects.map(&:trackers).reduce(:&) + @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) + @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) + if @copy + @attachments_present = @issues.detect {|i| i.attachments.any?}.present? + @subtasks_present = @issues.detect {|i| !i.leaf?}.present? + end + + @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) + render :layout => false if request.xhr? + end + + def bulk_update + @issues.sort! + @copy = params[:copy].present? + attributes = parse_params_for_bulk_issue_attributes(params) + + unsaved_issue_ids = [] + moved_issues = [] + + if @copy && params[:copy_subtasks].present? + # Descendant issues will be copied with the parent task + # Don't copy them twice + @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} + end + + @issues.each do |issue| + issue.reload + if @copy + issue = issue.copy({}, + :attachments => params[:copy_attachments].present?, + :subtasks => params[:copy_subtasks].present? + ) + end + journal = issue.init_journal(User.current, params[:notes]) + issue.safe_attributes = attributes + call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) + if issue.save + moved_issues << issue + else + # Keep unsaved issue ids to display them in flash error + unsaved_issue_ids << issue.id + end + end + set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) + + if params[:follow] + if @issues.size == 1 && moved_issues.size == 1 + redirect_to issue_url(moved_issues.first) + elsif moved_issues.map(&:project).uniq.size == 1 + redirect_to project_issues_url(moved_issues.map(&:project).first) + end + else + redirect_back_or_default _project_issues_path(@project) + end + end + + def destroy + # 增加删除页面类型,如果是个人主页,则返回该主页,项目动态则返回项目动态页眉 + page_classify = params[:page_classify] unless params[:page_classify].nil? + page_id = params[:page_id] unless params[:page_id].nil? + @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f + if @hours > 0 + case params[:todo] + when 'destroy' + # nothing to do + when 'nullify' + TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) + when 'reassign' + reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) + if reassign_to.nil? + flash.now[:error] = l(:error_issue_not_found_in_project) + return + else + TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) + end + else + # display the destroy form if it's a user request + return unless api_request? + end + end + @issues.each do |issue| + begin + issue.reload.destroy + rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists + # nothing to do, issue was already deleted (eg. by a parent) + end + end + respond_to do |format| + if page_classify + format.html { redirect_back_or_default _project_issues_path(@project, page_classify, page_id) } + else + format.html { redirect_back_or_default _project_issues_path(@project) } + end + format.api { render_api_ok } + end + end + + def add_journal + if User.current.logged? + jour = Journal.new + jour.user_id = User.current.id + jour.notes = params[:notes] + jour.journalized = @issue + jour.save_attachments(params[:attachments]) + jour.save + update_user_activity(@issue.class,@issue.id) + update_forge_activity(@issue.class,@issue.id) + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) + @user_activity_id = params[:user_activity_id] + @priorities = IssuePriority.active + + respond_to do |format| + # Issue详情单独处理 + if params[:is_issue_show] + format.js{redirect_to issue_path(@issue)} + else + format.js + end + end + end + end + + def add_journal_in_org + if User.current.logged? + jour = Journal.new + jour.user_id = User.current.id + jour.notes = params[:notes] + jour.journalized = @issue + jour.save + org_activity = OrgActivity.where("org_act_type='Issue' and org_act_id =#{@issue.id}").first + org_activity.updated_at = jour.created_on + org_activity.save + @user_activity_id = params[:user_activity_id] + respond_to do |format| + format.js + end + end + end + + #对某个journ回复,显示回复框 + def reply + @issue = Issue.find(params[:id]) + @jour = Journal.find(params[:journal_id]) + respond_to do |format| + format.js + end + end + + #给issue添加journ。回复内容包含 对某个被回复的journ的内容 + def add_reply + if User.current.logged? + jour = Journal.find(params[:journal_id]) + @issue = Issue.find params[:id] + @project = @issue.project + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) + @priorities = IssuePriority.active + new_jour = Journal.new + new_jour.user_id = User.current.id + new_jour.reply_id = params[:journal_id] + new_jour.parent_id = jour.id + new_jour.notes = params[:content] + new_jour.journalized = @issue + new_jour.save_attachments(params[:attachments]) + # new_jour = @issue.journals.build(:user_id => User.current.id, :reply_id => params[:journal_id], :notes => params[:content], :parent_id => jour.id) + @user_activity_id = params[:user_activity_id] + if new_jour.save + update_user_activity(@issue.class,@issue.id) + update_forge_activity(@issue.class,@issue.id) + respond_to do |format| + if params[:is_issue_show] + format.js{redirect_to issue_path(@issue)} + else + format.js + end + end + end + end + end + + # 需要刷新详情页面,代码同步一致 + # 获取project和issue状态是为了刷新页面 + # 值所以用delete是因为issue和journal在act_as_attachment中是同一个类型 + # 非动态页面直接刷新,动态页面手动刷新 + def delete_journal + @is_project = params[:is_project] + @issue = Issue.find(params[:id]) + begin + forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]) + forge_acts.destroy_all unless forge_acts.empty? + at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]) + at_message.destroy_all unless at_message.empty? + Journal.delete(params[:journal_id]) + rescue Exception => e + puts e + end + @user_activity_id = params[:user_activity_id] + respond_to do |format| + if @user_activity_id + format.js + else + format.js{ redirect_to issue_url(@issue)} + end + end + end + + def statistics + @project = Project.find(params[:id]) + params[:author_id].to_i != 0 ? (@author = User.find(params[:author_id].to_i).show_name) : @author = 0 + case params[:tracker_id].to_i + when 1 + @tracker = "缺陷" + when 2 + @tracker = "功能" + when 3 + @tracker = "支持" + when 4 + @tracker = "任务" + when 5 + @tracker = "周报" + when 0 + @tracker = 0 + end + params[:subject].blank? ? @search = 0 : @search = params[:subject] + params[:assigned_to_id].to_i != 0 ? (@assigned = User.find(params[:assigned_to_id].to_i).show_name) : @assigned = 0 + params[:fixed_version_id].to_i != 0 ? (@version = Version.find(params[:fixed_version_id].to_i).name) : @version = 0 + params[:done_ratio].to_i != -1 ? (@done = params[:done_ratio].to_i) : @done = -1 + case params[:priority_id].to_i + when 1 + @prior = "低" + when 2 + @prior = "正常" + when 3 + @prior = "高" + when 4 + @prior = "紧急" + when 5 + @prior = "立刻" + when 0 + @prior = 0 + end + case params[:status_id].to_i + when 1 + @status = "新增" + when 2 + @status = "正在解决" + when 3 + @status = "已解决" + when 4 + @status = "反馈" + when 5 + @status = "关闭" + when 6 + @status = "拒绝" + when 0 + @status = 0 + end + params[:issue_create_date_start].blank? ? @start_time = 0 : @start_time = params[:issue_create_date_start] + params[:issue_create_date_end].blank? ? @end_time = 0 : @end_time = params[:issue_create_date_end] + @filter_condition = true + @filter_condition = false if (@author == 0 && @tracker == 0 && @search == 0 && @assigned == 0 && @version == 0 && @done == -1 && @prior ==0 && @status == 0 && @start_time ==0 && @end_time) + if @project.nil? + render_404 + end + retrieve_query + sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) + sort_update(@query.sortable_columns) + @query.sort_criteria = sort_criteria.to_a + @project_base_tag = 'base_projects' + if @query.valid? + @tracker_id = params[:tracker_id] + @assign_to_id = params[:assigned_to_id] + @author_id = params[:author_id] + @priority_id = params[:priority_id] + @status_id = params[:status_id] + @subject = params[:subject] + @done_ratio = params[:done_ratio] + @fixed_version_id = params[:fixed_version_id] + @issue_count = @query.issue_count + @test = params[:test] + @project_sort = 'issues.updated_on desc' + if params[:test] != "0" + case @test + when "1" + @project_sort = 'issues.created_on desc' + when "2" + @project_sort = 'issues.created_on asc' + when "3" + @project_sort = 'issues.updated_on desc' + when "4" + @project_sort = 'issues.updated_on asc' + end + end + # 搜索结果 + # SELECT assigned_to_id, count(*) as ac FROM `issues` where project_id = @project.id group by assigned_to_id order by ac desc; + @issues_filter = @query.issues.sort_by{ |i| Issue.where(:project_id => @project.id , :assigned_to_id => i.assigned_to_id).count }.reverse + # @issues_filter = @query.issues(:order => @project_sort) + + # if params[:type] == 1 || params[:type].nil? + # @results = @issues_filter + # elsif params[:type] == "2" + # @results = @issues_filter.collect{|result| result.status_id !=5 } + # elsif params[:type] == "3" + # @results = @issues_filter.collect{|result| result.status_id !=5 } + # end + + #统计 + @results = {} + + #统计total + @alltotal = {} + for i in 0..5 do + @alltotal[i] = 0 + end + + @opentotal = {} + for i in 0..5 do + @opentotal[i] = 0 + end + + @closetotal = {} + for i in 0..5 do + @closetotal[i] = 0 + end + + #开启关闭 + @issue_open_count = 0 + @issue_close_count = 0 + + @issues_filter.each do |issue| + @alltotal[0] = @alltotal[0] + 1 + @alltotal[issue.tracker_id.to_i] = @alltotal[issue.tracker_id.to_i] + 1 + user_id = issue.assigned_to_id + if issue.assigned_to_id.nil? + user_id = 0 + end + + if !@results[user_id].nil? + @results[user_id][0] = @results[user_id][0] + 1 + @results[user_id][issue.tracker_id.to_i] = @results[user_id][issue.tracker_id.to_i] + 1 + + if issue.status_id.to_i == 5 + @issue_close_count = @issue_close_count + 1 + @results[user_id][12] = @results[user_id][12]+1 + @results[user_id][12+issue.tracker_id.to_i] = @results[user_id][12+issue.tracker_id.to_i]+1 + + @closetotal[0] = @closetotal[0] + 1 + @closetotal[issue.tracker_id.to_i] = @closetotal[issue.tracker_id.to_i] + 1 + else + @issue_open_count = @issue_open_count + 1 + @results[user_id][6] = @results[user_id][6]+1 + @results[user_id][6+issue.tracker_id.to_i] = @results[user_id][6+issue.tracker_id.to_i]+1 + + @opentotal[0] = @opentotal[0] + 1 + @opentotal[issue.tracker_id.to_i] = @opentotal[issue.tracker_id.to_i] + 1 + end + else + + @results[user_id] = {} + + tmpuser = User.find(user_id) + + @results[user_id][:name] = tmpuser.nil? ? "" : tmpuser.show_name + #所有的 + @results[user_id][0] = 1 + for i in 1..17 do + @results[user_id][i] = 0 + end + # @results[user_id][1] = 0 + # @results[user_id][2] = 0 + # @results[user_id][3] = 0 + # @results[user_id][4] = 0 + # @results[user_id][5] = 0 + @results[user_id][issue.tracker_id.to_i] = 1 + + #开启的 status_id = 12346 + # @results[user_id][6] = 0 + # @results[user_id][7] = 0 + # @results[user_id][8] = 0 + # @results[user_id][9] = 0 + # @results[user_id][10] = 0 + # @results[user_id][11] = 0 + + #关闭的 status_id = 5 + # @results[user_id][12] = 0 + # @results[user_id][13] = 0 + # @results[user_id][14] = 0 + # @results[user_id][15] = 0 + # @results[user_id][16] = 0 + # @results[user_id][17] = 0 + + if issue.status_id.to_i == 5 + @results[user_id][12] = 1 + @results[user_id][12+issue.tracker_id.to_i] = 1 + @issue_close_count = @issue_close_count+1 + + @closetotal[0] = @closetotal[0] + 1 + @closetotal[issue.tracker_id.to_i] = @closetotal[issue.tracker_id.to_i] + 1 + else + @issue_open_count = @issue_open_count+1 + @results[user_id][6] = 1 + @results[user_id][6+issue.tracker_id.to_i] = 1 + + @opentotal[0] = @opentotal[0] + 1 + @opentotal[issue.tracker_id.to_i] = @opentotal[issue.tracker_id.to_i] + 1 + end + + end + end + + respond_to do |format| + format.js + end + + else + render_404 + end + end + + private + + def find_project + project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) + @project = Project.find(project_id) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def allow_members + if !(User.current.member_of?(@project) || User.current.admin?) + render_403 + end + end + + def retrieve_previous_and_next_issue_ids + retrieve_query_from_session + if @query + sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) + sort_update(@query.sortable_columns, 'issues_index_sort') + limit = 500 + issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) + if (idx = issue_ids.index(@issue.id)) && idx < limit + if issue_ids.size < 500 + @issue_position = idx + 1 + @issue_count = issue_ids.size + end + @prev_issue_id = issue_ids[idx - 1] if idx > 0 + @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) + end + end + end + + # Used by #edit and #update to set some common instance variables + # from the params + # TODO: Refactor, not everything in here is needed by #edit + def update_issue_from_params + @edit_allowed = User.current.allowed_to?(:edit_issues, @project) + @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) + @time_entry.attributes = params[:time_entry] + + # 更新issue状态时,journal表产生记录,返回@current_journal + @issue.init_journal(User.current) + issue_attributes = params[:issue] + if issue_attributes && params[:conflict_resolution] + case params[:conflict_resolution] + when 'overwrite' + issue_attributes = issue_attributes.dup + issue_attributes.delete(:lock_version) + when 'add_notes' + issue_attributes = issue_attributes.slice(:notes) + when 'cancel' + redirect_to issue_url(@issue) + return false + end + end + + if params[:action] == "update" + senduser = User.find(params[:issue][:assigned_to_id]) + if senduser.id != User.current.id && @issue.assigned_to_id != params[:issue][:assigned_to_id].to_i + issue_id = @issue.id + issue_title = params[:issue][:subject] + priority_id = params[:issue][:priority_id] + ps = ProjectsService.new + ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id + end + end + + @issue.safe_attributes = issue_attributes + @priorities = IssuePriority.active + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) + true + end + + # TODO: Refactor, lots of extra code in here + # TODO: Changing tracker on an existing issue should not trigger this + def build_new_task_from_params + if params[:id].blank? + @training_task = TrainingTask.new + @training_task.project = @project + else + @training_task = @project.training_tasks.visible.find(params[:id]) + end + + @training_task.project = @project + @training_task.author ||= User.current + # Tracker must be set before custom field values + @training_task.tracker ||= @project.trackers.find((params[:training_task] && params[:training_task][:tracker_id]) || params[:tracker_id] || :first) + if @training_task.tracker.nil? + render_error l(:error_no_tracker_in_project) + return false + end + end + + def check_for_default_issue_status + if IssueStatus.default.nil? + render_error l(:error_no_default_issue_status) + return false + end + end + + def parse_params_for_bulk_issue_attributes(params) + attributes = (params[:issue] || {}).reject {|k,v| v.blank?} + attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} + if custom = attributes[:custom_field_values] + custom.reject! {|k,v| v.blank?} + custom.keys.each do |k| + if custom[k].is_a?(Array) + custom[k] << '' if custom[k].delete('__none__') + else + custom[k] = '' if custom[k] == '__none__' + end + end + end + attributes + end + + # Find the issue whose id is the :id parameter + # Raises a Unauthorized exception if the issue is not visible + def find_training_task + @training_task = TrainingTask.find(params[:id]) + @project = @training_task.project + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7315d7630..f479432ca 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1036,6 +1036,32 @@ module ApplicationHelper return @result end + # 更新各类消息为已读 + def update_messsages_to_viewed(message_type, forge_message_id) + if(message_type == "CourseMessage") + query = CourseMessage.where(:course_message_type => ["JoinCourse", "RemoveFromCourse"], + :user_id => User.current, + :course_id => forge_message_id, + :viewed => false) + elsif(message_type == "ForgeMessage") + query = ForgeMessage.where(:forge_message_type => ["ProjectInvite", "JoinProject", "RemoveFromProject"], + :user_id => User.current, + :project_id => forge_message_id, + :viewed => false) + elsif(message_type == "ContestMessage") + query = ContestMessage.where(:contest_message_type => ["ContestRequestDealResult", "JoinContest", "RemoveFromContest"], + :user_id => User.current, + :contest_id => forge_message_id, + :viewed => false) + elsif(message_type == "BlogMessage") + query = BlogMessage.where(:blog_message_type => "BlogComment", + :user_id => User.current, + :blog_id => forge_message_id, + :viewed => false) + end + query.update_all(:viewed => true) unless query.blank? + end + def show_attachment_tip container_id, container_type atts = Attachment.where(:container_id => container_id, :container_type => container_type, :is_public => 0) atts.count > 0 ? true :false diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index e97d32523..559160d60 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -257,6 +257,14 @@ module CoursesHelper count.to_s << '+' end + def searchTeacherAndAssistantNoManager course + members = [] + course.members.includes(:user).each do |m| + members << m if m && m.user && m.user != course.teacher && m.user.has_teacher_role(course) + end + members + end + # ===================================================================================== # return people list def searchTeacherAndAssistant project @@ -928,5 +936,11 @@ module CoursesHelper result = !m_roles.blank? result end + + #获取该班级下已关联项目的分组作业 + def select_group_homeworks course + student_work_pros = course.student_work_projects.where("project_id != -1 && project_id != 0") + homeworks = @course.homework_commons.where(:id => student_work_pros.map(&:homework_common_id)) + end end diff --git a/app/helpers/training_tasks_helper.rb b/app/helpers/training_tasks_helper.rb index 27569b973..4096b1cb0 100644 --- a/app/helpers/training_tasks_helper.rb +++ b/app/helpers/training_tasks_helper.rb @@ -1,2 +1,2 @@ -module TrainingTasksHelper -end +module TrainingTasksHelper +end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index ec0711bc4..d0c067437 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -1,100 +1,100 @@ -class PraiseTread < ActiveRecord::Base - attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread - belongs_to :user - belongs_to :praise_tread_object, polymorphic: true - #after_create :be_user_score - #after_destroy :down_user_score - include UserScoreHelper - def self.find_object_by_type_and_id(type,id) - @obj = nil - case type - when 'User' - @obj = User.find_by_id(id) - when 'Issue' - @obj = Issue.find_by_id(id) - when 'TrainingTask' - @obj = TrainingTask.find_by_id(id) - when 'Project' - @obj = Project.find_by_id(id) - when 'Bid' - @obj = Bid.find_by_id(id) - when 'Contest' - @obj = Contest.find_by_id(id) - when 'Memo' - @obj = Memo.find_by_id(id) - when 'Message' - @obj = Message.find_by_id(id) - end - return @obj - end - - # 获取裁定对象为Message时Message所属的项目或课程 - def project - project = nil - if self.praise_tread_object_type == 'Message' || self.praise_tread_object_type == 'Issues' - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - project = obj.project - end - project - end - - #更新用户分数 - by zjc - def be_user_score - #踩贴吧或讨论区帖子 - if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(self.user,1) - update_tread(target_user,1) - unless self.project.nil? - update_tread(self.user,2,self.project) - update_tread(target_user,2,self.project) - end - #顶贴吧或讨论区帖子 - elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) - update_praise(target_user,1) - unless self.project.nil? - update_praise(target_user,2,self.project) - end - #更新用户等级 - UserLevels.update_user_level(target_user) - end - end - - def down_user_score - #踩贴吧或讨论区帖子 - if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - #UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(self.user,1) - update_tread(target_user,1) - unless self.project.nil? - update_tread(self.user,2,self.project) - update_tread(target_user,2,self.project) - end - #顶贴吧或讨论区帖子 - elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - #UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) - update_praise(target_user,1) - unless self.project.nil? - update_praise(target_user,2,self.project) - end - #更新用户等级 - UserLevels.update_user_level(target_user) - end - end - - def self.praised(activity) - self.where(praise_tread_object_id: activity.id, - praise_tread_object_type: activity.class.to_s, - user_id: User.current.id).empty? - end - -end +class PraiseTread < ActiveRecord::Base + attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread + belongs_to :user + belongs_to :praise_tread_object, polymorphic: true + #after_create :be_user_score + #after_destroy :down_user_score + include UserScoreHelper + def self.find_object_by_type_and_id(type,id) + @obj = nil + case type + when 'User' + @obj = User.find_by_id(id) + when 'Issue' + @obj = Issue.find_by_id(id) + when 'TrainingTask' + @obj = TrainingTask.find_by_id(id) + when 'Project' + @obj = Project.find_by_id(id) + when 'Bid' + @obj = Bid.find_by_id(id) + when 'Contest' + @obj = Contest.find_by_id(id) + when 'Memo' + @obj = Memo.find_by_id(id) + when 'Message' + @obj = Message.find_by_id(id) + end + return @obj + end + + # 获取裁定对象为Message时Message所属的项目或课程 + def project + project = nil + if self.praise_tread_object_type == 'Message' || self.praise_tread_object_type == 'Issues' + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + project = obj.project + end + project + end + + #更新用户分数 - by zjc + def be_user_score + #踩贴吧或讨论区帖子 + if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) + update_tread(self.user,1) + update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end + #顶贴吧或讨论区帖子 + elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) + update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end + #更新用户等级 + UserLevels.update_user_level(target_user) + end + end + + def down_user_score + #踩贴吧或讨论区帖子 + if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + #UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) + update_tread(self.user,1) + update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end + #顶贴吧或讨论区帖子 + elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + #UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) + update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end + #更新用户等级 + UserLevels.update_user_level(target_user) + end + end + + def self.praised(activity) + self.where(praise_tread_object_id: activity.id, + praise_tread_object_type: activity.class.to_s, + user_id: User.current.id).empty? + end + +end diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index 5ef2922b0..f3e0cb530 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -31,7 +31,7 @@ class StudentsForCourse < ActiveRecord::Base #加入班级时创建已发布作业的作品 def create_student_works course = self.course - course.homework_commons.each do |hw| + course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").each do |hw| if hw.homework_type != 3 && hw.student_works.where("user_id = #{self.student_id}").count == 0 hw.student_works << StudentWork.new(:user_id => self.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0) end diff --git a/app/models/training_task.rb b/app/models/training_task.rb index 54fa72648..e518b1b4c 100644 --- a/app/models/training_task.rb +++ b/app/models/training_task.rb @@ -1,20 +1,20 @@ -class TrainingTask < ActiveRecord::Base - attr_accessible :description, :project_id, :subject, :tracker_id - belongs_to :project,:touch=> true - belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' - belongs_to :tracker - has_many :journals, :as => :journalized, :dependent => :destroy - has_many :visible_journals, - :class_name => 'Journal', - :as => :journalized, - :conditions => Proc.new { - ["(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(User.current, :view_private_notes)}))", false] - }, - :readonly => true - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy - has_one :praise_tread_cache, as: :object, dependent: :destroy - acts_as_attachable - - validates_presence_of :subject, :author - validates_length_of :subject, :maximum => 255 -end +class TrainingTask < ActiveRecord::Base + attr_accessible :description, :project_id, :subject, :tracker_id + belongs_to :project,:touch=> true + belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :tracker + has_many :journals, :as => :journalized, :dependent => :destroy + has_many :visible_journals, + :class_name => 'Journal', + :as => :journalized, + :conditions => Proc.new { + ["(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(User.current, :view_private_notes)}))", false] + }, + :readonly => true + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + acts_as_attachable + + validates_presence_of :subject, :author + validates_length_of :subject, :maximum => 255 +end diff --git a/app/views/cooperation/index.html.erb b/app/views/cooperation/index.html.erb index c3a102788..2a3a7a430 100644 --- a/app/views/cooperation/index.html.erb +++ b/app/views/cooperation/index.html.erb @@ -34,6 +34,12 @@
没有数据可以显示!
+ <% end %>没有数据可以显示!
+没有数据可以显示!
+- 学期:<%= current_time_and_term @course %> +
教师:<%= course_teacher_link teacher_num %> 学生:<%= course_student_link student_num %> -
-- 单位:<%= get_occupation_from_user(@course.teacher).blank? ? '无' : get_occupation_from_user(@course.teacher) %> + <%= current_time_and_term @course %> + <%= get_occupation_from_user(@course.teacher).blank? ? '无' : get_occupation_from_user(@course.teacher) %>
<% is_TA = get_user_member_roles_course @course, User.current, 7 %> <% is_TE = get_user_member_roles_course @course, User.current, 9 %> @@ -101,7 +99,7 @@ <%= link_to '学生身份', switch_role_course_path(@course, :user_id => User.current.id, :curr_role => (is_TA ? 7 : 9), :tar_role => 10), :class => "sy_btn_orange mr10 fl", :title => "由教师身份切换至学生身份" %> <% end %> <% unless (is_teacher || is_TA || is_TE || is_ST) %> -没有数据可以显示!
+<% end %> \ No newline at end of file diff --git a/app/views/projects/_applied_status.html.erb b/app/views/projects/_applied_status.html.erb index cce8ba32e..25f5cc8d2 100644 --- a/app/views/projects/_applied_status.html.erb +++ b/app/views/projects/_applied_status.html.erb @@ -1,49 +1,49 @@ -<% if !User.current.member_of?(@project) %> - <% if User.current.login? && !User.current.admin %> - -<%= l_or_humanize(m, :prefix => "project_module_").html_safe %>
请输入申诉理由
<%= format_time(activity.created_at) %> 发布
-<%= format_time(activity.updated_at) %> 更新
-<%= format_time(activity.created_at) %> 发布
+<%= format_time(activity.updated_at) %> 更新
+- <% case @training_task.tracker_id %> - <% when 1%> - 【缺陷】 - <% when 2%> - 【功能】 - <% when 3%> - 【支持】 - <% when 4%> - 【任务】 - <% when 5%> - 【周报】 - <% end %> - <%= @training_task.subject %>
- -<%= string %>
- <% end %> - <% end %> -<%= comment.notes.html_safe %>
-<%= string %>
+ <% end %> + <% end %> +<%= comment.notes.html_safe %>
+