From 95b5c2ce0c5b946e86e0e44771b566b7f878eef5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 5 Sep 2017 16:46:51 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=8D=95=E9=80=89?= =?UTF-8?q?=E5=A4=9A=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 34 +- app/views/challenges/_choose_type.html.erb | 408 +----------------- .../_single_or_multiple_question.html.erb | 397 +++++++++++++++++ app/views/challenges/_task_edit_page.html.erb | 5 + app/views/challenges/_task_pass_form.html.erb | 60 --- app/views/challenges/edit.html.erb | 2 +- app/views/challenges/edit.js.erb | 1 + 7 files changed, 434 insertions(+), 473 deletions(-) create mode 100644 app/views/challenges/_single_or_multiple_question.html.erb create mode 100644 app/views/challenges/_task_edit_page.html.erb create mode 100644 app/views/challenges/edit.js.erb diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 72ea81bda..834e6b302 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -97,6 +97,10 @@ class ChallengesController < ApplicationController @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if challenge_pos - 1 > 0 @tab = params[:tab].blank? ? 1 : params[:tab].to_i @editor = params[:editor] # 编辑模式 + respond_to do |format| + format.html + format.js + end end def destroy @@ -111,22 +115,22 @@ class ChallengesController < ApplicationController def update ActiveRecord::Base.transaction do @challenge.update_attributes(params[:challenge]) - if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0 - begin - @challenge.challenge_questions.delete_all - params[:question][:cnt].each_with_index do |test, index| - answer = params[:choice][:answer][index] == "0" ? false : true - ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer) - end - redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) - rescue Exception => e - flash[:error] = "#{e.message}" - format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} - raise ActiveRecord::Rollback - end - else + #if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0 + # begin + # @challenge.challenge_questions.delete_all + # params[:question][:cnt].each_with_index do |test, index| + # answer = params[:choice][:answer][index] == "0" ? false : true + # ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer) + # end + # redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + # rescue Exception => e + # flash[:error] = "#{e.message}" + # format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} + # raise ActiveRecord::Rollback + # end + #else redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) - end + #end end end diff --git a/app/views/challenges/_choose_type.html.erb b/app/views/challenges/_choose_type.html.erb index a9fc7ec70..35ed85afc 100644 --- a/app/views/challenges/_choose_type.html.erb +++ b/app/views/challenges/_choose_type.html.erb @@ -3,19 +3,16 @@
  • 本关任务
  • - + 多选题 + 单选题
    -
    +

    <% if User.current.manager_of_shixun?(@shixun) %> - 编辑 + 编辑 <% end %>

    @@ -36,403 +33,20 @@
    +
    -
  • - 编辑 - 删除 -
  • -
    -
    -
  • - -
    - -
    -
  • - -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • -
      -
    • - - -
    • - -
    • -
    -
    -
    -

    - -
    -
    -
      -
    • - -
      - -
      -
    • -
    -
    -
    -

    - -
    -
    -
  • - - - > - - - - > - - - - > - -
  • - -
  • - - <%= select_tag :challenge_score, options_for_select([100, 200]), :name => 'challenge[score]', :class => " fl", :style => "height: 40px; width:170px;" %> -
    - -
  • - -
    -
      - <% if @st == 0 %> -
    1. 如果学员查看了参考答案,则不能得到相应的经验值
    2. -
    3. 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+100经验值、+100金币
    4. - <% else %> -
    5. 如果学员答题错误,则不能得到相应的经验值
    6. -
    7. 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币
    8. - <% end %> -
    -
    -
    -
    -

    - -
    -
    -
  • - -
    - <% if params[:action] == "edit" && @challenge_tags.count > 0 %> - <% @challenge_tags.each do |tag| %> -
    - - -
    - <% end %> - <% end %> - -
    " id="add_shixun_skill"> - - -
    - +添加 -
    -
  • -

    -
    -
      - <% if @st == 0 %> -
    1. 学员未参考答案通过了本阶段的评测时将获得技能,否则不能获得技能
    2. - <% else %> -
    3. 学员答题正确将获得技能,否则不能获得技能
    4. - <% end %> -
    -
    -
    -
    - -
  • - 保存 - 取消 -
  • + <%= render :partial => "single_or_multiple_question" %>
    \ No newline at end of file diff --git a/app/views/challenges/_single_or_multiple_question.html.erb b/app/views/challenges/_single_or_multiple_question.html.erb new file mode 100644 index 000000000..5c76a2f99 --- /dev/null +++ b/app/views/challenges/_single_or_multiple_question.html.erb @@ -0,0 +1,397 @@ +
  • + 编辑 + 删除 +
  • +
    +
    +
  • + +
    + +
    +
  • + +
  • + + + + +
  • +
  • + + + + +
  • +
  • + + + + +
  • +
  • + + + + +
  • + +
    +
    +

    + +
    +
    + +
    +
    +

    + +
    +
    +
  • + + + > + + + + > + + + + > + +
  • + +
  • + + <%= select_tag :challenge_score, options_for_select([100, 200]), :name => 'challenge[score]', :class => " fl", :style => "height: 40px; width:170px;" %> +
    + +
  • + +
    +
      + <% if @st == 0 %> +
    1. 如果学员查看了参考答案,则不能得到相应的经验值
    2. +
    3. 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+100经验值、+100金币
    4. + <% else %> +
    5. 如果学员答题错误,则不能得到相应的经验值
    6. +
    7. 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币
    8. + <% end %> +
    +
    +
    +
    +

    + +
    +
    +
  • + +
    + <% if params[:action] == "edit" && @challenge_tags.count > 0 %> + <% @challenge_tags.each do |tag| %> +
    + + +
    + <% end %> + <% end %> + +
    " id="add_shixun_skill"> + + +
    + +添加 +
    +
  • +

    +
    +
      + <% if @st == 0 %> +
    1. 学员未参考答案通过了本阶段的评测时将获得技能,否则不能获得技能
    2. + <% else %> +
    3. 学员答题正确将获得技能,否则不能获得技能
    4. + <% end %> +
    +
    +
    +
    + +
  • + 保存 + 取消 +
  • + \ No newline at end of file diff --git a/app/views/challenges/_task_edit_page.html.erb b/app/views/challenges/_task_edit_page.html.erb new file mode 100644 index 000000000..06295a539 --- /dev/null +++ b/app/views/challenges/_task_edit_page.html.erb @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app/views/challenges/_task_pass_form.html.erb b/app/views/challenges/_task_pass_form.html.erb index 380b9f855..c765a69d4 100644 --- a/app/views/challenges/_task_pass_form.html.erb +++ b/app/views/challenges/_task_pass_form.html.erb @@ -34,66 +34,6 @@

    - <% if false %> - <% if @st != 0 %> - <% if params[:action] == "edit" && @challenge.challenge_questions.count > 0 %> - <% @challenge.challenge_questions.each_with_index do |question, index| %> -
  • - - - - -
  • - <% end %> - <% elsif @st == 2 %> -
  • - - - - -
  • -
  • - - - - -
  • - <% else %> -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • - <% end %> - - <% end %> - <% end %>
  • 保存 <% if params[:action] == "new" %> diff --git a/app/views/challenges/edit.html.erb b/app/views/challenges/edit.html.erb index 65873a499..f24364ce3 100644 --- a/app/views/challenges/edit.html.erb +++ b/app/views/challenges/edit.html.erb @@ -83,7 +83,7 @@ <% else %> - <%= render :partial => "choose_type" %> + <%= render :partial => "choose_type" %> <% end %>
    diff --git a/app/views/challenges/edit.js.erb b/app/views/challenges/edit.js.erb new file mode 100644 index 000000000..ed1fdeb98 --- /dev/null +++ b/app/views/challenges/edit.js.erb @@ -0,0 +1 @@ +$("#task_show_page").html('<%= j(render :partial => "task_edit_page") %>'); \ No newline at end of file From d2f3a460c7a736f2c9e26e8e0b5b180d6fa7e608 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 6 Sep 2017 09:40:52 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/challenges/_choose_type.html.erb | 2 ++ app/views/challenges/_single_or_multiple_question_show.html.erb | 0 2 files changed, 2 insertions(+) create mode 100644 app/views/challenges/_single_or_multiple_question_show.html.erb diff --git a/app/views/challenges/_choose_type.html.erb b/app/views/challenges/_choose_type.html.erb index 35ed85afc..5590def69 100644 --- a/app/views/challenges/_choose_type.html.erb +++ b/app/views/challenges/_choose_type.html.erb @@ -37,6 +37,8 @@
    <%= render :partial => "single_or_multiple_question" %>
    + + <%= render :partial => 'single_or_multiple_question_show'%>
    \ No newline at end of file From 9c36affeec50cb22012c38e54189686399850f20 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 6 Sep 2017 14:42:31 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E5=8D=95=E9=80=89=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 18 +- app/views/challenges/_choose_type.html.erb | 54 ++- .../_single_or_multiple_question.html.erb | 420 +++++++++--------- app/views/challenges/_task_pass_form.html.erb | 42 +- .../challenges/add_choose_question.js.erb | 1 + app/views/challenges/edit.html.erb | 2 +- config/routes.rb | 2 + 7 files changed, 304 insertions(+), 235 deletions(-) create mode 100644 app/views/challenges/add_choose_question.js.erb diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 834e6b302..7bbef79a1 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,8 +2,8 @@ class ChallengesController < ApplicationController layout "base_shixun" before_filter :check_authentication - before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation] - before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation] + before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_or_edit_choose_question] + before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_or_edit_choose_question] before_filter :build_challege_from_params, :only => [:new, :create] before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create] before_filter :allowed_view, :only => [:show] @@ -103,6 +103,20 @@ class ChallengesController < ApplicationController end end + def new_or_edit_choose_question + + respond_to do |format| + format.js + end + end + + def add_choose_question + @type = params[:type].to_i + respond_to do |format| + format.js + end + end + def destroy next_challenges = @shixun.challenges.where("position > #{@challenge.position}") next_challenges.update_all("position = position - 1") diff --git a/app/views/challenges/_choose_type.html.erb b/app/views/challenges/_choose_type.html.erb index 5590def69..a4e320270 100644 --- a/app/views/challenges/_choose_type.html.erb +++ b/app/views/challenges/_choose_type.html.erb @@ -35,7 +35,7 @@
    - <%= render :partial => "single_or_multiple_question" %> + <%#= render :partial => "single_or_multiple_question" %>
    <%= render :partial => 'single_or_multiple_question_show'%> @@ -50,5 +50,57 @@ sequenceDiagram: true // 默认不解析 }); }); + //添加单选、多选tab + $(".addoption-btn").on("click",function(){ + var length= $(".stage-part-2").find(".nav_check_item li").length; + if(length<11){ + var title=$(this).html(); + var type = title.indexOf("多选")>0 ? 2 : 1; + if(title.indexOf("多选")>0){//多选 + title="多选题"; + }else{ + title="单选题"; + } + var li_con=length+"."+title+""; + var html="
  • "+li_con+"
  • "; + $(".stage-part-2").find(".nav_check_item li").removeClass("check_nav"); + $(".stage-part-2").find(".nav_check_item li").eq(length-1).after(html); + $.ajax({ + url: "<%= add_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun) %>", + dateType: "script", + data: {type: type}, + success: function(){ + + } + }) + } + // editor_tigan(); + }); + //删除单选、多选tab + $(".deloption-btn").on("click",function(){ + var index=0; + for(var i=1;i<$(".stage-part-2").find(".nav_check_item li").length;i++){ + var length=$(".stage-part-2").find(".nav_check_item li").length; + var item=$(".stage-part-2").find(".nav_check_item li"); + if(item.eq(i).hasClass("check_nav")){ + if(length>1){ + item.eq(0).addClass("check_nav"); + item.eq(i).remove(); + } + + } + } + for(var i=1;i<$(".stage-part-2").find(".nav_check_item li").length;i++){ + var item=$(".stage-part-2").find(".nav_check_item li"); + item.eq(i).html(i+"."+item.eq(i).find("span").html()+""); + } + }) + //第二个ul tab的切换事件 + $(".stage-part-2").find(".nav_check_item li").live("click",function(){ + if($(".nav_check_item li").length>1){ + $(".nav_check_item li").removeClass("check_nav"); + $(this).addClass("check_nav"); + } + }) \ No newline at end of file diff --git a/app/views/challenges/_single_or_multiple_question.html.erb b/app/views/challenges/_single_or_multiple_question.html.erb index 5c76a2f99..19b9b14fa 100644 --- a/app/views/challenges/_single_or_multiple_question.html.erb +++ b/app/views/challenges/_single_or_multiple_question.html.erb @@ -1,77 +1,76 @@ -
  • - 编辑 - 删除 -
  • -
    -
    -
  • - -
    - +<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> +<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %> +<%= labelled_form_for @challenge, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun), :html => {:id => "challenge_choose_update", :remote => true } do |f| %> +
  • + 编辑 + 删除 +
  • +
    +
    +
  • + +
    + +
    +
  • + +
  • + + + + +
  • +
  • + + + + +
  • +
  • + + + + +
  • +
  • + + + + +
  • +
      +
    • + + +
    • + +
    • +
    +
    +

    + +
  • + +
    + +
    +

    +

  • - -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • -
  • - - - - -
  • - -
    -
    -

    - -
    -
    - -
    -
    -

    - -
    -
    -
  • - +

    + +
    +
    +
  • + > @@ -85,154 +84,157 @@
  • -
  • - - <%= select_tag :challenge_score, options_for_select([100, 200]), :name => 'challenge[score]', :class => " fl", :style => "height: 40px; width:170px;" %> -
    - -
  • +
  • + + <%= select_tag :challenge_score, options_for_select([100, 200]), :name => 'challenge[score]', :class => " fl", :style => "height: 40px; width:170px;" %> +
    + +
  • -
    -
      - <% if @st == 0 %> -
    1. 如果学员查看了参考答案,则不能得到相应的经验值
    2. -
    3. 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+100经验值、+100金币
    4. - <% else %> +
      +
      1. 如果学员答题错误,则不能得到相应的经验值
      2. 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币
      3. - <% end %> -
      -
      -
    -
    -

    - -
    -
    -
  • - -
    - <% if params[:action] == "edit" && @challenge_tags.count > 0 %> - <% @challenge_tags.each do |tag| %> -
    - - -
    - <% end %> - <% end %> - -
    " id="add_shixun_skill"> - - + +
    +
    +
  • +

    + +
    +
    +
  • + +
    + <% if params[:action] == "edit" && @challenge_tags.count > 0 %> + <% @challenge_tags.each do |tag| %> +
    + + +
    + <% end %> + <% end %> +
    " id="add_shixun_skill"> + + +
    + +添加 +
    +
  • +

    +
    +
      +
    1. 学员答题正确将获得技能,否则不能获得技能
    2. +
    - +添加
    - -

    -
    -
      - <% if @st == 0 %> -
    1. 学员未参考答案通过了本阶段的评测时将获得技能,否则不能获得技能
    2. - <% else %> -
    3. 学员答题正确将获得技能,否则不能获得技能
    4. - <% end %> -
    -
    -
    -
  • - 保存 - 取消 -
  • +
  • + 保存 + 取消 +
  • +<% end %> +<%= form_tag url_for(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position)), :remote => true, :id => 'challenge_choose_update' do |f| %> +<%#= form_tag(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), format: :js ,method: :post, id: "challenge_choose_update", remote: true) do |f| %> +<%#= form_for(@challenge, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :remote => true, :method => "post",:html => {:id => 'challenge_choose_update'}) do |f| %> +<%#= form_for :challenge_choose, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :html => {:id => "challenge_choose_update", :remote => true, :method => :post} do |f| %>
  • 编辑 删除 @@ -10,17 +21,10 @@
  • - +
    +
  • -
  • @@ -52,6 +56,7 @@
  • +
    @@ -60,7 +65,7 @@
  • - +

    @@ -82,7 +87,8 @@ > -
  • + +
  • @@ -129,9 +135,8 @@ -
  • - 保存 + 保存 取消
  • <% end %> @@ -254,7 +259,7 @@ var nSkill = $(".knowledge_frame"); console.log(nSkill.length); if (nSkill.length > 0){ - $("#challenge_skill_update").submit(); //当增加或者保存技能标签以后执行保存操作 + //$("#challenge_skill_update").submit(); //当增加或者保存技能标签以后执行保存操作 }else{ $("#stage_name_notice").show(); } @@ -264,7 +269,7 @@ // 获取父节点的id var obj = $(thisObj).parent(); $(obj).remove(); - $("#challenge_skill_update").submit(); + //$("#challenge_skill_update").submit(); } @@ -346,6 +351,7 @@ if($(".check-option-bg").length>0){ for(var i=0;i<$(".check-option-bg").length;i++){ $("#current-option").html($("#current-option").html()+$(".check-option-bg").eq(i).html()); + $("input[name='standard_answer']").val($(".check-option-bg").eq(i).html()) } }else{ $("#current-option").html("请点击正确选项"); @@ -396,4 +402,93 @@ var lens = answer.length; return lens; } + // 根据难易程度设置不同的奖励经验值(适用新建与编辑模式) + var list = $('input:radio[name="challenge[difficulty]"]:checked').val(); // 获取select的索引值 + var index = parseInt(<%= @st == 0 ? 1 : 10 %>); // 单选 与 多选分数系数 + if(list == 1){ + $("#challenge_score").empty(); + for(var i = 100; i <= 200; i += 100){ + $("#challenge_score").append(""); + } + }else if(list == 2){ + $("#challenge_score").empty(); + for(var i = 300; i <= 600; i += 100){ + $("#challenge_score").append(""); + } + }else if(list == 3){ + $("#challenge_score").empty(); + for(var i= 700; i <= 1000; i += 100){ + $("#challenge_score").append(""); + } + } + $("#challenge_score").find("option[value='<%= @challenge.score %>']").attr("selected",true); // 设置option默认值 + $("#challenge_difficulty_1").click(function(){ + $("#challenge_score").empty(); + for(var i = 100; i <= 200; i += 100){ + $("#challenge_score").append(""); + } + }); + $("#challenge_difficulty_2").click(function(){ + $("#challenge_score").empty(); + for(var i = 300; i <= 600; i += 100){ + $("#challenge_score").append(""); + } + }); + $("#challenge_difficulty_3").click(function(){ + $("#challenge_score").empty(); + for(var i= 700; i <= 1000; i += 100){ + $("#challenge_score").append(""); + } + }); + function challenge_score_update(){ + if($("#challenge_score").val().trim()==""){ + $("#challenge_score").focus(); + $("#new_shixun_score").show(); + }else{ + $('#challenge_score_update').submit(); + } + } + $("#score_cancel").click(function(){ + $("#scoring_edit").hide(); + $("#scroe_show").show(); + }); + + + function challenge_choose_update(st){ + set_choice_answer(); + var error = $("#choice_error_tip"); + if($('#challenge_choose_subject textarea').val().trim() == ""){ + $("#challenge_choose_subject textarea").focus(); + $("#new_shixun_name").show(); + }else if($("#challenge_choose_answer textarea").val().trim() == ""){ + $("#challenge_choose_answer textarea").focus(); + $("#new_shixun_pass").show(); + }else if(judge_choice_contents()){ + error.html("选项不能为空").show(); + }else{ + if(st == "1"){ + if(judge_choice_contents()) { + error.html("选项内容不能为空").show(); + }else if(choice_num() < 2){ + error.html("单选题选项不能少于2个").show(); + }else if(judge_choice_answer() == 0){ + error.html("请设置答案").show(); + }else{ + $('#challenge_choose_update').submit(); + } + }else if(st == "2"){ + if(judge_choice_contents()) { + error.html("选项内容不能为空").show(); + }else if(choice_num() < 3){ + error.html("多选题选项不能少于3个").show(); + }else if(judge_choice_answer() < 2){ + error.html("答案不能少于2个").show(); + }else{ + $('#challenge_choose_update').submit(); + } + }else{ + $('#challenge_choose_update').submit(); + } + } + } \ No newline at end of file diff --git a/app/views/challenges/new_or_edit_choose_question.js.erb b/app/views/challenges/new_or_edit_choose_question.js.erb new file mode 100644 index 000000000..b5c714994 --- /dev/null +++ b/app/views/challenges/new_or_edit_choose_question.js.erb @@ -0,0 +1 @@ +$("#task_content").html("<%= j(render :partial => 'single_or_multiple_question_show')%>"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b99775080..31c8d1757 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,7 +117,7 @@ RedmineApp::Application.routes.draw do get 'index_down' match 'update_evaluation', :via => [:get, :post, :put] match 'add_choose_question', :via => [:get, :post] - match 'new_or_edit_choose_question', :via => [:get, :post] + post 'new_or_edit_choose_question' end end From 87612ef6ee585763c9b507c07b0d3e98cc3e7e17 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 7 Sep 2017 10:26:54 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E8=A7=A3=E5=86=B3post=E8=AF=B7=E6=B1=824?= =?UTF-8?q?06=E4=B8=8D=E6=8E=A5=E5=8F=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 6 ++++++ app/views/challenges/_single_or_multiple_question.html.erb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index b84af8d4a..4ec00f17b 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -9,6 +9,8 @@ class ChallengesController < ApplicationController before_filter :allowed_view, :only => [:show] before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation] before_filter :find_shixun_language, :only => [:show, :new, :edit] + before_filter :default_format_js, only: :new_or_edit_choose_question + #skip_before_filter :verify_authenticity_token, :only => [:new_or_edit_choose_question] include ApplicationHelper @@ -315,4 +317,8 @@ class ChallengesController < ApplicationController @language = language_switch language end + def default_format_js + response.headers['content--type'] = 'text/javascript' + request.format = 'js' + end end diff --git a/app/views/challenges/_single_or_multiple_question.html.erb b/app/views/challenges/_single_or_multiple_question.html.erb index 3ff71e8bd..9442a9883 100644 --- a/app/views/challenges/_single_or_multiple_question.html.erb +++ b/app/views/challenges/_single_or_multiple_question.html.erb @@ -8,7 +8,7 @@ -<%= form_tag url_for(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position)), :remote => true, :id => 'challenge_choose_update' do |f| %> +<%= form_tag(url_for(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position)), :remote => true, :id => 'challenge_choose_update') do |f| %> <%#= form_tag(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), format: :js ,method: :post, id: "challenge_choose_update", remote: true) do |f| %> <%#= form_for(@challenge, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :remote => true, :method => "post",:html => {:id => 'challenge_choose_update'}) do |f| %> <%#= form_for :challenge_choose, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :html => {:id => "challenge_choose_update", :remote => true, :method => :post} do |f| %> From 6cc88c874d1ce37bf7dde78439e2b47c0ae8b278 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 7 Sep 2017 19:16:55 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 +- .../_single_or_multiple_question.html.erb | 83 ++++++++----------- .../challenges/new_choose_question.js.erb | 1 + ...d_challenge_choose_id_to_challenge_tags.rb | 5 ++ 4 files changed, 43 insertions(+), 50 deletions(-) create mode 100644 app/views/challenges/new_choose_question.js.erb create mode 100644 db/migrate/20170907100131_add_challenge_choose_id_to_challenge_tags.rb diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 4ec00f17b..c55498257 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -9,7 +9,7 @@ class ChallengesController < ApplicationController before_filter :allowed_view, :only => [:show] before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation] before_filter :find_shixun_language, :only => [:show, :new, :edit] - before_filter :default_format_js, only: :new_or_edit_choose_question + #before_filter :default_format_js, only: :new_or_edit_choose_question #skip_before_filter :verify_authenticity_token, :only => [:new_or_edit_choose_question] @@ -122,14 +122,12 @@ class ChallengesController < ApplicationController respond_to do |format| format.js - format.html end rescue Exception => e flash[:error] = "#{e.message}" redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun) raise ActiveRecord::Rollback end - end end diff --git a/app/views/challenges/_single_or_multiple_question.html.erb b/app/views/challenges/_single_or_multiple_question.html.erb index 9442a9883..330554ceb 100644 --- a/app/views/challenges/_single_or_multiple_question.html.erb +++ b/app/views/challenges/_single_or_multiple_question.html.erb @@ -8,10 +8,8 @@ -<%= form_tag(url_for(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position)), :remote => true, :id => 'challenge_choose_update') do |f| %> -<%#= form_tag(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), format: :js ,method: :post, id: "challenge_choose_update", remote: true) do |f| %> -<%#= form_for(@challenge, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :remote => true, :method => "post",:html => {:id => 'challenge_choose_update'}) do |f| %> -<%#= form_for :challenge_choose, :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :html => {:id => "challenge_choose_update", :remote => true, :method => :post} do |f| %> +<%= form_for("", :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :remote => true, :html => {:id => 'challenge_choose_update'}) do |f| %> +<%#= form_tag(url_for(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position)), :remote => true, :id => 'challenge_choose_update') do |f| %>
  • 编辑 删除 @@ -136,7 +134,7 @@
  • - 保存 + 保存 取消
  • <% end %> @@ -205,44 +203,8 @@ imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>"//url }); - /* - function latex_event(){ - $("#challenge_choose_answer [type=\"latex\"]").bind("click", function(){ - alert(2); - choose_answer_editormd.cm.replaceSelection("```latex"); - choose_answer_editormd.cm.replaceSelection("\n"); - choose_answer_editormd.cm.replaceSelection("\n"); - choose_answer_editormd.cm.replaceSelection("```"); - var __Cursor = choose_answer_editormd.cm.getDoc().getCursor(); - choose_answer_editormd.cm.setCursor(__Cursor.line-1, 0); - }); - $("#challenge_choose_answer [type=\"inline\"]").bind("click", function(){ - choose_answer_editormd.cm.replaceSelection("$$$$"); - var __Cursor = choose_answer_editormd.cm.getDoc().getCursor(); - choose_answer_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2); - choose_answer_editormd.cm.focus(); - }); - $("#challenge_choose_subject [type=\"latex\"]").bind("click", function(){ - alert(1); - subject_editormd.cm.replaceSelection("```latex"); - subject_editormd.cm.replaceSelection("\n"); - subject_editormd.cm.replaceSelection("\n"); - subject_editormd.cm.replaceSelection("```"); - var __Cursor = subject_editormd.cm.getDoc().getCursor(); - subject_editormd.cm.setCursor(__Cursor.line-1, 0); - }); - $("#challenge_choose_subject [type=\"inline\"]").bind("click", function(){ - subject_editormd.cm.replaceSelection("$$$$"); - var __Cursor = subject_editormd.cm.getDoc().getCursor(); - subject_editormd.cm.setCursor(__Cursor.line, __Cursor.ch-2); - subject_editormd.cm.focus(); - }); - $("[type=\"inline\"]").attr("title", "行内公式"); - $("[type=\"latex\"]").attr("title", "多行公式"); - }*/ //技能标签 var SnSkill = $(".knowledge_frame").length; - function add_tag(){ var num = $(".task-bd-grey").children('div').length; var val = $(".task-tag-input").val().trim(); @@ -440,20 +402,20 @@ $("#challenge_score").append(""); } }); - function challenge_score_update(){ +/* function challenge_score_update(){ if($("#challenge_score").val().trim()==""){ $("#challenge_score").focus(); $("#new_shixun_score").show(); }else{ $('#challenge_score_update').submit(); } - } + }*/ + $("#score_cancel").click(function(){ $("#scoring_edit").hide(); $("#scroe_show").show(); }); - function challenge_choose_update(st){ set_choice_answer(); var error = $("#choice_error_tip"); @@ -474,7 +436,16 @@ }else if(judge_choice_answer() == 0){ error.html("请设置答案").show(); }else{ - $('#challenge_choose_update').submit(); + $.ajax({ + url: "<%= new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position) %>", + data: $("#challenge_choose_update").serialize(), + type: 'POST', + dataType: "script", + remote: true, + success: function(){ + + } + }); } }else if(st == "2"){ if(judge_choice_contents()) { @@ -484,10 +455,28 @@ }else if(judge_choice_answer() < 2){ error.html("答案不能少于2个").show(); }else{ - $('#challenge_choose_update').submit(); + $.ajax({ + url: "<%= new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position) %>", + data: $("#challenge_choose_update").serialize(), + dataType: "script", + type: 'POST', + remote: true, + success: function(){ + + } + }); } }else{ - $('#challenge_choose_update').submit(); + $.ajax({ + url: "<%= new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position) %>", + data: $("#challenge_choose_update").serialize(), + dataType: "script", + type: 'POST', + remote: true, + success: function(){ + + } + }); } } } diff --git a/app/views/challenges/new_choose_question.js.erb b/app/views/challenges/new_choose_question.js.erb new file mode 100644 index 000000000..b5c714994 --- /dev/null +++ b/app/views/challenges/new_choose_question.js.erb @@ -0,0 +1 @@ +$("#task_content").html("<%= j(render :partial => 'single_or_multiple_question_show')%>"); \ No newline at end of file diff --git a/db/migrate/20170907100131_add_challenge_choose_id_to_challenge_tags.rb b/db/migrate/20170907100131_add_challenge_choose_id_to_challenge_tags.rb new file mode 100644 index 000000000..43eb8456f --- /dev/null +++ b/db/migrate/20170907100131_add_challenge_choose_id_to_challenge_tags.rb @@ -0,0 +1,5 @@ +class AddChallengeChooseIdToChallengeTags < ActiveRecord::Migration + def change + add_column :challenge_tags, :challenge_question_id, :integer + end +end From a27f10d884b255d3c6aa112577f1b027f09e3f5c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 12 Sep 2017 09:05:51 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=9A=84?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=92=8C=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 41 +++++++---- app/models/challenge_question.rb | 2 +- app/models/challenge_tag.rb | 2 +- .../_single_or_multiple_question.html.erb | 15 ++-- ..._single_or_multiple_question_show.html.erb | 72 +++++++++++-------- config/routes.rb | 2 +- ...hallenge_question_id_for_challenge_tags.rb | 8 +++ 7 files changed, 89 insertions(+), 53 deletions(-) create mode 100644 db/migrate/20170911033152_modify_challenge_question_id_for_challenge_tags.rb diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index c55498257..0a8010b9f 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,8 +2,8 @@ class ChallengesController < ApplicationController layout "base_shixun" before_filter :check_authentication - before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_or_edit_choose_question] - before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_or_edit_choose_question] + before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question] + before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question] before_filter :build_challege_from_params, :only => [:new, :create] before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create] before_filter :allowed_view, :only => [:show] @@ -106,19 +106,36 @@ class ChallengesController < ApplicationController end end - def new_or_edit_choose_question + def new_choose_question + logger.info("##########") ActiveRecord::Base.transaction do begin -=begin - @challenge_choose = ChallengeChoose.new(params[:choose]) - @challenge_choose.challenge_id = @challenge.id + logger.info("@@@@@") + @challenge_choose = ChallengeChoose.new + logger.info("----") + @challenge_choose.challenge_id = @challenge.id + @challenge_choose.subject = params[:choose][:subject] + @challenge_choose.answer = params[:choose][:answer] @challenge_choose.standard_answer = params[:standard_answer] - @challenge_choose.score = params[:challenge][:score].to_i - @challenge_choose.difficult = params[:challenge][:difficulty].to_i - @challenge_choose.position = params[:position].to_i - @challenge_choose.type = params[:type].to_i - @challenge_choose.save! -=end + @challenge_choose.score = params[:challenge][:score].to_i + @challenge_choose.difficult = params[:challenge][:difficulty].to_i + @challenge_choose.position = params[:position].to_i + @challenge_choose.type = params[:type].to_i + logger.info("*****") + if @challenge_choose.save! + logger.info("11111") + # 创建选项 + params[:question][:cnt].each_with_index do |test, index| + answer = params[:choice][:answer][index] == "0" ? false : true + ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer) + end + # 创建单选多选的技能标签 + unless params[:knowledge].blank? + params[:knowledge][:input].each do |input| + ChallengeTag.create(:name => input, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id) + end + end + end respond_to do |format| format.js diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb index 9d9615c54..3540330b7 100644 --- a/app/models/challenge_question.rb +++ b/app/models/challenge_question.rb @@ -2,5 +2,5 @@ class ChallengeQuestion < ActiveRecord::Base # 选择题的选项内容 belongs_to :challenge_choose # right_key 选项是否是答案, position 选项的位置 - attr_accessible :challenge_choose_id, :option_name, :position + attr_accessible :challenge_choose_id, :option_name, :position, :right_key end diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb index a300ac30d..35b3f5be7 100644 --- a/app/models/challenge_tag.rb +++ b/app/models/challenge_tag.rb @@ -1,5 +1,5 @@ class ChallengeTag < ActiveRecord::Base - attr_accessible :challenge_id, :name + attr_accessible :challenge_id, :name, :challenge_choose_id belongs_to :challenge belongs_to :challenge_choose end diff --git a/app/views/challenges/_single_or_multiple_question.html.erb b/app/views/challenges/_single_or_multiple_question.html.erb index 330554ceb..980d7c895 100644 --- a/app/views/challenges/_single_or_multiple_question.html.erb +++ b/app/views/challenges/_single_or_multiple_question.html.erb @@ -8,7 +8,7 @@ -<%= form_for("", :url => new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position), :remote => true, :html => {:id => 'challenge_choose_update'}) do |f| %> +<%= form_for("", :url => "", :html => {:id => 'challenge_choose_update'}) do |f| %> <%#= form_tag(url_for(new_or_edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :type => @type, :position => @position)), :remote => true, :id => 'challenge_choose_update') do |f| %>
  • 编辑 @@ -139,7 +139,7 @@
  • <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 31c8d1757..ccff28922 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,7 +117,7 @@ RedmineApp::Application.routes.draw do get 'index_down' match 'update_evaluation', :via => [:get, :post, :put] match 'add_choose_question', :via => [:get, :post] - post 'new_or_edit_choose_question' + post 'new_choose_question' end end diff --git a/db/migrate/20170911033152_modify_challenge_question_id_for_challenge_tags.rb b/db/migrate/20170911033152_modify_challenge_question_id_for_challenge_tags.rb new file mode 100644 index 000000000..adfe808c6 --- /dev/null +++ b/db/migrate/20170911033152_modify_challenge_question_id_for_challenge_tags.rb @@ -0,0 +1,8 @@ +class ModifyChallengeQuestionIdForChallengeTags < ActiveRecord::Migration + def up + rename_column :challenge_tags, :challenge_question_id, :challenge_choose_id + end + + def down + end +end From 0a1e895dc21de54b9373e28e783b2abf1590952d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 12 Sep 2017 14:08:19 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E5=8D=95=E9=80=89=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E9=A2=98=E7=9A=84TPM=EF=BC=88=E5=88=9D=E7=89=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 24 +++-- app/views/challenges/_choose_type.html.erb | 16 +++- .../_single_or_multiple_question.html.erb | 92 ++++++++++--------- app/views/challenges/choose_type_show.js.erb | 1 + config/routes.rb | 1 + ...24832_modify_type_for_challenge_chooses.rb | 8 ++ 6 files changed, 86 insertions(+), 56 deletions(-) create mode 100644 app/views/challenges/choose_type_show.js.erb create mode 100644 db/migrate/20170912024832_modify_type_for_challenge_chooses.rb diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 0a8010b9f..b5b24de5c 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,8 +2,8 @@ class ChallengesController < ApplicationController layout "base_shixun" before_filter :check_authentication - before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question] - before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question] + before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show] + before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show] before_filter :build_challege_from_params, :only => [:new, :create] before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create] before_filter :allowed_view, :only => [:show] @@ -97,7 +97,7 @@ class ChallengesController < ApplicationController if challenge_pos < challenge_num @next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first end - @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if challenge_pos - 1 > 0 + @prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if (challenge_pos - 1) > 0 @tab = params[:tab].blank? ? 1 : params[:tab].to_i @editor = params[:editor] # 编辑模式 respond_to do |format| @@ -107,12 +107,9 @@ class ChallengesController < ApplicationController end def new_choose_question - logger.info("##########") ActiveRecord::Base.transaction do begin - logger.info("@@@@@") @challenge_choose = ChallengeChoose.new - logger.info("----") @challenge_choose.challenge_id = @challenge.id @challenge_choose.subject = params[:choose][:subject] @challenge_choose.answer = params[:choose][:answer] @@ -120,10 +117,8 @@ class ChallengesController < ApplicationController @challenge_choose.score = params[:challenge][:score].to_i @challenge_choose.difficult = params[:challenge][:difficulty].to_i @challenge_choose.position = params[:position].to_i - @challenge_choose.type = params[:type].to_i - logger.info("*****") + @challenge_choose.category = params[:category].to_i if @challenge_choose.save! - logger.info("11111") # 创建选项 params[:question][:cnt].each_with_index do |test, index| answer = params[:choice][:answer][index] == "0" ? false : true @@ -148,9 +143,18 @@ class ChallengesController < ApplicationController end end + def choose_type_show + @challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first + + respond_to do |format| + format.js + end + end + def add_choose_question - @type = params[:type].to_i + @category = params[:category].to_i @position = params[:position] + #@challenge_choose = @challenge.challenge_chooses respond_to do |format| format.js end diff --git a/app/views/challenges/_choose_type.html.erb b/app/views/challenges/_choose_type.html.erb index 6c7ab3a65..87960bc32 100644 --- a/app/views/challenges/_choose_type.html.erb +++ b/app/views/challenges/_choose_type.html.erb @@ -3,6 +3,13 @@
  • 本关任务
  • + <% @challenge.challenge_chooses.each_with_index do |choose, index| %> +
  • + + <%= (index + 1).to_s + (choose.category == 1 ? ".单选题" : ".多选题") %> + +
  • + <% end %> + 多选题 + 单选题 @@ -55,7 +62,7 @@ var length= $(".stage-part-2").find(".nav_check_item li").length; if(length<11){ var title=$(this).html(); - var type = title.indexOf("多选")>0 ? 2 : 1; + var category = title.indexOf("多选")>0 ? 2 : 1; if(title.indexOf("多选")>0){//多选 title="多选题"; }else{ @@ -68,9 +75,8 @@ $.ajax({ url: "<%= add_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun) %>", dateType: "script", - data: {type: type, position: length}, + data: {category: category, position: length}, success: function(){ - } }) } @@ -96,10 +102,10 @@ } }) //第二个ul tab的切换事件 - $(".stage-part-2").find(".nav_check_item li").live("click",function(){ + $(".stage-part-2").find(".nav_check_item li a").live("click",function(){ if($(".nav_check_item li").length>1){ $(".nav_check_item li").removeClass("check_nav"); - $(this).addClass("check_nav"); + $(this).parent().addClass("check_nav"); } }) diff --git a/app/views/challenges/_single_or_multiple_question.html.erb b/app/views/challenges/_single_or_multiple_question.html.erb index 980d7c895..a10f520bb 100644 --- a/app/views/challenges/_single_or_multiple_question.html.erb +++ b/app/views/challenges/_single_or_multiple_question.html.erb @@ -2,7 +2,7 @@ <%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %> + + +<% if false %>
    -

    " id="correct_tip"> - 正确 -

    -

    " id="error_tip"> - 错误 -

    1.单选题

    应在下列程序划线处填入的语句是()

    
             
    - <% @game_challenge.challenge_questions.each_with_index do |question, i| %> -
    " onclick="choice_answer('<%= @st %>', this)"> - - - - - -
    - <%= (question.position + 65).chr %>. -
    -

    <%= question.option_name %>

    -
    -
    -
    + <% @game_challenge.challenge_chooses.each do |choose| %> + <% choose.challenge_questions.each_with_index do |question, i| %> +
    " onclick="choice_answer('<%= @st %>', this)"> + + + + + +
    + <%= (question.position + 65).chr %>. +
    +

    <%= question.option_name %>

    +
    +
    +
    + <% end %> <% end %>

    @@ -39,3 +108,4 @@
    +<% end %> \ No newline at end of file diff --git a/app/views/games/_game_choose_results.html.erb b/app/views/games/_game_choose_results.html.erb new file mode 100644 index 000000000..a69854400 --- /dev/null +++ b/app/views/games/_game_choose_results.html.erb @@ -0,0 +1,44 @@ +<%= content_for(:header_tags) do %> + <%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %> +<% end %> + +
    +
    +
    +
    +
    +
    +

    + 3/5 +

    +

    + 5/5 全部通过 +

    + <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> +
    +
    + + 题目<%= index + 1 %> + + + +
    +
    +
      +
    • 正确选项:<%= choose.standard_answer %>
    • +
    • 你的选项:789
    • +
    +
    +
    + <% end %> +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/games/_game_show.html.erb b/app/views/games/_game_show.html.erb index 0daa13b4b..875f33c22 100644 --- a/app/views/games/_game_show.html.erb +++ b/app/views/games/_game_show.html.erb @@ -92,7 +92,7 @@ <% if @st != 0 %> <%= render :partial => "games/choice_question" %> - <% else %> + <% else %>
    diff --git a/app/views/layouts/base_myshixun.html.erb b/app/views/layouts/base_myshixun.html.erb index 2b5e6831a..f633e36f4 100644 --- a/app/views/layouts/base_myshixun.html.erb +++ b/app/views/layouts/base_myshixun.html.erb @@ -9,7 +9,7 @@ <%= favicon %> <%= javascript_heads %> <%= heads_for_theme %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','css/taskstyle', 'css/project','css/popup','repository','css/gantt','css/cssPlus-v.0.2-build', 'css/edu-common','css/edu-public', 'css/edu-popup', 'css/edu-tooltipster' %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','css/taskstyle', 'css/project','css/popup','repository','css/gantt','css/cssPlus-v.0.2-build', 'css/edu-common','css/edu-public', 'css/edu-popup', 'css/edu-tooltipster', 'css/magic-check' %> <%= javascript_include_tag 'edu/application', 'edu/edu_tpi' %> <%= call_hook :view_layouts_base_html_head %> diff --git a/public/javascripts/edu/edu_tpi.js b/public/javascripts/edu/edu_tpi.js index d31ae9a57..51d48c332 100644 --- a/public/javascripts/edu/edu_tpi.js +++ b/public/javascripts/edu/edu_tpi.js @@ -143,11 +143,11 @@ function open_answer(game, myshixun){ // 选择题选择答案 function choice_answer(st, nThis){ - if(st == "1"){ + if(st == "2"){ //$(nThis).hasClass("card-check") ? $(nThis).removeClass("card-check") : $(nThis).addClass("card-check"); $(nThis).toggleClass("card-check"); $(nThis).toggleClass("color_white"); - } else if (st == "2"){ + } else if (st == "1"){ var choice = $(".color_white"); choice.removeClass("card-check"); choice.removeClass("color_white"); From 7bb99cee44a69666dfab548f827c69aea37087ee Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Wed, 13 Sep 2017 17:10:39 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E6=98=BE=E7=A4=BA=E5=92=8C=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/games/_choice_question.html.erb | 73 +++++++++++++++++------ 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/app/views/games/_choice_question.html.erb b/app/views/games/_choice_question.html.erb index 41aa897ae..badbf1536 100644 --- a/app/views/games/_choice_question.html.erb +++ b/app/views/games/_choice_question.html.erb @@ -14,30 +14,43 @@
    <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %>

    <%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>

    -
    +
    - <% choose.challenge_questions.each_with_index do |question, i| %> -
    
    -                
    -
    " onclick=""> - - <% if choose.category == 1 %> - - <% else %> - - - <% end %> -
    - <%= (question.position + 65).chr %>. +
    + <% choose.challenge_questions.each_with_index do |question, i| %> +

    + + <% if choose.category == 1 %> + + <% else %> + + + <% end %> + + +

    + <% end %> + +
    + <% end %> +

    @@ -67,6 +80,30 @@ } }); }); + + $(function(){ + $(".problem_single p input").live("change",function(event){ + var $this=$(this).parents(".problem_single").find("input[name='user_answer']"); + var value=""; + if($(this).attr("category")=="1"){ + value=""; + //alert($(this).siblings("label").find("span").html()); + if($(this).attr("checked")=="checked"){ + value=$(this).siblings("label").find("span").html(); + } + }else{ + var p=$(this).parents(".problem_single").find("p"); + value=""; + for(var i=0;i< p.length;i++){ + if(p.eq(i).find("input").attr("checked")=="checked"){ + //alert(p.eq(i).find("input").siblings("label").find("span").html()); + value+=p.eq(i).find("input").siblings("label").find("span").html(); + } + } + } + $this.val(value); + }) + }) From 2c7e5d1f38b386ccb2001f88278da1ff59e7f85b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 14 Sep 2017 17:30:58 +0800 Subject: [PATCH 13/17] =?UTF-8?q?TPI=E5=8D=95=E9=80=89=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 72 ++++++++----------- app/models/challenge.rb | 21 ++++++ app/views/games/_choice_question.html.erb | 33 +++++---- app/views/games/_code_actions.html.erb | 60 ++++------------ app/views/games/_game_choose_results.html.erb | 43 +++++++---- app/views/games/_game_show.html.erb | 7 +- app/views/games/show.js.erb | 12 ++++ ..._modify_correct_type_for_choose_outputs.rb | 8 +++ 8 files changed, 134 insertions(+), 122 deletions(-) create mode 100644 db/migrate/20170914024926_modify_correct_type_for_choose_outputs.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 00e9e52d9..f2fdb4e22 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -296,55 +296,41 @@ class GamesController < ApplicationController end # 选择题评测(选择题不需要重新评测) + # score 获得金币数 tag_count 技能数 right用户是否全对 answer_right全部选择题的正确性 def evaluating_choice - - if false - @game_challenge = @game.challenge - user_answer = params[:answer] - correct = true - score = 0 - tag_count = 0 - if !user_answer.blank? - if user_answer.split("").count != @game_challenge.challenge_questions.where(:right_key => true).count - correct = false - else - user_answer.split("").each do |answer| - question = @game_challenge.challenge_questions.where(:position => answer.to_i).first - unless question.right_key - correct = false - break - end - end - end - else - correct = false + @game_challenge = @game.challenge + @challenges = Challenge.where(:shixun_id => @myshixun.shixun_id) + @shixun = @myshixun.shixun + score = 0 + tag_count = 0 + @right = true + answer_right = [] + @game_challenge.challenge_chooses.each_with_index do |choose, index| + correct = (params[:answer][index] == choose.standard_answer) ? true : false + if choose.choose_outputs.blank? + ChooseOutputs.create(:challenge_choose_id => choose.id, :user_id => User.current.id, :answer => params[:answer][index], :correct => correct) end - @game.update_attributes(:status => 2, :end_time => Time.now) - had_done = @game.had_done - shixun = @myshixun.shixun - if shixun.status > 1 && !@game.answer_open + if @shixun.status > 1 && !@game.answer_open if correct - #User.current.update_attributes(:grade => (User.current.grade + @game.challenge.score), :experience => (User.current.experience + @game.challenge.score)) - reward_grade(@game.user, @game.id, 'Game', @game_challenge.score) - reward_experience(@game.user, @game.id, 'Game', @game_challenge.score) - @game.update_attribute(:final_score, @game_challenge.score) - score = @game_challenge.score - tag_count = @game_challenge.challenge_tags.count - else - score = "+0" - tag_count = 0 + score += choose.score + tag_count += choose.challenge_tags.count end - elsif shixun.status > 1 && @game.answer_open - score = -@game_challenge.score.to_i - tag_count = 0 - else - score = "+0" - tag_count = 0 + elsif @shixun.status > 1 && @game.answer_open + score -= choose.score end - if @game.outputs.blank? - Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct) + unless correct + @right = false end - render :json => {correct: correct, had_done: had_done, :grade => User.where(:id => User.current.id).first.grade, score: score, tag_count: tag_count} + answer_right << correct + end + @game.update_attributes(:status => 2, :end_time => Time.now) + @had_done = @game.had_done + reward_grade(@game.user, @game.id, 'Game', score) + reward_experience(@game.user, @game.id, 'Game', score) + @game.update_attribute(:final_score, score) + + respond_to do |format| + format.js{redirect_to myshixun_game_path(@game, :myshixun_id => @myshixun, :choose => 1)} end end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 7efd0c6ba..128a64d8b 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -28,6 +28,27 @@ class Challenge < ActiveRecord::Base str end + def choose_correct_num + num = 0 + self.challenge_chooses.each do |choose| + outputs = ChooseOutputs.where(:challenge_choose_id => choose.id).first + if outputs.nil? + num = nil + else + num += (outputs.correct ? 1 : 0) + end + end + return num + end + + def choose_score + score = 0 + self.challenge_chooses.each do |choose| + score += choose.score + end + return score + end + def next_challenge challenge_count = Challenge.where(:shixun_id => self.shixun_id).count render_404 if self.position ==challenge_count diff --git a/app/views/games/_choice_question.html.erb b/app/views/games/_choice_question.html.erb index badbf1536..cebfd0a05 100644 --- a/app/views/games/_choice_question.html.erb +++ b/app/views/games/_choice_question.html.erb @@ -11,30 +11,30 @@
    -
    - <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> -

    <%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>

    -
    - -
    -
    +
    + <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> +

    <%= (index + 1).to_s + "." + (choose.category == 1 ? "单选题" : "多选题") %>

    +
    + +
    +
    <% choose.challenge_questions.each_with_index do |question, i| %>

    <% if choose.category == 1 %> - + name="answer[<%= index + 1 %>]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-radio ml5"> <% else %> - + name="answer[]" category="<%= choose.category %>" value="<%= (question.position + 65).chr %>" id="result_<%= index %>_<%= i %>" class="ml-3 mr5 magic-checkbox ml5"> <% end %> - +

    <% end %> -
    - <% end %> - -

    -
    +

    +
    @@ -61,7 +61,7 @@
    - <%= render :partial => 'games/game_choose_results' %> + <%= render :partial => 'games/game_choose_results', :locals => { :game_challenge => @game_challenge} %>
    @@ -129,7 +129,6 @@ -
    <%= (question.position + 65).chr %>.
    diff --git a/app/views/games/_code_actions.html.erb b/app/views/games/_code_actions.html.erb index 9044a7fa0..746ce1313 100644 --- a/app/views/games/_code_actions.html.erb +++ b/app/views/games/_code_actions.html.erb @@ -84,57 +84,25 @@ // 选择题提交评测 // answer 选择的答案 function choice_submmit(){ - var answer = ""; - var nBtn = $(".card-check"); - var choice = nBtn.find("input[name='answer']"); - for(var i = 0; i < choice.length; i++){ - answer += $(choice[i]).val(); - } - if(answer == ""){ - notice_sure_box("答案不能为空!"); - return; + var user_answer = []; + var input_answer = $("input[name='user_answer']"); + var lens = input_answer.length; + for(i = 0; i < lens; i++ ){ + var answer = $(input_answer[i]).val(); + if(answer == ""){ + notice_sure_box("第"+ (i+1) + "题未答,请确认!"); + return; + } + user_answer.push(answer) } + console.log(user_answer); $("#code_test").html("评测中.."); $.ajax({ - type: "post", + type: "POST", url: '<%= evaluating_choice_myshixun_game_path(@game, :myshixun_id => @myshixun) %>', - data: {answer: answer}, - dataType: "json", + data: {answer:user_answer}, + dataType: "script", success: function(data){ - console.log(data); - clearInterval(cm); - var icon = $("#game_status_<%= @game_challenge.id %>"); // 实训列表的icon - icon.find("i").attr("class", "fa fa-unlock fr font-18 mt5 color-light-green w20_center"); - icon.find("a:last").attr("title", "已完成"); - $("#code_test").remove(); - if(data.correct){ - $("#correct_tip").show(); - $("#user_grade").html(data.grade); - $("#shixun_exp_<%=@game_challenge.id %>").html("经验值+"+ data.score + ""); - $("#shixun_grade_<%=@game_challenge.id %>").html("金币+"+ data.score + ""); - $("#shixun_tag_<%=@game_challenge.id %>").html("技能标签+"+ data.tag_count + ""); - if( data.had_done == 0 ) { - $("#code_estimate").html("下一关"); - var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game=> @game, :myshixun => @myshixun, :had_done => 0}) %>"; - }else{ - $("#code_estimate").html("退出实训"); - var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game => @game, :myshixun => @myshixun, :had_done => 1}) %>"; - } - // 传递具体屏幕的宽高,实现不同浏览器与不同分辨率都能撑满屏幕 - pop_box_new2(htmlvalue, window.innerWidth, window.innerHeight); - }else{ - $("#error_tip").show(); - var span_class = parseInt(data.score) < 0 ? "u-color-light-red" : "color-light-green"; - $("#shixun_exp_<%=@game_challenge.id %>").html("经验值+0"); - $("#shixun_grade_<%=@game_challenge.id %>").html("金币"+ data.score + ""); - $("#shixun_tag_<%=@game_challenge.id %>").html("技能标签+0"); - if(0 == data.had_done){ - $("#code_estimate").html("下一关"); - }else if(1 == data.had_done ){ - $("#code_estimate").html("退出实训"); - } - - } }, error: function(){ console.log("错了"); diff --git a/app/views/games/_game_choose_results.html.erb b/app/views/games/_game_choose_results.html.erb index a69854400..061dc8066 100644 --- a/app/views/games/_game_choose_results.html.erb +++ b/app/views/games/_game_choose_results.html.erb @@ -1,6 +1,3 @@ -<%= content_for(:header_tags) do %> - <%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %> -<% end %>
    • 测试结果 @@ -14,25 +11,41 @@
      -

      - 3/5 -

      -

      - 5/5 全部通过 -

      - <% @game_challenge.challenge_chooses.each_with_index do |choose, index| %> + <% unless game_challenge.choose_correct_num == nil %> + <% if game_challenge.choose_correct_num != game_challenge.challenge_chooses.count %> +

      + <%= game_challenge.choose_correct_num %>/<%= game_challenge.challenge_chooses.count %>错误 +

      + <% else %> +

      + <%= game_challenge.challenge_chooses.count %>/<%= game_challenge.challenge_chooses.count %> 全部通过 +

      + <% end %> + <% end %> + <% game_challenge.challenge_chooses.each_with_index do |choose, index| %>
      题目<%= index + 1 %> - - - + <%# outputs = ChooseOutputs.where(:challenge_choose_id => choose.id).first %> + <% unless choose.choose_outputs.blank? %> + <% if choose.choose_outputs.try(:answer) != choose.standard_answer %> + + <% else %> + + <% end %> + <% else %> + + <% end %>
        -
      • 正确选项:<%= choose.standard_answer %>
      • -
      • 你的选项:789
      • + <% if choose.choose_outputs.blank? %> +
      • 尚未提交,暂不支持查看
      • + <% else %> +
      • 正确选项:<%= choose.standard_answer %>
      • +
      • 你的选项:<%= choose.choose_outputs.try(:answer).nil? ? "无" : choose.choose_outputs.try(:answer) %>
      • + <% end %>
      diff --git a/app/views/games/_game_show.html.erb b/app/views/games/_game_show.html.erb index 875f33c22..a477cd4d0 100644 --- a/app/views/games/_game_show.html.erb +++ b/app/views/games/_game_show.html.erb @@ -27,7 +27,12 @@
    • <%= link_to '评论', shixun_discuss_shixun_path(@shixun), :class => "tab_type", :style => "font-size: 16px", :remote => true %>
    • - 经验值:<%= @game_challenge.score %> + <% if @st == 0 %> + 经验值:<%= @game_challenge.score %> + <% else %> + 经验值:<%= @game_challenge.choose_score %> + <% end %> +
    diff --git a/app/views/games/show.js.erb b/app/views/games/show.js.erb index 7e910d2e2..2419d5fec 100644 --- a/app/views/games/show.js.erb +++ b/app/views/games/show.js.erb @@ -10,6 +10,18 @@ $("#all_task_show").html("<%= j (render :partial => "games_list") %>"); $("#all_task_show").hide(); fadein = 0; + // 选择题 + <% if params[:choose] == "1" %> + <% if @had_done == 0 %> + $("#code_estimate").html("下一关"); + var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game=> @game, :myshixun => @myshixun, :had_done => 0}) %>"; + <% else %> + $("#code_estimate").html("退出实训"); + var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game => @game, :myshixun => @myshixun, :had_done => 1}) %>"; + <% end %> + // 传递具体屏幕的宽高,实现不同浏览器与不同分辨率都能撑满屏幕 + pop_box_new2(htmlvalue, window.innerWidth, window.innerHeight); + <% end %> <% else %> $("#all_task_show").html("<%= j (render :partial => "games_list") %>"); $("#all_task_tab").trigger("click"); // 模拟全部任务点击事件 diff --git a/db/migrate/20170914024926_modify_correct_type_for_choose_outputs.rb b/db/migrate/20170914024926_modify_correct_type_for_choose_outputs.rb new file mode 100644 index 000000000..a186d8842 --- /dev/null +++ b/db/migrate/20170914024926_modify_correct_type_for_choose_outputs.rb @@ -0,0 +1,8 @@ +class ModifyCorrectTypeForChooseOutputs < ActiveRecord::Migration + def up + change_column :choose_outputs, :correct, :boolean + end + + def down + end +end From 9dc48292eb970a3d654380929870ac18a2822900 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 14 Sep 2017 18:45:19 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E5=8D=95=E9=80=89=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 12 +++++++++++- app/views/games/_code_actions.html.erb | 4 ++-- app/views/games/_game_show.html.erb | 10 ++++++++-- public/javascripts/edu/edu_tpi.js | 3 ++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index f2fdb4e22..05c415cb7 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -385,9 +385,19 @@ class GamesController < ApplicationController def answer challenge = @game.challenge @challenge_score = challenge.score.to_i + @answer = "" # 已经开启过 @score = User.current.grade.to_i - @challenge_score - @answer = challenge.answer + if(params[:choose] == "true") + challenge.challenge_chooses.each_with_index do |choose, index| + @answer += "第"+ ((index + 1).to_s) +"题:
    " + @answer += choose.answer + @answer += "


    " + end + else + @answer = challenge.answer + end + if challenge.shixun.status < 2 || @game.answer_open @viewed = 1 else diff --git a/app/views/games/_code_actions.html.erb b/app/views/games/_code_actions.html.erb index 746ce1313..89f5c5c5c 100644 --- a/app/views/games/_code_actions.html.erb +++ b/app/views/games/_code_actions.html.erb @@ -16,15 +16,15 @@ <% if @game.status == 1 %> 评测中.. <% end %> - <% if show_next_stage?(@game, @myshixun.shixun.try(:status)) %> <% if @had_done == 0 %> + <% if show_next_stage?(@game, @myshixun.shixun.try(:status)) %> <%= link_to "下一关 ", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "shixun-task-btn task-btn-blue mr15 mt8", :id => "next_step", :remote => true %> + <% end %> <% else %> 退出实训 <% end %> - <% end %>