Description:
added timeout related javascripts
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r228:9e664dd71888 - - 5 files changed: 91 inserted, 2 deleted
@@ -0,0 +1,7 | |||
|
1 | + CodejomTimeout.timeouts = [ | |
|
2 | + - @submission_timeouts.each_pair do |id, t| | |
|
3 | + - if t!=nil | |
|
4 | + = "{problem: #{id}, timeout: #{t}}," | |
|
5 | + - else | |
|
6 | + = "{problem: #{id}, timeout: null}," | |
|
7 | + ]; |
@@ -0,0 +1,58 | |||
|
1 | + var CodejomTimeout = { | |
|
2 | + | |
|
3 | + timeStarted: null, | |
|
4 | + | |
|
5 | + inputDataDuration: 5, // 5 minutes | |
|
6 | + | |
|
7 | + timeouts: [], | |
|
8 | + | |
|
9 | + updateProblemMessages: function() { | |
|
10 | + CodejomTimeout.timeouts.each(function(data) { | |
|
11 | + if(data.timeout==null) { | |
|
12 | + $("problem-submission-form-" + data.problem).hide(); | |
|
13 | + } else if(data.timeout==0) { | |
|
14 | + $("problem-timing-message-" + data.problem).innerHTML = | |
|
15 | + "The recent input data is expired. Please download a new one. You'll have 5 minute to submit."; | |
|
16 | + $("problem-submission-form-" + data.problem).hide(); | |
|
17 | + } else { | |
|
18 | + $("problem-timing-message-" + data.problem).innerHTML = | |
|
19 | + "You have about " + parseInt(data.timeout/60) + " minute(s) and " + parseInt(data.timeout % 60) + " second(s) to submit."; | |
|
20 | + $("problem-submission-form-" + data.problem).show(); | |
|
21 | + } | |
|
22 | + }); | |
|
23 | + }, | |
|
24 | + | |
|
25 | + refreshProblemMessages: function() { | |
|
26 | + var timeElapsed = ((new Date()).getTime() - CodejomTimeout.timeStarted)/1000; | |
|
27 | + // update timeout info | |
|
28 | + CodejomTimeout.timeouts.each(function(data) { | |
|
29 | + if(data.timeout > timeElapsed) { | |
|
30 | + data.timeout -= timeElapsed; | |
|
31 | + } else if(data.timeout > 0) { | |
|
32 | + data.timeout = 0; | |
|
33 | + } | |
|
34 | + }); | |
|
35 | + | |
|
36 | + CodejomTimeout.updateProblemMessages(); | |
|
37 | + CodejomTimeout.registerRefreshEvent(); | |
|
38 | + }, | |
|
39 | + | |
|
40 | + registerRefreshEvent: function() { | |
|
41 | + CodejomTimeout.timeStarted = (new Date()).getTime(), | |
|
42 | + setTimeout(function () { | |
|
43 | + CodejomTimeout.refreshProblemMessages(); | |
|
44 | + }, 2700); | |
|
45 | + }, | |
|
46 | + | |
|
47 | + updateTimeoutAfterDownloadClick: function(problem) { | |
|
48 | + CodejomTimeout.timeouts | |
|
49 | + .filter(function(data) { return data.problem==problem; }) | |
|
50 | + .each(function(data) { | |
|
51 | + if(data.timeout==0 || data.timeout==null) { | |
|
52 | + // TODO: use value from rails app. | |
|
53 | + data.timeout = CodejomTimeout.inputDataDuration * 60; | |
|
54 | + } | |
|
55 | + }); | |
|
56 | + CodejomTimeout.updateProblemMessages(); | |
|
57 | + }, | |
|
58 | + }; |
@@ -269,12 +269,30 | |||
|
269 | 269 | if recent!=nil |
|
270 | 270 | recent_id = recent.to_i |
|
271 | 271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
272 | 272 | end |
|
273 | 273 | end |
|
274 | 274 | |
|
275 | + def prepare_timeout_information(problems) | |
|
276 | + @submission_timeouts = {} | |
|
277 | + problems.each do |problem| | |
|
278 | + assignment = @user.get_recent_test_pair_assignment_for(problem) | |
|
279 | + if assignment == nil | |
|
280 | + timeout = nil | |
|
281 | + else | |
|
282 | + if assignment.expired? | |
|
283 | + timeout = 0 | |
|
284 | + else | |
|
285 | + timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime | |
|
286 | + end | |
|
287 | + end | |
|
288 | + @submission_timeouts[problem.id] = timeout | |
|
289 | + end | |
|
290 | + @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} | |
|
291 | + end | |
|
292 | + | |
|
275 | 293 | def prepare_list_information |
|
276 | 294 | @user = User.find(session[:user_id]) |
|
277 | 295 | |
|
278 | 296 | all_problems = Problem.find_available_problems |
|
279 | 297 | |
|
280 | 298 | passed = {} |
@@ -292,12 +310,14 | |||
|
292 | 310 | else |
|
293 | 311 | @current_problem_id = nil |
|
294 | 312 | end |
|
295 | 313 | |
|
296 | 314 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
297 | 315 | |
|
316 | + prepare_timeout_information(@problems) | |
|
317 | + | |
|
298 | 318 | @prob_submissions = Array.new |
|
299 | 319 | @problems.each do |p| |
|
300 | 320 | if sub_count.has_key? p.id |
|
301 | 321 | @prob_submissions << { :count => sub_count[p.id] } |
|
302 | 322 | else |
|
303 | 323 | @prob_submissions << { :count => 0 } |
@@ -1,11 +1,11 | |||
|
1 | 1 | .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"} |
|
2 | 2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
3 | 3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
4 | 4 | %b Input: |
|
5 | - %input{:type => "submit", :value => "Download input"} | |
|
5 | + %input{:type => "submit", :value => "Download input", :onclick => "CodejomTimeout.updateTimeoutAfterDownloadClick(#{problem.id}); return true;"} | |
|
6 | 6 | %span{:id => "problem-timing-message-#{problem.id}"} |
|
7 | 7 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
8 | 8 | %div{:id => "problem-submission-form-#{problem.id}"} |
|
9 | 9 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
10 | 10 | %b Submit output: |
|
11 | 11 | %input{:type => "file", :name => "file"} |
@@ -1,9 +1,10 | |||
|
1 | 1 | - content_for :head do |
|
2 | 2 | = javascript_include_tag :defaults |
|
3 | 3 | = javascript_include_tag 'announcement_refresh.js' |
|
4 | + = javascript_include_tag 'codejom_timeout.js' | |
|
4 | 5 | |
|
5 | 6 | = user_title_bar(@user) |
|
6 | 7 | |
|
7 | 8 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
8 | 9 | %span{:class => 'title'} |
|
9 | 10 | Announcements |
@@ -25,9 +26,12 | |||
|
25 | 26 | Choose problems from the list on the right. |
|
26 | 27 | = render :partial => 'problem', :collection => @problems |
|
27 | 28 | |
|
28 | 29 | %br{:clear=>'both'}/ |
|
29 | 30 | %hr/ |
|
30 | 31 | |
|
31 | - :javascript | |
|
32 | + %script{:type => "text/javascript"} | |
|
32 | 33 | Announcement.registerRefreshEventTimer(); |
|
34 | + = render :partial => 'submission_timeouts' | |
|
35 | + CodejomTimeout.updateProblemMessages(); | |
|
36 | + CodejomTimeout.registerRefreshEvent(); | |
|
33 | 37 |
You need to be logged in to leave comments.
Login now