# HG changeset patch # User Jittat Fakcharoenphol # Date 2010-01-26 00:49:26 # Node ID 2b6293a64dbbc543804bf43c220efffaab9fcd05 # Parent 68329c4240e122d0ca28a4f8e1727b872bf9fe1f added test assignment time out 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 @@ -203,6 +203,11 @@ redirect_to :action => 'list' and return end + if recent_assignment.expired? + flash[:notice] = 'The current input is expired. Please download a new input data.' + 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.' redirect_to :action => 'list' and return diff --git a/app/models/test_pair_assignment.rb b/app/models/test_pair_assignment.rb --- a/app/models/test_pair_assignment.rb +++ b/app/models/test_pair_assignment.rb @@ -1,5 +1,11 @@ class TestPairAssignment < ActiveRecord::Base + belongs_to :user belongs_to :test_pair belongs_to :problem + + def expired? + return created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION < Time.new.gmtime + end + end diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -96,7 +96,7 @@ def can_request_new_test_pair_for?(problem) recent = get_recent_test_pair_assignment_for problem - return (recent == nil or recent.submitted) + return (recent == nil or recent.submitted or recent.expired?) end def get_new_test_pair_assignment_for(problem) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,7 +14,7 @@ <%= user_header %> -<%= content_tag(:p,flash[:notice],:style => "color:green") if flash[:notice]!=nil %> +<% if flash[:notice]!=nil %>
<%= flash[:notice] %>
<% end %> <%= yield %> 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 @@ -3,6 +3,7 @@ - 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"} diff --git a/config/environment.rb.SAMPLE b/config/environment.rb.SAMPLE --- a/config/environment.rb.SAMPLE +++ b/config/environment.rb.SAMPLE @@ -107,3 +107,4 @@ # OPTIONS FOR CODE JOM # -------------------- CODEJOM_MAX_ALIVE_LEVEL = 10 +TEST_ASSIGNMENT_EXPIRATION_DURATION = 5.minute diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -264,3 +264,16 @@ .problem-panel .problem-form { border: 1px dotted #99aaee; background: #eeeeff; } + +.notice-bar { + margin-top: 3px; + margin-bottom: 3px; + text-align: center; } + .notice-bar span.notice { + color: white; + font-weight: bold; + background: #000070; + padding: 3px 20px 3px 20px; + -moz-border-radius: 2px; + -webkit-border-radius: 5px; + border-radius: 5px; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -310,3 +310,17 @@ .problem-form border: 1px dotted #99aaee background: #eeeeff + +.notice-bar + margin-top: 3px + margin-bottom: 3px + text-align: center + + span.notice + color: white + font-weight: bold + background: #000070 + padding: 3px 20px 3px 20px + -moz-border-radius: 2px + -webkit-border-radius: 5px + border-radius: 5px