diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 88b39a1b0..6e5fa6700 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -92,7 +92,7 @@ class HomeworkCommonController < ApplicationController @homework = HomeworkCommon.new @shixuns = Shixun.where(:status => 2).where("name like ?", "%#{search}%") @shixuns_count = @shixuns.count - @limit = 2 + @limit = 8 @is_remote = true @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 @offset ||= @shixun_pages.offset diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 315ea10e6..6e3a97144 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -244,6 +244,7 @@ class ManagementsController < ApplicationController else shixun.update_column('status', 2) apply_action.update_attributes(:status => 1, :dealer_id => User.current.id) + shixun_modify_status_without_publish shixun, 1 end @authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => 0) respond_to do |format| diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index a2f8b7597..ba6370a99 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -7,7 +7,7 @@ class StudentWorkController < ApplicationController require "base64" before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex, :set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project, - :search_course_students,:work_canrepeat,:add_group_member,:change_project] + :search_course_students,:work_canrepeat,:add_group_member,:change_project,:relate_myshixun] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work, :retry_work, :revise_attachment, :hide_score_detail, :destroy_score] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -563,7 +563,7 @@ class StudentWorkController < ApplicationController student_work.user_id = User.current.id student_work.commit_time = Time.now #student_work.late_reason = params[:late_reason] if params[:late_reason] - student_work.group_id = @homework.student_works.all_commit.select("distinct group_id").count + 1 + student_work.group_id = @homework.homework_type == 3 ? @homework.student_works.all_commit.select("distinct group_id").count + 1 : 0 student_work.save_attachments(params[:attachments]) render_attachment_warning_if_needed(student_work) if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 @@ -728,10 +728,13 @@ class StudentWorkController < ApplicationController ids = ids - [User.current.id] end @team_work = User.where(:id => ids) + elsif @homework.homework_type == 4 + @shixun = @homework.homework_commons_shixuns.shixun + @myshixun = Myshixun.find @work.myshixun_id end respond_to do |format| - format.html{render :layout => 'base_edu'} format.js + format.html{render :layout => 'base_edu'} end end @@ -874,6 +877,48 @@ class StudentWorkController < ApplicationController end end + def relate_myshixun + myshixun = Myshixun.where(:shixun_id => @homework.homework_commons_shixuns.shixun_id, :user_id => User.current.id).first + if myshixun + work = @homework.student_works.where(:user_id => User.current.id).first + work = work || StudentWork.new(:homework_common_id => @homework.id, :user_id => User.current.id, :work_status => 0) + if work.work_status == 0 + work.myshixun_id = myshixun.id + work.commit_time = Time.now + if @homework.end_time < Time.now + work.late_penalty = @homework.late_penalty + work.work_status = 2 + + #更新CourseHomeworkStatistics中学生的迟交作品数 + course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, User.current.id) + course_statistics.update_attribute('late_commit_work_num', course_statistics.late_commit_work_num + 1) if course_statistics + else + work.late_penalty = 0 + work.work_status = 1 + end + if work.save + #更新CourseHomeworkStatistics中学生的未交作品数、已交作品数 + course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, User.current.id) + course_statistics.update_attribute('committed_work_num', course_statistics.committed_work_num + 1) if course_statistics + course_statistics.update_attribute('un_commit_work_num', (course_statistics.un_commit_work_num - 1) < 0 ? 0 : (course_statistics.un_commit_work_num - 1)) if course_statistics + + @homework.update_column(:updated_at, Time.now) + update_course_activity(@homework.class,@homework.id) + update_user_activity(@homework.class,@homework.id) + update_org_activity(@homework.class,@homework.id) + + course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录 + course_message.save + @status = 1 + end + else + @status = 2 + end + else + @status = 0 + end + end + #添加评分,已评分则为修改评分 def add_score @is_last = params[:is_last] == "true" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1b72455ff..cf8e10aad 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,8 +181,8 @@ module ApplicationHelper end # 已通过的关卡数 - def had_passed_changllenge_count shixun - myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => User.current.id).first + def had_passed_changllenge_count shixun, user + myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => user.id).first if myshixun.nil? 0 else diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 0416e72b7..b15a76b6f 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -98,29 +98,42 @@ module StudentWorkHelper work = cur_user_works_for_homework homework project = cur_user_projects_for_homework homework if work.nil? && homework.end_time >= Time.now - link_to "提交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr' + if homework.homework_type == 4 + link_to "关联实训", relate_myshixun_student_work_index_path(:homework => homework.id),:class => 'task-btn task-btn-blue fr',:remote => true + else + link_to "提交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr' + end elsif work.nil? && homework.end_time < Time.now if homework.allow_late && homework.homework_detail_manual.comment_status < 6 - link_to "补交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr' + if homework.homework_type == 4 + link_to "关联实训", relate_myshixun_student_work_index_path(:homework => homework.id),:class => 'task-btn task-btn-blue fr',:remote => true + else + link_to "补交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr' + end end elsif work - if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前 - if homework.homework_type != 3 - link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品" - else - work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")" - if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0 + if homework.homework_type == 4 + myshixun = Myshixun.find work.myshixun_id + link_to "继续实训", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "task-btn task-btn-blue fr mr10",:target => "_blank" if myshixun + else + if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前 + if homework.homework_type != 3 link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品" else - link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评开启后提交的作品不参与匿评" + work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")" + if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0 + link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品" + else + link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评开启后提交的作品不参与匿评" + end end + elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status > 3 + link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评已结束" + elsif homework.end_time >= Time.now && work.user_id == User.current.id + link_to "修改作品", edit_student_work_url_without_domain(work.id),:class => 'task-btn task-btn-blue fr' + else + link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "作业截止后不可修改作品" end - elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status > 3 - link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评已结束" - elsif homework.end_time >= Time.now && work.user_id == User.current.id - link_to "修改作品", edit_student_work_url_without_domain(work.id),:class => 'task-btn task-btn-blue fr' - else - link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "作业截止后不可修改作品" end end end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index eff520ef6..5d23cb584 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -7,6 +7,7 @@ class Myshixun < ActiveRecord::Base has_many :games, :dependent => :destroy, :order => "games.id ASC" belongs_to :shixun has_one :shixun_modify, :dependent => :destroy + has_many :student_works def total_stage self.games.count @@ -18,6 +19,34 @@ class Myshixun < ActiveRecord::Base return position end + def done_time + time = "" + if self.status == 1 + time = self.games.order("end_time desc").first.try(:end_time) + end + time + end + + def total_spend_time + time = 0 + self.games.each do |game| + if game.status == 2 + time += (game.end_time -game.open_time).to_i > 0 ? (game.end_time -game.open_time).to_i : 0 + end + end + time + end + + def total_score + score = 0 + self.games.each do |game| + if game.status == 2 + score += game.final_score + end + end + score + end + # id 转换成 identifier def to_param identifier diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 404b8d28f..69beab432 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -54,6 +54,14 @@ class Shixun < ActiveRecord::Base render_404 end + def shixun_score + score = 0 + self.challenges.each do |challenge| + score += challenge.score + end + score + end + def collaborators self.shixun_members.select{|member| member.role == 2} unless self.shixun_members.blank? end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 45ab6d04e..cc800cbb6 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -13,6 +13,7 @@ class StudentWork < ActiveRecord::Base # course's message has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :attachments, :dependent => :destroy + has_one :myshixun scope :has_committed, lambda{where("work_status != 0 and work_status != 3")} scope :all_commit, lambda{where("work_status != 0")} diff --git a/app/views/homework_common/_homework_index_list.html.erb b/app/views/homework_common/_homework_index_list.html.erb index 4f119620a..3f027a5a4 100644 --- a/app/views/homework_common/_homework_index_list.html.erb +++ b/app/views/homework_common/_homework_index_list.html.erb @@ -72,16 +72,16 @@ <% end %> <% if (User.current.teacher_of_course(homework_common.course) || homework_common.user == User.current) && User.current.homework_banks.where(:homework_common_id => homework_common.id).empty? %> -
<%= student_work.student_works_scores.where(:reviewer_role => 2).group_by(&:user_id).count%>名助教进行了评分
<%= ta_score_mode(@homework) %>分:<%= student_work.teaching_asistant_score %> 分
@@ -27,7 +27,7 @@
<% end %>
<%= student_work.user.show_name %>(<%= student_work.user.login %>)
diff --git a/app/views/student_work/_evaluation_un_group_work.html.erb b/app/views/student_work/_evaluation_un_group_work.html.erb
index 283ec3a0b..b1f55e774 100644
--- a/app/views/student_work/_evaluation_un_group_work.html.erb
+++ b/app/views/student_work/_evaluation_un_group_work.html.erb
@@ -18,10 +18,10 @@
<%= student_work.student_works_scores.where(:reviewer_role => 2).group_by(&:user_id).count%>名助教进行了评分
<%= ta_score_mode(@homework) %>分:<%= student_work.teaching_asistant_score %> 分
@@ -30,7 +30,7 @@
<% end %>
<%= student_work.user.show_name %>(<%= student_work.user.login %>)
diff --git a/app/views/student_work/_evaluation_un_pro_work.html.erb b/app/views/student_work/_evaluation_un_pro_work.html.erb
index cc3be23a0..7587d166f 100644
--- a/app/views/student_work/_evaluation_un_pro_work.html.erb
+++ b/app/views/student_work/_evaluation_un_pro_work.html.erb
@@ -15,10 +15,10 @@
<%= student_work.student_works_scores.where(:reviewer_role => 2).group_by(&:user_id).count%>名助教进行了评分
<%= ta_score_mode(@homework) %>分:<%= student_work.teaching_asistant_score %> 分
@@ -30,7 +30,7 @@
<%= student_work.system_score.nil? ? "--" : (!score_open ? "**" : format("%.1f",student_work.system_score))%>
已通过<%= had_passed_changllenge_count(shixun, student_work.user) %>关,共<%= shixun.challenges.count %>关 +
++ <%= link_to @shixun.owner.try(:show_name), user_path(@shixun.owner), :class => "link-name-dark fl", :target => "_blank" %> + / + <%= link_to @shixun.name, shixun_path(@shixun), :class => "edu-info-dark fl", :target => "_blank" %> +
+ 经验值:<%= @myshixun.total_score %> +| 序号 | + +耗时 | +经验值 | +
|---|---|---|
| 第<%= index + 1 %>关 | + +<%= game.status == 2 ? game_spend_time((game.end_time - game.open_time).to_i) : '- -' %> | +<%= game.status == 2 ? game.final_score : '- -' %> | +
<%= shixun.name %> - 已解锁第<%= had_passed_changllenge_count(shixun) %>关/共<%= shixun.challenges.count %>关 + 已解锁第<%= had_passed_changllenge_count(shixun, User.current) %>关/共<%= shixun.challenges.count %>关 <%= format_time shixun.created_at %>
diff --git a/app/views/users/_myjoin_shixun_list.html.erb b/app/views/users/_myjoin_shixun_list.html.erb index 55d64abe5..d38c620b2 100644 --- a/app/views/users/_myjoin_shixun_list.html.erb +++ b/app/views/users/_myjoin_shixun_list.html.erb @@ -10,7 +10,7 @@<%= (User.find shixun.user_id).show_name %> <%= shixun.language %> - <%= had_passed_changllenge_count shixun %> / <%= shixun.challenges.count %> 任务完成 + <%= had_passed_changllenge_count shixun, User.current %> / <%= shixun.challenges.count %> 任务完成 <%= format_time(shixun.updated_at) %> 开启
diff --git a/config/routes.rb b/config/routes.rb index 367e9aebc..4ca57552c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -494,6 +494,7 @@ RedmineApp::Application.routes.draw do get 'alert_appeal_box' get 'delete_score_comment' get 'deal_appeal_score' + get 'relate_myshixun' end end diff --git a/db/migrate/20170522071931_add_attachment_to_course_module.rb b/db/migrate/20170522071931_add_attachment_to_course_module.rb deleted file mode 100644 index 18720c28e..000000000 --- a/db/migrate/20170522071931_add_attachment_to_course_module.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAttachmentToCourseModule < ActiveRecord::Migration - def change - add_column :course_modules, :attachment, :integer - end -end diff --git a/db/migrate/20170523011829_change_news_for_course_module.rb b/db/migrate/20170523011829_change_news_for_course_module.rb deleted file mode 100644 index eeb2d8f03..000000000 --- a/db/migrate/20170523011829_change_news_for_course_module.rb +++ /dev/null @@ -1,8 +0,0 @@ -class ChangeNewsForCourseModule < ActiveRecord::Migration - def up - rename_column :course_modules, :news, :boards - end - - def down - end -end diff --git a/db/migrate/20170526062330_del_course_modules.rb b/db/migrate/20170526062330_del_course_modules.rb deleted file mode 100644 index 2b2f1cfd1..000000000 --- a/db/migrate/20170526062330_del_course_modules.rb +++ /dev/null @@ -1,8 +0,0 @@ -class DelCourseModules < ActiveRecord::Migration - def up - drop_table :course_modules - end - - def down - end -end diff --git a/db/migrate/20170627073830_add_myshixun_to_student_work.rb b/db/migrate/20170627073830_add_myshixun_to_student_work.rb new file mode 100644 index 000000000..3e8622a7b --- /dev/null +++ b/db/migrate/20170627073830_add_myshixun_to_student_work.rb @@ -0,0 +1,5 @@ +class AddMyshixunToStudentWork < ActiveRecord::Migration + def change + add_column :student_works, :myshixun_id, :integer + end +end diff --git a/public/javascripts/edu/course.js b/public/javascripts/edu/course.js index 16c941cd5..a3047e3c2 100644 --- a/public/javascripts/edu/course.js +++ b/public/javascripts/edu/course.js @@ -493,4 +493,14 @@ $.fn.peSlider = function(settings){ } } }); -}; \ No newline at end of file +}; + +$(function() { + //匿评评分提示 + $(".student_score_info").live("mouseover", function () { + $(this).find("div").show(); + }); + $(".student_score_info").live("mouseout", function () { + $(this).find("div").hide(); + }); +}); \ No newline at end of file diff --git a/public/stylesheets/css/edu-class.css b/public/stylesheets/css/edu-class.css index 5d8906479..a65f52a16 100644 --- a/public/stylesheets/css/edu-class.css +++ b/public/stylesheets/css/edu-class.css @@ -87,6 +87,7 @@ table.table-pa5 th,table.table-pa5 td{ padding:0 5px;} .edu-class-right-box{ background:#fff; position:relative; padding-bottom:20px;} a.edu-class-user-img{ height: 80px;} .edu-class-user-img img{ width: 80px; height: 80px; border-radius:100px;} +.edu-work-user-img img{ border-radius:100px;} a.edu-class-right-add{ display: block; position:absolute; bottom: 0; width: 100%; height: 40px; background-color: rgba(0, 0, 0, 0.3);color:#fff; text-align: center; line-height: 40px;} a:hover.edu-class-right-add{ background-color: rgba(0, 0, 0, 0.4);} .edu-undis{ display: none!important;}