diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 58b43a737..ca5944f40 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -2,12 +2,12 @@ class ChallengesController < ApplicationController layout "base_shixun" before_filter :check_authentication - before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build] - before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy] + 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 :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] - before_filter :query_challeges, :only => [:show, :edit, :update] + before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation] before_filter :find_shixun_language, :only => [:show, :new, :edit] include ApplicationHelper @@ -26,6 +26,13 @@ class ChallengesController < ApplicationController @challenge.position = challenge_count + 1 @challenge.shixun = @shixun @challenge.user = User.current + @challenge.save! + + respond_to do |format| + format.html {redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)} + end + +=begin ActiveRecord::Base.transaction do begin @challenge.save! @@ -53,6 +60,7 @@ class ChallengesController < ApplicationController raise ActiveRecord::Rollback end end +=end end # 处理新建challenge返回的pipeline片段 @@ -84,6 +92,7 @@ class ChallengesController < ApplicationController end def edit + @tab = params[:tab].blank? ? 1 : params[:tab].to_i end def destroy @@ -94,6 +103,9 @@ 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]) @@ -123,6 +135,40 @@ class ChallengesController < ApplicationController end end end +=end + end + + def update_evaluation + ActiveRecord::Base.transaction do + @challenge.update_attributes(params[:challenge]) + begin + if params[:tab].to_i == 2 + @test_sets.delete_all unless @test_sets.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 + end + end + elsif params[:tab].to_i == 5 + @challenge_tags.delete_all unless @challenge_tags.blank? + unless params[:knowledge].blank? + params[:knowledge][:input].each do |input| + ChallengeTag.create(:name => input, :challenge_id => @challenge.id) + end + end + end + # 向jenkins端发送请求,构建公共测试用例 + add_shixun_modify_status(@shixun, 1) + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + rescue Exception => e + flash[:error] = "#{e.message}" + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + raise ActiveRecord::Rollback + end + end end def index_down diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e37a91360..82b776c86 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -9,7 +9,7 @@ class Challenge < ActiveRecord::Base has_many :games, :dependent => :destroy validates_presence_of :subject - validates_presence_of :score + # validates_presence_of :score validates_presence_of :task_pass validates_length_of :subject, :maximum => 255 diff --git a/app/views/challenges/_answer_form.html.erb b/app/views/challenges/_answer_form.html.erb new file mode 100644 index 000000000..d3be65ee3 --- /dev/null +++ b/app/views/challenges/_answer_form.html.erb @@ -0,0 +1,31 @@ +<%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> +<%= javascript_include_tag '/editormd/editormd.min.js','/editormd/examples/js/jquery.min.js' %> + +
+ \ No newline at end of file diff --git a/app/views/challenges/_edit_answer.html.erb b/app/views/challenges/_edit_answer.html.erb new file mode 100644 index 000000000..e1027e9a0 --- /dev/null +++ b/app/views/challenges/_edit_answer.html.erb @@ -0,0 +1,88 @@ ++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ 测试集<%= index + 1 %> + <% if test.is_public? %> + + <% else %> + + <% end %> +
+<%= test.input.gsub("\r\n", "
").html_safe unless test.input.blank? %>
<%= test.output.gsub("\r\n", "
").html_safe unless test.output.blank? %>
+ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++ <% if @shixun.status == 0 && User.current.manager_of_shixun?(@shixun) %> + 编辑 + <% end %> +
++