Merge branch 'dev_shixun_project' of https://git.trustie.net/jacknudt/trustieforge into dev_shixun_project
This commit is contained in:
commit
91975a624c
|
@ -6,6 +6,7 @@ class ChallengesController < ApplicationController
|
|||
before_filter :authorize_tpi, :only => [:new, :create]
|
||||
before_filter :build_challege_from_params, :only => [:new, :create]
|
||||
before_filter :tpi_manager_allowed, :only => [:challenge_build]
|
||||
before_filter :query_challeges, :only => [:show, :edit, :update]
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
|
@ -69,9 +70,6 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@challenge_samples = @challenge.challenge_samples
|
||||
@test_sets = @challenge.test_sets
|
||||
@challenge_tags = @challenge.challenge_tags
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
|
@ -79,15 +77,44 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@challenge_samples = @challenge.challenge_samples
|
||||
@test_sets = @challenge.test_sets
|
||||
@challenge_tags = @challenge.challenge_tags
|
||||
end
|
||||
|
||||
def update
|
||||
@challenge = Challenge.new(params[:challenge])
|
||||
|
||||
respond_to do |format|
|
||||
if @challenge.update_attributes(params[:challenge])
|
||||
ActiveRecord::Base.transaction do
|
||||
@challenge_samples.destroy unless @challenge_samples.blank?
|
||||
@test_sets.destroy unless @test_sets.blank?
|
||||
@challenge_tags.destroy unless @challenge_tags.blank?
|
||||
if params[:sample][:input].length > 0
|
||||
params[:sample][:input].each_with_index do |value, index|
|
||||
unless (value == params[:sample][:output][index] && value.blank?)
|
||||
ChallengeSample.create(:challenge_id => @challenge.id, :input => value, :output => params[:sample][:output][index])
|
||||
end
|
||||
end
|
||||
end
|
||||
if params[:program][:input].length > 0
|
||||
params[:program][:input].each_with_index do |value, index|
|
||||
unless (value == params[:program][:output][index] && value.blank?)
|
||||
TestSet.create(:challenge_id => @challenge.id, :input => value, :output => params[:program][:output][index])
|
||||
end
|
||||
end
|
||||
end
|
||||
if params[:knowledge][:input].length > 0
|
||||
params[:knowledge][:input].each do |input|
|
||||
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: 'Shixun was successfully created.'}
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @challenge.errors }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def index_down
|
||||
# @challenges = @shixun.challenges
|
||||
|
@ -191,6 +218,12 @@ class ChallengesController < ApplicationController
|
|||
@challenge.user ||= User.current
|
||||
end
|
||||
|
||||
def query_challeges
|
||||
@challenge_samples = @challenge.challenge_samples
|
||||
@test_sets = @challenge.test_sets
|
||||
@challenge_tags = @challenge.challenge_tags
|
||||
end
|
||||
|
||||
def find_challenge
|
||||
@challenge = Challenge.find(params[:id])
|
||||
@shixun = @challenge.shixun
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</div>
|
||||
<div class=" panel-form ">
|
||||
<ul>
|
||||
<%= labelled_form_for @challenge, :url => shixun_challenges_path(@shixun) do |f| %>
|
||||
<%= labelled_form_for @challenge, :url => shixun_challenge_path(@challenge, :shixun_id => @shixun) do |f| %>
|
||||
<%= render :partial => "form", :locals => {:f => f} %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
@ -20,18 +20,3 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<% if false %>
|
||||
<!--新建缺陷开始-->
|
||||
<div class="pro_new_con mb10">
|
||||
<div class="pro-task-new-con clear">
|
||||
<%#= call_hook(:view_issues_new_top, {:training_task => @training_task}) %>
|
||||
<%= labelled_form_for @challenge, :url => shixun_challenges_path(@shixun) do |f| %>
|
||||
<%= error_messages_for 'training_task' %>
|
||||
<div>
|
||||
<%= render :partial => 'form', :locals => {:f => f} %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
Loading…
Reference in New Issue