diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 526535157..39401d079 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -458,7 +458,7 @@ class StudentWorksController < ApplicationController @shixun = @homework.shixuns.take # 提示: 这里如果includes outputs表的话: sum(:evaluate_count)会出现错误 @games = @work.myshixun.games.joins(:challenge).reorder("challenges.position asc") if @work.myshixun - @comment = @work.student_works_scores.shixun_comment.first + @comment = @work.shixun_work_comments.find_by(challenge_id: 0) # 用户最大评测次数 if @games @@ -474,19 +474,37 @@ class StudentWorksController < ApplicationController # 实训作品的评阅 def shixun_work_comment - tip_exception("评阅不能为空") if params[:comment].blank? - tip_exception("缺少is_hidden参数") if params[:is_hidden].blank? || ![1, 0].include?(params[:is_hidden]) - comment = @work.student_works_scores.shixun_comment.first || StudentWorksScore.new(student_work_id: @work.id, user_id: current_user.id) - comment.comment = params[:comment] - comment.is_hidden = params[:is_hidden] - comment.save! - normal_status("评阅成功") + tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank? + ActiveRecord::Base.transaction do + challenge = @homework.shixuns.first&.challenges.find_by(id: params[:challenge_id]) unless params[:challenge_id].blank? + if challenge.present? + comment = @work.shixun_work_comments.find_by(challenge_id: challenge.id) || + ShixunWorkComment.new(student_work_id: @work.id, user_id: current_user.id, challenge_id: challenge.id) + else + comment = @work.shixun_work_comments.find_by(challenge_id: 0) || + ShixunWorkComment.new(student_work_id: @work.id, user_id: current_user.id, challenge_id: 0) + end + comment.comment = params[:comment] + comment.hidden_comment = params[:hidden_comment] + comment.save! + normal_status("评阅成功") + end end # 删除实训作品评阅 def destroy_work_comment - @work.student_works_scores.shixun_comment.first.destroy! if @work.student_works_scores.shixun_comment.first.present? - normal_status("删除成功") + ActiveRecord::Base.transaction do + tip_exception("visible_comment参数有误") if params[:visible_comment].nil? + + comment = @work.shixun_work_comments.find_by!(id: params[:comment_id]) + params[:visible_comment] ? comment.comment = nil : comment.hidden_comment = nil + if comment.comment.nil? && comment.hidden_comment.nil? + comment.destroy! + else + comment.save! + end + normal_status("删除成功") + end end def export_shixun_work_report diff --git a/app/models/shixun_work_comment.rb b/app/models/shixun_work_comment.rb new file mode 100644 index 000000000..7a67238ab --- /dev/null +++ b/app/models/shixun_work_comment.rb @@ -0,0 +1,5 @@ +class ShixunWorkComment < ApplicationRecord + belongs_to :student_work + belongs_to :user + belongs_to :challenge, optional: true +end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 168cfeb68..9c9efa17c 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -7,6 +7,7 @@ class StudentWork < ApplicationRecord belongs_to :myshixun, optional: true has_many :student_works_evaluation_distributions, dependent: :destroy has_many :student_works_scores, dependent: :destroy + has_many :shixun_work_comments, dependent: :destroy belongs_to :project, optional: true # attachtype: 1(正常提交的附件), 7(补交的附件) diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 29a5c1874..e63cc2c13 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -36,6 +36,10 @@ if @shixun challenge_score = @homework.challenge_score game.challenge_id json.game_score_full challenge_score json.game_score @work.work_challenge_score game, challenge_score + challenge_comment = @work.shixun_work_comments.find_by(challenge_id: game.challenge_id) + json.challenge_comment challenge_comment&.comment + json.challenge_comment_hidden challenge_comment&.hidden_comment + json.comment_id challenge_comment&.id end end @@ -54,8 +58,9 @@ if @shixun json.passed_time @work.myshixun&.passed_time # 评阅信息 - json.work_comment @user_course_identity < Course::STUDENT || !@comment&.is_hidden ? @comment&.comment : nil - json.work_comment_hidden @comment&.is_hidden + json.work_comment @comment&.comment + json.work_comment_hidden @user_course_identity < Course::STUDENT ? @comment&.hidden_comment : nil + json.comment_id @comment&.id # 图形统计 # 1: 效率 diff --git a/db/migrate/20190909080508_create_shixun_work_comments.rb b/db/migrate/20190909080508_create_shixun_work_comments.rb new file mode 100644 index 000000000..eb21f0d04 --- /dev/null +++ b/db/migrate/20190909080508_create_shixun_work_comments.rb @@ -0,0 +1,13 @@ +class CreateShixunWorkComments < ActiveRecord::Migration[5.2] + def change + create_table :shixun_work_comments do |t| + t.references :student_work, index: true, type: :integer + t.references :challenge, index: true, type: :integer, default: 0 + t.references :user, index: true, type: :integer + t.text :comment + t.text :hidden_comment + + t.timestamps + end + end +end diff --git a/db/migrate/20190909082555_migrate_shixun_work_comment.rb b/db/migrate/20190909082555_migrate_shixun_work_comment.rb new file mode 100644 index 000000000..f58531b80 --- /dev/null +++ b/db/migrate/20190909082555_migrate_shixun_work_comment.rb @@ -0,0 +1,13 @@ +class MigrateShixunWorkComment < ActiveRecord::Migration[5.2] + def change + StudentWorksScore.where(is_ultimate: 0, score: nil).where("created_at > '2019-09-04 00:00:00'").each do |work_score| + if work_score.student_work && work_score.student_work.homework_common&.shixuns + if work_score.is_hidden + ShixunWorkComment.create!(student_work_id: work_score.student_work_id, user_id: work_score.user_id, hidden_comment: work_score.comment) + else + ShixunWorkComment.create!(student_work_id: work_score.student_work_id, user_id: work_score.user_id, comment: work_score.comment) + end + end + end + end +end diff --git a/public/javascripts/educoder/edu_application.js b/public/javascripts/educoder/edu_application.js index 612a5a44b..7f8f8ac4d 100644 --- a/public/javascripts/educoder/edu_application.js +++ b/public/javascripts/educoder/edu_application.js @@ -218,7 +218,7 @@ function _initSider() { }) } $(function() { - loadHeader(); + // loadHeader(); _initSider(); $(window).scroll(function() { @@ -436,86 +436,86 @@ function editormd_to_html(id, callback) { } function loadHeader() { - //头部导航条的----------显示搜索框 - $("#search-open").on("click", function(e) { - $(this).hide(); - // $("#header-nav").animate({opacity:"0"},1000); - $(".posi-search").show() - // .animate({opacity:"1"},1000); - $("#header-nav").css("z-index", "2"); - $(".posi-search").css("z-index", "3"); - // $(".search-input").val(""); // 不清空 - $(".search-input").focus(); - $(".search-all .search-content").hide(); - e.stopPropagation(); - //阻止冒泡 - }); - $(".search-input").on("click", function(e) { - e.stopPropagation(); - //阻止冒泡 - }); - //搜索框输入内容 - $(".search-input").on("input", function(e) { - if ($(".search-input").val() == "") { - $(".search-all .search-content").hide(); - } else { - $(".search-all .search-content").show(); - } - e.stopPropagation(); - //阻止冒泡 - }); - //搜索 - $("#header_keyword_search").on("click", header_search); - $("input[name='search_keyword']").on("keydown", function(event) { - var code; - if (!event) { - event = window.event; - //针对ie浏览器 - code = event.keyCode; - } else { - code = event.keyCode; - } - if (code == 13) { - header_search(); - return false; - } - }); - $(".search-clear").click(function(e) { - e.stopPropagation(); - }); - //切换搜索条件 - $("#searchkey li").click(function(e) { - var key = $($(this).children("a")[0]).html(); - switch (key) { - case '实训': - $("#search_type").val('1'); - break; - case '课堂': - $("#search_type").val('2'); - break; - case '用户': - $("#search_type").val('3'); - break; - } - $("#searchkey").siblings(".searchkey").html(key); - // $("#searchkey").hide(); - e.stopPropagation(); - //阻止冒泡 - }); - //切换选择导航条 - $("#header-nav li").click(function() { - $("#header-nav li").removeClass("active"); - $(this).addClass("active"); - }); - //点击页面其它(与搜索框无关的地方)都会将搜索框隐藏,所以与搜索框有关的地方需要阻止冒泡 - $("body").on("click", function() { - closeSearch(); - }); - - $(".search_history").on("click", function() { - $("input[name='search_keyword']").val($(this).html()); - header_search(); - }); + // //头部导航条的----------显示搜索框 + // $("#search-open").on("click", function(e) { + // $(this).hide(); + // // $("#header-nav").animate({opacity:"0"},1000); + // $(".posi-search").show() + // // .animate({opacity:"1"},1000); + // $("#header-nav").css("z-index", "2"); + // $(".posi-search").css("z-index", "3"); + // // $(".search-input").val(""); // 不清空 + // $(".search-input").focus(); + // $(".search-all .search-content").hide(); + // e.stopPropagation(); + // //阻止冒泡 + // }); + // $(".search-input").on("click", function(e) { + // e.stopPropagation(); + // //阻止冒泡 + // }); + // //搜索框输入内容 + // $(".search-input").on("input", function(e) { + // if ($(".search-input").val() == "") { + // $(".search-all .search-content").hide(); + // } else { + // $(".search-all .search-content").show(); + // } + // e.stopPropagation(); + // //阻止冒泡 + // }); + // //搜索 + // $("#header_keyword_search").on("click", header_search); + // $("input[name='search_keyword']").on("keydown", function(event) { + // var code; + // if (!event) { + // event = window.event; + // //针对ie浏览器 + // code = event.keyCode; + // } else { + // code = event.keyCode; + // } + // if (code == 13) { + // header_search(); + // return false; + // } + // }); + // $(".search-clear").click(function(e) { + // e.stopPropagation(); + // }); + // //切换搜索条件 + // $("#searchkey li").click(function(e) { + // var key = $($(this).children("a")[0]).html(); + // switch (key) { + // case '实训': + // $("#search_type").val('1'); + // break; + // case '课堂': + // $("#search_type").val('2'); + // break; + // case '用户': + // $("#search_type").val('3'); + // break; + // } + // $("#searchkey").siblings(".searchkey").html(key); + // // $("#searchkey").hide(); + // e.stopPropagation(); + // //阻止冒泡 + // }); + // //切换选择导航条 + // $("#header-nav li").click(function() { + // $("#header-nav li").removeClass("active"); + // $(this).addClass("active"); + // }); + // //点击页面其它(与搜索框无关的地方)都会将搜索框隐藏,所以与搜索框有关的地方需要阻止冒泡 + // $("body").on("click", function() { + // closeSearch(); + // }); + // + // $(".search_history").on("click", function() { + // $("input[name='search_keyword']").val($(this).html()); + // header_search(); + // }); } function header_search() { diff --git a/public/react/public/images/share_logo_icon.jpg b/public/react/public/images/share_logo_icon.jpg new file mode 100644 index 000000000..079ac4342 Binary files /dev/null and b/public/react/public/images/share_logo_icon.jpg differ diff --git a/public/react/public/index.html b/public/react/public/index.html index b252ccf36..de539ffba 100755 --- a/public/react/public/index.html +++ b/public/react/public/index.html @@ -22,6 +22,8 @@ -->