diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 8cefa5071..bb28fff54 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -494,6 +494,7 @@ class ExerciseQuestionsController < ApplicationController def adjust_score ActiveRecord::Base.transaction do begin + ex_all_scores = @exercise.exercise_questions.pluck(:question_score).sum ex_obj_score = @exercise_current_user.objective_score #全部客观题得分 ex_subj_score = @exercise_current_user.subjective_score < 0.0 ? 0.0 : @exercise_current_user.subjective_score #全部主观题得分 ex_answers = @exercise_question.exercise_answers.search_answer_users("user_id",@user_id) #当前用户答案的得分 @@ -501,9 +502,11 @@ class ExerciseQuestionsController < ApplicationController if ex_answers.present? #学生有回答时 取学生的答题得分,否则0分 answer_choice_array = [] ex_answers.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + if a.try(:exercise_choice).try(:choice_position).present? + answer_choice_array.push(a&.exercise_choice&.choice_position) #学生答案的位置 + end end - user_answer_content = answer_choice_array.sort + user_answer_content = answer_choice_array.reject(&:blank?).sort standard_answer = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).sort if standard_answer.size == 1 # 老数据需要判断学生答题是否正确, 正确取原题得分,否则是0分 standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort @@ -535,6 +538,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = new_obj_score + ex_subj_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :objective_score => new_obj_score, @@ -563,6 +568,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = new_obj_score + ex_subj_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :objective_score => new_obj_score, @@ -587,6 +594,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = ex_obj_score + new_sub_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :subjective_score => new_sub_score, @@ -615,6 +624,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = new_obj_score + ex_subj_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :objective_score => new_obj_score, @@ -623,23 +634,26 @@ class ExerciseQuestionsController < ApplicationController @exercise_current_user.update_attributes(ex_scores) end comments = params[:comment] - question_comment = @exercise_question.exercise_answer_comments.first + question_comment = @exercise_question.exercise_answer_comments&.first + if question_comment.present? comment_option = { - :comment => comments.present? ? comments : question_comment.comment, + :comment => comments, :score => @c_score, - :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil + :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil, + :user_id => current_user.id } question_comment.update_attributes(comment_option) @exercise_comments = question_comment else + ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id) comment_option = { :user_id => current_user.id, :comment => comments, :score => @c_score, :exercise_question_id => @exercise_question.id, :exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil, - :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil + :exercise_answer_id => ex_answer_comment_id } @exercise_comments = ExerciseAnswerComment.new(comment_option) @exercise_comments.save diff --git a/app/models/exercise_answer_comment.rb b/app/models/exercise_answer_comment.rb index 7da0ec4c7..4279ba445 100644 --- a/app/models/exercise_answer_comment.rb +++ b/app/models/exercise_answer_comment.rb @@ -3,7 +3,7 @@ class ExerciseAnswerComment < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_shixun_answer, optional: true - belongs_to :exercise_answer,optional: true + belongs_to :exercise_answer, optional: true scope :search_answer_comments, lambda {|name,ids| where("#{name}":ids)} end diff --git a/public/react/src/modules/courses/coursesPublic/NewShixunModel.js b/public/react/src/modules/courses/coursesPublic/NewShixunModel.js index 395e4096d..fbb97cbb5 100644 --- a/public/react/src/modules/courses/coursesPublic/NewShixunModel.js +++ b/public/react/src/modules/courses/coursesPublic/NewShixunModel.js @@ -22,18 +22,15 @@ class NewShixunModel extends Component{ } } componentDidMount() { - let{page,type,keyword,order,diff,limit}=this.state; - let status=this.props.statustype===undefined?'all':'published'; - this.setState({ - status:status - }) + let{page,type,keyword,order,diff,limit,status}=this.state; this.getdatalist(page,type,status,keyword,order,diff,limit) } - getdatalist=(page,type,status,keyword,order,diff,limit,pagetype)=>{ + getdatalist=(page,type,newstatus,keyword,order,diff,limit,pagetype)=>{ this.setState({ isspinning:true }) + let status=this.props.statustype===undefined?newstatus:'published'; let url="/shixun_lists.json" axios.get(url,{params:{ page, @@ -142,10 +139,11 @@ class NewShixunModel extends Component{ belongto=(value)=>{ this.setState({ type:value, - keyword:undefined + keyword:undefined, + page:1 }) - let{page,status,keyword,order,diff,limit}=this.state; - this.getdatalist(page,value,status,keyword,order,diff,limit) + let{status,order,diff,limit}=this.state; + this.getdatalist(1,value,status,undefined,order,diff,limit) } updatedlist=(order)=>{ @@ -441,7 +439,7 @@ class NewShixunModel extends Component{ ` } - {JSON.stringify(item.description) == "{}"?"":
+ {JSON.stringify(item.description) == "{}"?"":
} {item.challenge_names.length===0?"":
@@ -530,4 +528,28 @@ class NewShixunModel extends Component{ } } -export default NewShixunModel; \ No newline at end of file +export default NewShixunModel; + + +// {JSON.stringify(item.content) == "{}"?
+//
:
+// {item.content.description === undefined || item.content.description===0?"":item.content.description.map((item,key)=>{ +// return( +// {} +// ) +// })} +//
} +// +// {JSON.stringify(item.content) == "{}"?item.challenge_names.length===0?"":
+// {item.challenge_names.map((item,key)=>{ +// return( +// 第{key+1}关:{item} +// ) +// })} +//
:
+// {item.content.challenge_names === undefined || item.content.challenge_names===0?"":item.content.challenge_names.map((item,key)=>{ +// return( +// {} +// ) +// })} +//
} \ No newline at end of file diff --git a/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js b/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js index b5a1a7c26..f45de9b64 100644 --- a/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js +++ b/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js @@ -199,7 +199,7 @@ class ExerciseReviewAndAnswer extends Component{ result.data && result.data.exercise_questions.length>0 && result.data.exercise_questions.map((item,key)=>{ if( item.question_type == 4 && item.answer_status == 0 ){ ajustSore.push({ - inputSore:undefined, + inputSore:0, desc:undefined, id:item.question_id, position:item.q_position, @@ -268,15 +268,15 @@ class ExerciseReviewAndAnswer extends Component{ exercise_questions : update(prevState.exercise_questions, {[key]: { setScore: {$set: flag == undefined || flag==false ? true : false}}}) }),()=>{ if (position && type && (flag == undefined || flag==false)) { + $("#input_"+position+"_"+type).focus(); $("html").animate({ scrollTop: $("#Anchor_"+position+"_"+type).offset().top - 150 }); - if(id){ let { ajustSore } = this.state; let obj = ajustSore.filter(obj => obj.id === id).length > 0; if(!obj){ ajustSore.push({ id, - inputSore:undefined, + inputSore:0, desc:undefined, position:position, setTip:"" @@ -332,7 +332,7 @@ class ExerciseReviewAndAnswer extends Component{ ) } //确认调分 - setAction=(key,q_id,maxScore)=>{ + setAction=(key,q_id,maxScore,oldScore)=>{ let {ajustSore}=this.state; let list = ajustSore.filter(obj => obj.id == q_id); let index = ajustSore.map(function (item) { return item.id; }).indexOf(q_id); @@ -382,21 +382,26 @@ class ExerciseReviewAndAnswer extends Component{ }).then((result)=>{ if(result.status==200){ this.props.showNotification('调分成功'); + this.getInfo(); + // let statusScore = score==0 ? 0 : score > 0 && score < maxScore ? 2 : 1; - let statusScore = score==0 ? 0 : score > 0 && score < maxScore ? 2 : 1; - - this.setState( - (prevState) => ({ - exercise_questions : update(prevState.exercise_questions, {[key]: { user_score: {$set: parseFloat(score).toFixed(1)},answer_status : {$set: statusScore},question_comments:{$set:result.data.question_comments} }}), - }) - ) + // this.setState( + // (prevState) => ({ + // exercise_questions : update(prevState.exercise_questions, {[key]: { user_score: {$set: parseFloat(score).toFixed(1)},answer_status : {$set: statusScore},question_comments:{$set:result.data.question_comments} }}), + // }) + // ) - this.setState( - (prevState) => ({ - ajustSore : update(prevState.ajustSore, {[index]: { desc: {$set: undefined},inputSore:{ $set:undefined }}}) - }) - ) - this.showSetScore(key,true); + // this.setState( + // (prevState) => ({ + // ajustSore : update(prevState.ajustSore, {[index]: { desc: {$set: undefined},inputSore:{ $set:undefined }}}) + // }) + // ) + // let {exerciseTotalScore} = this.state; + // let newScore = parseFloat(parseFloat(exerciseTotalScore)+parseFloat(score)-parseFloat(oldScore)).toFixed(1); + // this.setState({ + // exerciseTotalScore:newScore + // }) + // this.showSetScore(key,true); } }).catch((error)=>{ console.log(error); @@ -781,7 +786,6 @@ class ExerciseReviewAndAnswer extends Component{
{ exercise_questions && exercise_questions.map((item,key)=>{ - debugger; let list = ajustSore && ajustSore.filter(obj => obj.id === item.question_id); return(
@@ -928,12 +932,13 @@ class ExerciseReviewAndAnswer extends Component{ precision={1} className={ list && list.length>0 && list[0].setTip !="" ? "edu-txt-center winput-115-40 fl mt3 noticeTip inputNumber30" : "edu-txt-center winput-115-40 fl mt3 inputNumber30"} onChange={(value)=>this.inputScore(value,item.question_id)} + id={`${"input_"+item.q_position+"_"+item.question_type}`} > { parseInt(item.answer_status) == 0 && item.question_type == 4 ? 未评分 : '' } - this.setAction(key,item.question_id,item.question_score)}>确认 + this.setAction(key,item.question_id,item.question_score,item.user_score)}>确认

{ list && list.length > 0 && list[0].setTip !="" ?

{ list[0].setTip }

:""