diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 87fe18a96..20811cab7 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -14,7 +14,7 @@ class ChallengesController < ApplicationController def new # 顶部导航 - @st = params[:st] + @st = params[:st].to_i @project_menu_type = 11 respond_to do |format| format.html { render :action => 'new', :layout => 'base_shixun' } @@ -29,17 +29,20 @@ class ChallengesController < ApplicationController @challenge.position = challenge_count + 1 @challenge.shixun = @shixun @challenge.user = User.current - # @challenge.st = params[:st] + @challenge.st = params[:st].to_i if @challenge.save! - # 创建选项 - # params[:question].each do |test| - # ChallengeQuestion.where(:option_name => option_name,:challenges => challenge_id, :positon => 1, :right_key => true) - # end + if params[:st].to_i != 0 + #创建选项 + 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 + end end redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun) rescue Exception => e flash[:error] = "#{e.message}" - redirect_to new_shixun_challenge_path(:shixun_id => @shixun) + redirect_to new_shixun_challenge_path(:shixun_id => @shixun, :st => params[:st].to_i) raise ActiveRecord::Rollback end end @@ -103,6 +106,7 @@ class ChallengesController < ApplicationController end def edit + @st = @challenge.st challenge_num = Challenge.where(:shixun_id => @shixun).count challenge_pos = @challenge.position if challenge_pos < challenge_num @@ -120,39 +124,25 @@ class ChallengesController < ApplicationController end def update - @challenge.update_attributes(params[:challenge]) - redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) -=begin - respond_to do |format| ActiveRecord::Base.transaction do @challenge.update_attributes(params[:challenge]) - begin - @test_sets.delete_all unless @test_sets.blank? - @challenge_tags.delete_all unless @challenge_tags.blank? - if params[:test_set][:hidden].length > 0 - params[:test_set][:input].each_with_index do |input, index| - unless (input[index] == params[:test_set][:output][index] && input[index].nil?) - params[:test_set][:hidden][index].to_i == 0 ? open = 1 : open = 0 - TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index], :is_public => open, :position => (index + 1)) - end + 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 - unless params[:knowledge].blank? - params[:knowledge][:input].each do |input| - ChallengeTag.create(:name => input, :challenge_id => @challenge.id) - end - end - # 向jenkins端发送请求,构建公共测试用例 - add_shixun_modify_status(@shixun, 1) - format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '更新成功!'} - rescue Exception => e - flash[:error] = "#{e.message}" - format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} - raise ActiveRecord::Rollback + else + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) end end - end -=end end def update_evaluation diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b53d6979e..00065036c 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -4,7 +4,7 @@ class GamesController < ApplicationController skip_before_filter :verify_authenticity_token, :only => [:file_update] before_filter :find_myshixun, :only => [:index] before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, - :game_status, :change_status, :answer, :minus_score, :refresh_game_list, :reset_original_code, :reset_new_code] + :game_status, :change_status, :answer, :minus_score, :refresh_game_list, :reset_original_code, :reset_new_code, :evaluating_choice] before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update, :reset_original_code, :reset_new_code] before_filter :allowd_manager before_filter :allowd_view, :only => [:show] @@ -26,6 +26,7 @@ class GamesController < ApplicationController # @praise 判断是否点赞 # @tread 判断是否踩 # git_repository_url @myshixun, "Myshixun" + # @st 0 编程任务 1 多选任务 2 单选任务 def show # 展示全部实训 if @game.status == 1 @@ -38,12 +39,15 @@ class GamesController < ApplicationController @shixun = @myshixun.shixun # @games_count = @games.count @game_challenge = @game.challenge + @st = @game_challenge.st @had_done = @game.had_done @praise = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?", @game_challenge.id, @game_challenge.class.to_s, User.current.id).first @tread = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?", @game_challenge.id, "ChallengeTread", User.current.id).first @rev = @rev.nil? ? "master" : @rev @type = params[:type] challenge_path = @game_challenge.path + # 用户选项 + @user_answer = @game.outputs.first.actual_output.split("") unless @st == 0 || @game.outputs.blank? # 默认打开文件 logger.info("repository id is #{@repository.try(:id)}, repository's shixun_id =#{@repository.try(:myshixun_id)} shixun_id =#{@repository.try(:shixun_id)}, project_id => #{@repository.try(:project_id)}") # 验证challenge文件名的合法性 @@ -262,6 +266,31 @@ class GamesController < ApplicationController had_done: had_done} end + # 选择题评测(选择题不需要重新评测) + def evaluating_choice + @game_challenge = @game.challenge + user_answer = params[:answer] + correct = true + had_done = @game.had_done + if !user_answer.blank? + 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 + else + correct = false + end + @game.update_attributes(:status => 2, :end_time => Time.now) + if @game.outputs.blank? + Output.create(:game_id => @game.id, :actual_output => user_answer, :result => correct) + end + render :json => {correct: correct, had_done: had_done} + end + + def change_status @game.update_attribute(:status, 0) outputs = @game.outputs diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index abab48f3b..e69e9fd9f 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -27,7 +27,7 @@ class MyshixunsController < ApplicationController jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo") user_id = User.current.id - params = {gameID:@myshixun.id} + params = {gameID:@myshixun.id, operationEnvironment:@myshixun.shixun.try(:language)} res = uri_exec uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:92)") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b2327fc2c..2d85a462d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -164,7 +164,7 @@ module ApplicationHelper # 实训语言的种类 def shixun_language - ["Java", "C", "C++", "Python", "MySQL/Java","JFinal","Docker","Ethoernet","Dynamips"] + ["Java", "C", "C++", "Python", "MySQL/Java","JFinal","Docker","Ethereum","Dynamips"] end # 实训试用专业 diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 6779b345e..3ec4901a2 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -8,6 +8,7 @@ class Challenge < ActiveRecord::Base has_many :test_sets, :dependent => :destroy has_many :challenge_tags, :dependent => :destroy has_many :games, :dependent => :destroy + has_many :challenge_questions, :dependent => :destroy validates_presence_of :subject # validates_presence_of :score @@ -43,4 +44,15 @@ class Challenge < ActiveRecord::Base myshixun = Myshixun.where(:shixun_id => self.shixun.id, :user_id => User.current.id).first game = Game.where(:myshixun_id => myshixun.id, :challenge_id => self.id).first end + + # 正确答案 + def right_answers + answer = "" + self.challenge_questions.each do |ans| + if ans.right_key + answer << (ans.position + 65).chr + end + end + return answer + end end diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb index bda6780ce..eb835c32e 100644 --- a/app/models/challenge_question.rb +++ b/app/models/challenge_question.rb @@ -1,3 +1,4 @@ class ChallengeQuestion < ActiveRecord::Base - attr_accessible :challenge_id, :option, :position, :right_key + belongs_to :challenge + attr_accessible :challenge_id, :option_name, :position, :right_key end diff --git a/app/models/output.rb b/app/models/output.rb index b6edbb602..68ba45061 100644 --- a/app/models/output.rb +++ b/app/models/output.rb @@ -1,5 +1,6 @@ class Output < ActiveRecord::Base # attr_accessible :title, :body + # actual_output 编程题:实际输出, 选择题: 用户提交的答案(如: 014 对应用户选择为A B E) default_scope :order => 'test_set_position desc' belongs_to :game end diff --git a/app/views/challenges/_answer_form.html.erb b/app/views/challenges/_answer_form.html.erb index 11007ca74..98f3a8e7b 100644 --- a/app/views/challenges/_answer_form.html.erb +++ b/app/views/challenges/_answer_form.html.erb @@ -47,7 +47,7 @@ saveHTMLToTextarea : true, // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 dialogMaskOpacity : 0.6, - placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息", + placeholder: "<%= @st == 0 ? '' : "请输入各个选项的具体解析或其他相关信息" %>", imageUpload : true, 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 diff --git a/app/views/challenges/_content_list.html.erb b/app/views/challenges/_content_list.html.erb index 0cd13ea7b..ee83bd164 100644 --- a/app/views/challenges/_content_list.html.erb +++ b/app/views/challenges/_content_list.html.erb @@ -5,23 +5,29 @@ <%= @challenges.count %> <% end %> <% if User.current.manager_of_shixun?(@shixun) && @shixun.status == 0 %> - - 新建阶段 + +单选任务 + +多选任务 + +编程任务 + <% end %>
- <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + <% if User.current.manager_of_shixun?(@shixun) %> 编辑 <% end %>
diff --git a/app/views/challenges/_edit_propaedeutics.html.erb b/app/views/challenges/_edit_propaedeutics.html.erb new file mode 100644 index 000000000..d3a5af201 --- /dev/null +++ b/app/views/challenges/_edit_propaedeutics.html.erb @@ -0,0 +1,44 @@ ++ <% if User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
+- <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + <% if User.current.manager_of_shixun?(@shixun) %> 编辑 <% end %>
diff --git a/app/views/challenges/_edit_skill.html.erb b/app/views/challenges/_edit_skill.html.erb index 2a00676bd..64c4556b6 100644 --- a/app/views/challenges/_edit_skill.html.erb +++ b/app/views/challenges/_edit_skill.html.erb @@ -2,7 +2,7 @@- <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + <% if User.current.manager_of_shixun?(@shixun) %> 编辑 <% end %>
diff --git a/app/views/challenges/_edit_task_pass.html.erb b/app/views/challenges/_edit_task_pass.html.erb index e859c0763..75473897c 100644 --- a/app/views/challenges/_edit_task_pass.html.erb +++ b/app/views/challenges/_edit_task_pass.html.erb @@ -3,7 +3,7 @@- <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + <% if User.current.manager_of_shixun?(@shixun) %> 编辑 <% end %>
@@ -23,6 +23,31 @@" id="correct_tip"> + 正确 +
+" id="error_tip"> + 错误 +
+ <% @game_challenge.challenge_questions.each_with_index do |question, i| %> + + <% end %> + +
+ <%= link_to image_tag(url_to_avatar(dis.user), :alt => "头像", :width => 60, :height => 60), user_path(dis.user),:class => "fl mt5", :target => '_blank' %> +
<%= link_to dis.user.show_name, user_path(dis.user), :class => "fl link-color-grey" %> <%= render :partial => "discusses/dis_praise", :locals => {:discuss => dis} %>
-<%= dis.content %>
-+
<%= dis.content %>
+<%= time_from_now dis.created_at %>
-+
<% if User.current.manager_of_shixun?(@shixun) && dis.children.count == 0 %> 回复 <% end %> diff --git a/app/views/homework_bank/_new_group_homework.html.erb b/app/views/homework_bank/_new_group_homework.html.erb index 7e3a4523f..685f81938 100644 --- a/app/views/homework_bank/_new_group_homework.html.erb +++ b/app/views/homework_bank/_new_group_homework.html.erb @@ -1,6 +1,6 @@ <% not_allow_select = edit_mode && @homework.student_works.has_committed.count != 0 %> -
<%= edit_mode ? '编辑' : '新建' %>分组作业
<%= edit_mode ? '编辑' : '新建' %>编程作业
<%= edit_mode ? '编辑' : '新建' %>普通作业
diff --git a/app/views/homework_common/index.html.erb b/app/views/homework_common/index.html.erb index 49c1f615e..bc2465e67 100644 --- a/app/views/homework_common/index.html.erb +++ b/app/views/homework_common/index.html.erb @@ -21,7 +21,7 @@ <%= render :partial => 'homework_search_form', :locals => {:course => @course} %>