# HG changeset patch # User Jittat Fakcharoenphol # Date 2010-01-26 02:08:22 # Node ID 1586858ff9d52d5835bdcfaf281a8583d6ec05a7 # Parent 2b6293a64dbbc543804bf43c220efffaab9fcd05 shows recent problem after wrong submissions diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -198,23 +198,28 @@ problem = Problem.find(params[:id]) user = User.find(session[:user_id]) recent_assignment = user.get_recent_test_pair_assignment_for problem + if recent_assignment == nil flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' + session[:current_problem_id] = problem.id redirect_to :action => 'list' and return end if recent_assignment.expired? flash[:notice] = 'The current input is expired. Please download a new input data.' + session[:current_problem_id] = problem.id redirect_to :action => 'list' and return end if recent_assignment.submitted flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' + session[:current_problem_id] = problem.id redirect_to :action => 'list' and return end if params[:file] == nil flash[:notice] = 'You have not submitted any output.' + session[:current_problem_id] = problem.id redirect_to :action => 'list' and return end @@ -247,6 +252,7 @@ flash[:notice] = 'Correct solution.' user.update_codejom_status else + session[:current_problem_id] = problem.id flash[:notice] = 'Incorrect solution.' end redirect_to :action => 'list' @@ -280,6 +286,13 @@ sub_count[status.problem_id] = status.submission_count end + if session.has_key? :current_problem_id + @current_problem_id = session[:current_problem_id] + session.delete(:current_problem_id) + else + @current_problem_id = nil + end + @problems = all_problems.reject { |problem| passed.has_key? problem.id } @prob_submissions = Array.new diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -19,9 +19,13 @@ end def random_test_pair(forbidden_numbers=nil) - begin + if forbidden_numbers.length < test_pair_count + begin + test_num = 1 + rand(test_pair_count) + end while forbidden_numbers!=nil and forbidden_numbers.include? test_num + else test_num = 1 + rand(test_pair_count) - end while forbidden_numbers!=nil and forbidden_numbers.include? test_num + end test_pairs.find_by_number test_num end diff --git a/app/views/main/_problem.html.haml b/app/views/main/_problem.html.haml --- a/app/views/main/_problem.html.haml +++ b/app/views/main/_problem.html.haml @@ -1,13 +1,15 @@ -.problem-panel{:id => "problem-panel-#{problem.id}", :style => "display:none"} +.problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"} .problem-form{:id => "problem-form-#{problem.id}"} - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do %b Input: %input{:type => "submit", :value => "Download input"} - = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." - - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do - %b Submit output: - %input{:type => "file", :name => "file"} - %input{:type => "submit", :value => "Submit solution"} + %span{:id => "problem-timing-message-#{problem.id}"} + = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." + %div{:id => "problem-submission-form-#{problem.id}"} + - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do + %b Submit output: + %input{:type => "file", :name => "file"} + %input{:type => "submit", :value => "Submit solution"} .problem-description - if problem.description!=nil diff --git a/app/views/main/list.html.haml b/app/views/main/list.html.haml --- a/app/views/main/list.html.haml +++ b/app/views/main/list.html.haml @@ -20,10 +20,11 @@ .problem-list = render :partial => 'problem_title', :collection => @problems, :as => :problem .problem-content - %span{:id => "problem-panel-filler"} - %b Welcome to Code Jom - %br/ - Choose problems from the list on the right. + - if @current_problem_id==nil + %span{:id => "problem-panel-filler"} + %b Welcome to Code Jom + %br/ + Choose problems from the list on the right. = render :partial => 'problem', :collection => @problems %br{:clear=>'both'}/