diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 965aacab0..f71103973 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -101,27 +101,27 @@ class MessagesController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE end - # 与我相关动态的记录add start - if(@board && @board.course) #项目的先不管 - teachers = searchTeacherAndAssistant(@board.course) - for teacher in teachers - if(teacher.user_id != User.current.id) - notify = ActivityNotify.new() - if(@board.course) - notify.activity_container_id = @board.course_id - notify.activity_container_type = 'Course' - else - notify.activity_container_id = @board.project_id - notify.activity_container_type = 'Project' - end - notify.activity_id = @message.id - notify.activity_type = 'Message' - notify.notify_to = teacher.user_id - notify.is_read = 0 - notify.save() - end - end - end + # # 与我相关动态的记录add start + # if(@board && @board.course) #项目的先不管 + # teachers = searchTeacherAndAssistant(@board.course) + # for teacher in teachers + # if(teacher.user_id != User.current.id) + # notify = ActivityNotify.new() + # if(@board.course) + # notify.activity_container_id = @board.course_id + # notify.activity_container_type = 'Course' + # else + # notify.activity_container_id = @board.project_id + # notify.activity_container_type = 'Project' + # end + # notify.activity_id = @message.id + # notify.activity_type = 'Message' + # notify.notify_to = teacher.user_id + # notify.is_read = 0 + # notify.save() + # end + # end + # end # 与我相关动态的记录add end call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index ea4dd404a..9f8d25c7e 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -12,10 +12,37 @@ class StudentWorkController < ApplicationController ### def program_test - resultObj = {status: 0, results: [], error_msg: '', time: Time.now} - student_work = find_or_save_student_work - unless student_work - resultObj[:status] = 100 + is_test = params[:is_test] == 'true' + resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')} + unless is_test + student_work = find_or_save_student_work + + unless student_work + resultObj[:status] = 100 + else + if @homework.homework_type == 2 && @homework.homework_detail_programing + result = test_realtime(student_work, params[:src]) + logger.debug result + resultObj[:status] = result["status"] + resultObj[:results] = result["results"] + resultObj[:error_msg] = result["error_msg"] + results = result["results"] + if result["status"].to_i == -2 #编译错误 + results = [result["error_msg"]] + end + student_work_test = student_work.student_work_tests.build(status: result["status"], results: results, + src: params[:src]) + unless student_work.save + resultObj[:status] = 200 + else + resultObj[:status] = result["status"].to_i + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count + end + + end + end + else if @homework.homework_type == 2 && @homework.homework_detail_programing result = test_realtime(student_work, params[:src]) @@ -27,18 +54,15 @@ class StudentWorkController < ApplicationController if result["status"].to_i == -2 #编译错误 results = [result["error_msg"]] end - student_work_test = student_work.student_work_tests.build(status: result["status"], results: results, - src: params[:src]) - unless student_work.save - resultObj[:status] = 200 - else - resultObj[:status] = result["status"].to_i - resultObj[:time] = student_work_test.created_at.to_s(:db) - resultObj[:index] = student_work.student_work_tests.count - end - + + resultObj[:status] = result["status"].to_i + resultObj[:time] = Time.now.strftime('%Y-%m-%d %T') + resultObj[:index] = 0 end + end + + render :json => resultObj end @@ -142,10 +166,18 @@ class StudentWorkController < ApplicationController end def new + if @homework.homework_type==2 + redirect_to new_user_commit_homework_users_path(homework_id: @homework.id) + return + end + @user = User.current @student_work = @homework.student_works.where("user_id = ?",User.current.id).first if @student_work.nil? @student_work = StudentWork.new end + respond_to do |format| + format.html{ render :layout => "new_base_user"} + end end def create @@ -186,11 +218,12 @@ class StudentWorkController < ApplicationController end def edit + @user = User.current if !User.current.admin? && @homework.homework_type == 2 #编程作业不能修改作业 render_403 else respond_to do |format| - format.html + format.html{ render :layout => "new_base_user"} end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5bd124fb9..e3480b238 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -106,18 +106,18 @@ class UsersController < ApplicationController return end # 当前用户查看消息,则设置消息为已读 - if params[:viewed] == "all" - course_querys = @user.course_messages - forge_querys = @user.forge_messages - user_querys = @user.user_feedback_messages - forum_querys = @user.memo_messages - if User.current.id == @user.id - course_querys.update_all(:viewed => true) - forge_querys.update_all(:viewed => true) - user_querys.update_all(:viewed => true) - forum_querys.update_all(:viewed => true) - end - end + #if params[:viewed] == "all" + # course_querys = @user.course_messages + # forge_querys = @user.forge_messages + # user_querys = @user.user_feedback_messages + # forum_querys = @user.memo_messages + # if User.current.id == @user.id + # course_querys.update_all(:viewed => true) + # forge_querys.update_all(:viewed => true) + # user_querys.update_all(:viewed => true) + # forum_querys.update_all(:viewed => true) + # end + #end # @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count case params[:type] when nil @@ -347,6 +347,7 @@ class UsersController < ApplicationController def new_user_commit_homework @user = User.current @homework = HomeworkCommon.find(params[:homework_id]) + @is_test = params[:is_test] == 'true' @student_work = @homework.student_works.where(user_id: User.current.id).first if @student_work.nil? @student_work = StudentWork.new @@ -359,7 +360,7 @@ class UsersController < ApplicationController def user_commit_homework flash[:notice] = l(:notice_successful_create) - redirect_to user_homeworks_user_path(User.current) + redirect_to student_work_index_url(:homework => params[:homework]) end def user_new_homework diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ad9322cbc..2f210f466 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2347,7 +2347,7 @@ module ApplicationHelper if homework.homework_type == 1 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前 link_to "修改作品", "", :class => 'c_blue', :title => "开启匿评后不可修改作品" elsif homework.homework_type == 2 #编程作业不能修改作品 - link_to "作品已交", "",:class => 'c_blue',:title => "编程作业不可修改作品" + link_to "作品已交", student_work_index_path(:homework => homework.id),:class => 'c_blue',:title => "编程作业不可修改作品" else link_to "修改作品", edit_student_work_path(work.id),:class => 'c_blue' end diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index f24d5078f..bff997ba4 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -1,4 +1,6 @@ # encoding: utf-8 +include UserScoreHelper + module StudentWorkHelper def user_projects_option cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1" diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 41f76a792..c94763e31 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -433,7 +433,7 @@ module UserScoreHelper #协同得分 def collaboration(option_number) - option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo + option_number.memo * 2 + option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo end #影响力得分 def influence(option_number) @@ -445,7 +445,7 @@ module UserScoreHelper end #项目贡献得分 def active(option_number) - option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 + option_number.memo * 2 + option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 end #更新发帖数 diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 4f62d24c2..eae880380 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -15,6 +15,8 @@ class CourseMessage < ActiveRecord::Base after_create :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + self.message_alls << MessageAll.new(:user_id => self.user_id) + end end end diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 2d05972ab..0c8b3384f 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -22,6 +22,8 @@ class ForgeMessage < ActiveRecord::Base after_create :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + self.message_alls << MessageAll.new(:user_id => self.user_id) + end end end diff --git a/app/models/memo_message.rb b/app/models/memo_message.rb index 9be00ce14..ce3896389 100644 --- a/app/models/memo_message.rb +++ b/app/models/memo_message.rb @@ -12,6 +12,8 @@ class MemoMessage < ActiveRecord::Base after_create :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + self.message_alls << MessageAll.new(:user_id => self.user_id) + end end end diff --git a/app/models/news.rb b/app/models/news.rb index 6e2725d1c..a9e9d1d18 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -121,7 +121,7 @@ class News < ActiveRecord::Base # Description 公用表中也要记录 def act_as_forge_activity # 如果是project为空,那么是课程相关的,不需要保存 - if !self.project.nil? + if self.project self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.project.id) end diff --git a/app/models/query.rb b/app/models/query.rb index 19bd1bed5..7f51aa53c 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -492,26 +492,28 @@ class Query < ActiveRecord::Base def project_statement project_clauses = [] - if project && !project.descendants.active.empty? - ids = [project.id] - if has_filter?("subproject_id") - case operator_for("subproject_id") - when '=' - # include the selected subprojects - ids += values_for("subproject_id").each(&:to_i) - when '!*' - # main project only - else - # all subprojects + # unless project.descendants.blank? + if project && project.descendants && project.descendants.active && !project.descendants.active.empty? + ids = [project.id] + if has_filter?("subproject_id") + case operator_for("subproject_id") + when '=' + # include the selected subprojects + ids += values_for("subproject_id").each(&:to_i) + when '!*' + # main project only + else + # all subprojects + ids += project.descendants.collect(&:id) + end + elsif Setting.display_subprojects_issues? ids += project.descendants.collect(&:id) end - elsif Setting.display_subprojects_issues? - ids += project.descendants.collect(&:id) + project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') + elsif project + project_clauses << "#{Project.table_name}.id = %d" % project.id end - project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') - elsif project - project_clauses << "#{Project.table_name}.id = %d" % project.id - end + # end project_clauses.any? ? project_clauses.join(' AND ') : nil end diff --git a/app/models/user_feedback_message.rb b/app/models/user_feedback_message.rb index 02335b8e2..db7d3a384 100644 --- a/app/models/user_feedback_message.rb +++ b/app/models/user_feedback_message.rb @@ -11,6 +11,8 @@ class UserFeedbackMessage < ActiveRecord::Base after_save :add_user_message def add_user_message - self.message_alls << MessageAll.new(:user_id => self.user_id) + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? + self.message_alls << MessageAll.new(:user_id => self.user_id) + end end end diff --git a/app/views/attachments/_new_form.html.erb b/app/views/attachments/_new_form.html.erb index 38b471897..47f6fd202 100644 --- a/app/views/attachments/_new_form.html.erb +++ b/app/views/attachments/_new_form.html.erb @@ -23,6 +23,7 @@ <% end %> <% end %> +
<% project = project %>