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 | + }; |
@@ -251,71 +251,91 | |||||
|
251 | if passed |
|
251 | if passed |
|
252 | flash[:notice] = 'Correct solution.' |
|
252 | flash[:notice] = 'Correct solution.' |
|
253 | user.update_codejom_status |
|
253 | user.update_codejom_status |
|
254 | else |
|
254 | else |
|
255 | session[:current_problem_id] = problem.id |
|
255 | session[:current_problem_id] = problem.id |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
257 | end |
|
257 | end |
|
258 | redirect_to :action => 'list' |
|
258 | redirect_to :action => 'list' |
|
259 | end |
|
259 | end |
|
260 |
|
260 | ||
|
261 | protected |
|
261 | protected |
|
262 |
|
262 | ||
|
263 | def prepare_announcements(recent=nil) |
|
263 | def prepare_announcements(recent=nil) |
|
264 | if Configuration.show_tasks_to?(@user) |
|
264 | if Configuration.show_tasks_to?(@user) |
|
265 | @announcements = Announcement.find_published(true) |
|
265 | @announcements = Announcement.find_published(true) |
|
266 | else |
|
266 | else |
|
267 | @announcements = Announcement.find_published |
|
267 | @announcements = Announcement.find_published |
|
268 | end |
|
268 | end |
|
269 | if recent!=nil |
|
269 | if recent!=nil |
|
270 | recent_id = recent.to_i |
|
270 | recent_id = recent.to_i |
|
271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
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 | ||
|
278 | all_problems = Problem.find_available_problems |
|
296 | all_problems = Problem.find_available_problems |
|
279 |
|
297 | ||
|
280 | passed = {} |
|
298 | passed = {} |
|
281 | sub_count = {} |
|
299 | sub_count = {} |
|
282 | @user.submission_statuses.each do |status| |
|
300 | @user.submission_statuses.each do |status| |
|
283 | if status.passed |
|
301 | if status.passed |
|
284 | passed[status.problem_id] = true |
|
302 | passed[status.problem_id] = true |
|
285 | end |
|
303 | end |
|
286 | sub_count[status.problem_id] = status.submission_count |
|
304 | sub_count[status.problem_id] = status.submission_count |
|
287 | end |
|
305 | end |
|
288 |
|
306 | ||
|
289 | if session.has_key? :current_problem_id |
|
307 | if session.has_key? :current_problem_id |
|
290 | @current_problem_id = session[:current_problem_id] |
|
308 | @current_problem_id = session[:current_problem_id] |
|
291 | session.delete(:current_problem_id) |
|
309 | session.delete(:current_problem_id) |
|
292 | else |
|
310 | else |
|
293 | @current_problem_id = nil |
|
311 | @current_problem_id = nil |
|
294 | end |
|
312 | end |
|
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 |
|
301 | @prob_submissions << { :count => sub_count[p.id] } |
|
321 | @prob_submissions << { :count => sub_count[p.id] } |
|
302 | else |
|
322 | else |
|
303 | @prob_submissions << { :count => 0 } |
|
323 | @prob_submissions << { :count => 0 } |
|
304 | end |
|
324 | end |
|
305 | end |
|
325 | end |
|
306 | prepare_announcements |
|
326 | prepare_announcements |
|
307 | end |
|
327 | end |
|
308 |
|
328 | ||
|
309 | def check_viewability |
|
329 | def check_viewability |
|
310 | @user = User.find(session[:user_id]) |
|
330 | @user = User.find(session[:user_id]) |
|
311 | if (!Configuration.show_tasks_to?(@user)) and |
|
331 | if (!Configuration.show_tasks_to?(@user)) and |
|
312 | ((action_name=='submission') or (action_name=='submit')) |
|
332 | ((action_name=='submission') or (action_name=='submit')) |
|
313 | redirect_to :action => 'list' and return |
|
333 | redirect_to :action => 'list' and return |
|
314 | end |
|
334 | end |
|
315 | end |
|
335 | end |
|
316 |
|
336 | ||
|
317 | def prepare_grading_result(submission) |
|
337 | def prepare_grading_result(submission) |
|
318 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
338 | if Configuration.task_grading_info.has_key? submission.problem.name |
|
319 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
339 | grading_info = Configuration.task_grading_info[submission.problem.name] |
|
320 | else |
|
340 | else |
|
321 | # guess task info from problem.full_score |
|
341 | # guess task info from problem.full_score |
@@ -1,21 +1,21 | |||||
|
1 | .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"} |
|
1 | .problem-panel{:id => "problem-panel-#{problem.id}", :style => "#{(problem.id != @current_problem_id) ? "display:none" : ""}"} |
|
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}"} |
|
9 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
9 | - form_tag({ :action => 'submit_solution', :id => problem.id }, :method => :post, :multipart => true) do |
|
10 | %b Submit output: |
|
10 | %b Submit output: |
|
11 | %input{:type => "file", :name => "file"} |
|
11 | %input{:type => "file", :name => "file"} |
|
12 | %input{:type => "submit", :value => "Submit solution"} |
|
12 | %input{:type => "submit", :value => "Submit solution"} |
|
13 |
|
13 | ||
|
14 | .problem-description |
|
14 | .problem-description |
|
15 | - if problem.description!=nil |
|
15 | - if problem.description!=nil |
|
16 | - if problem.description.markdowned |
|
16 | - if problem.description.markdowned |
|
17 | = markdown(problem.description.body) |
|
17 | = markdown(problem.description.body) |
|
18 | - else |
|
18 | - else |
|
19 | = problem.description.body |
|
19 | = problem.description.body |
|
20 | - else |
|
20 | - else |
|
21 | (not available) |
|
21 | (not available) |
@@ -1,33 +1,37 | |||||
|
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 | ||
|
7 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
8 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
8 | %span{:class => 'title'} |
|
9 | %span{:class => 'title'} |
|
9 | Announcements |
|
10 | Announcements |
|
10 | #announcementbox-body |
|
11 | #announcementbox-body |
|
11 | = render :partial => 'announcement', :collection => @announcements |
|
12 | = render :partial => 'announcement', :collection => @announcements |
|
12 |
|
13 | ||
|
13 | %hr/ |
|
14 | %hr/ |
|
14 |
|
15 | ||
|
15 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
16 | %p=t 'main.start_soon' |
|
17 | %p=t 'main.start_soon' |
|
17 |
|
18 | ||
|
18 | - if Configuration.show_tasks_to?(@user) |
|
19 | - if Configuration.show_tasks_to?(@user) |
|
19 | .problem-list |
|
20 | .problem-list |
|
20 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | .problem-content |
|
22 | .problem-content |
|
22 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
23 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
23 | %b Welcome to Code Jom |
|
24 | %b Welcome to Code Jom |
|
24 | %br/ |
|
25 | %br/ |
|
25 | Choose problems from the list on the right. |
|
26 | Choose problems from the list on the right. |
|
26 | = render :partial => 'problem', :collection => @problems |
|
27 | = render :partial => 'problem', :collection => @problems |
|
27 |
|
28 | ||
|
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