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 | + }; |
@@ -272,6 +272,24 | |||||
|
272 | end |
|
272 | end |
|
273 | end |
|
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 | def prepare_list_information |
|
293 | def prepare_list_information |
|
276 | @user = User.find(session[:user_id]) |
|
294 | @user = User.find(session[:user_id]) |
|
277 |
|
295 | ||
@@ -295,6 +313,8 | |||||
|
295 |
|
313 | ||
|
296 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
314 | @problems = all_problems.reject { |problem| passed.has_key? problem.id } |
|
297 |
|
315 | ||
|
|
316 | + prepare_timeout_information(@problems) | ||
|
|
317 | + | ||
|
298 | @prob_submissions = Array.new |
|
318 | @prob_submissions = Array.new |
|
299 | @problems.each do |p| |
|
319 | @problems.each do |p| |
|
300 | if sub_count.has_key? p.id |
|
320 | if sub_count.has_key? p.id |
@@ -2,7 +2,7 | |||||
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
2 | .problem-form{:id => "problem-form-#{problem.id}"} |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
3 | - form_tag({ :action => 'download_input', :id => problem.id }, :method => :post) do |
|
4 | %b Input: |
|
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 | %span{:id => "problem-timing-message-#{problem.id}"} |
|
6 | %span{:id => "problem-timing-message-#{problem.id}"} |
|
7 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
7 | = "After downloading, you have #{TEST_ASSIGNMENT_EXPIRATION_DURATION/60} minutes to submit." |
|
8 | %div{:id => "problem-submission-form-#{problem.id}"} |
|
8 | %div{:id => "problem-submission-form-#{problem.id}"} |
@@ -1,6 +1,7 | |||||
|
1 | - content_for :head do |
|
1 | - content_for :head do |
|
2 | = javascript_include_tag :defaults |
|
2 | = javascript_include_tag :defaults |
|
3 | = javascript_include_tag 'announcement_refresh.js' |
|
3 | = javascript_include_tag 'announcement_refresh.js' |
|
|
4 | + = javascript_include_tag 'codejom_timeout.js' | ||
|
4 |
|
5 | ||
|
5 | = user_title_bar(@user) |
|
6 | = user_title_bar(@user) |
|
6 |
|
7 | ||
@@ -28,6 +29,9 | |||||
|
28 | %br{:clear=>'both'}/ |
|
29 | %br{:clear=>'both'}/ |
|
29 | %hr/ |
|
30 | %hr/ |
|
30 |
|
31 | ||
|
31 | - :javascript |
|
32 | + %script{:type => "text/javascript"} |
|
32 | Announcement.registerRefreshEventTimer(); |
|
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