Description:
added problem list auto update
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r257:76846842a151 - - 3 files changed: 14 inserted, 2 deleted

@@ -231,96 +231,105
231
231
232 if recent_assignment.submitted
232 if recent_assignment.submitted
233 flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
233 flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
234 session[:current_problem_id] = problem.id
234 session[:current_problem_id] = problem.id
235 redirect_to :action => 'list' and return
235 redirect_to :action => 'list' and return
236 end
236 end
237
237
238 if params[:file] == nil
238 if params[:file] == nil
239 flash[:notice] = 'You have not submitted any output.'
239 flash[:notice] = 'You have not submitted any output.'
240 session[:current_problem_id] = problem.id
240 session[:current_problem_id] = problem.id
241 redirect_to :action => 'list' and return
241 redirect_to :action => 'list' and return
242 end
242 end
243
243
244 submitted_solution = params[:file].read
244 submitted_solution = params[:file].read
245 test_pair = recent_assignment.test_pair
245 test_pair = recent_assignment.test_pair
246 passed = test_pair.grade(submitted_solution)
246 passed = test_pair.grade(submitted_solution)
247 points = passed ? 100 : 0
247 points = passed ? 100 : 0
248 submission = Submission.new(:user => user,
248 submission = Submission.new(:user => user,
249 :problem => problem,
249 :problem => problem,
250 :source => submitted_solution,
250 :source => submitted_solution,
251 :source_filename => params['file'].original_filename,
251 :source_filename => params['file'].original_filename,
252 :language_id => 0,
252 :language_id => 0,
253 :submitted_at => Time.new.gmtime,
253 :submitted_at => Time.new.gmtime,
254 :graded_at => Time.new.gmtime,
254 :graded_at => Time.new.gmtime,
255 :points => points)
255 :points => points)
256 submission.save
256 submission.save
257 recent_assignment.submitted = true
257 recent_assignment.submitted = true
258 recent_assignment.save
258 recent_assignment.save
259
259
260 status = user.get_submission_status_for(problem)
260 status = user.get_submission_status_for(problem)
261 if status == nil
261 if status == nil
262 status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0
262 status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0
263 end
263 end
264
264
265 status.submission_count += 1
265 status.submission_count += 1
266 status.passed = passed
266 status.passed = passed
267 status.save
267 status.save
268
268
269 if passed
269 if passed
270 flash[:notice] = 'Correct solution.'
270 flash[:notice] = 'Correct solution.'
271 user.update_codejom_status
271 user.update_codejom_status
272 else
272 else
273 session[:current_problem_id] = problem.id
273 session[:current_problem_id] = problem.id
274 flash[:notice] = 'Incorrect solution.'
274 flash[:notice] = 'Incorrect solution.'
275 end
275 end
276 redirect_to :action => 'list'
276 redirect_to :action => 'list'
277 end
277 end
278
278
279 + def problems
280 + prepare_list_information
281 + render :partial => 'problem_title', :collection => @problems, :as => :problem
282 + end
283 +
284 + def splash
285 + render :text => '<div class="notice">Most recent task:</span>'
286 + end
287 +
279 protected
288 protected
280
289
281 def prepare_announcements(recent=nil)
290 def prepare_announcements(recent=nil)
282 if Configuration.show_tasks_to?(@user)
291 if Configuration.show_tasks_to?(@user)
283 @announcements = Announcement.find_published(true)
292 @announcements = Announcement.find_published(true)
284 else
293 else
285 @announcements = Announcement.find_published
294 @announcements = Announcement.find_published
286 end
295 end
287 if recent!=nil
296 if recent!=nil
288 recent_id = recent.to_i
297 recent_id = recent.to_i
289 @announcements = @announcements.find_all { |a| a.id > recent_id }
298 @announcements = @announcements.find_all { |a| a.id > recent_id }
290 end
299 end
291 end
300 end
292
301
293 def prepare_timeout_information(problems)
302 def prepare_timeout_information(problems)
294 @submission_timeouts = {}
303 @submission_timeouts = {}
295 problems.each do |problem|
304 problems.each do |problem|
296 assignment = @user.get_recent_test_pair_assignment_for(problem)
305 assignment = @user.get_recent_test_pair_assignment_for(problem)
297 if assignment == nil
306 if assignment == nil
298 timeout = nil
307 timeout = nil
299 else
308 else
300 if (assignment.expired?) or (assignment.submitted)
309 if (assignment.expired?) or (assignment.submitted)
301 timeout = 0
310 timeout = 0
302 else
311 else
303 timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
312 timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
304 end
313 end
305 end
314 end
306 @submission_timeouts[problem.id] = timeout
315 @submission_timeouts[problem.id] = timeout
307 end
316 end
308 @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"}
317 @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"}
309 end
318 end
310
319
311 def prepare_list_information
320 def prepare_list_information
312 @user = User.find(session[:user_id])
321 @user = User.find(session[:user_id])
313
322
314 all_problems = Problem.find_available_problems
323 all_problems = Problem.find_available_problems
315
324
316 passed = {}
325 passed = {}
317 sub_count = {}
326 sub_count = {}
318 @user.submission_statuses.each do |status|
327 @user.submission_statuses.each do |status|
319 if status.passed
328 if status.passed
320 passed[status.problem_id] = true
329 passed[status.problem_id] = true
321 end
330 end
322 sub_count[status.problem_id] = status.submission_count
331 sub_count[status.problem_id] = status.submission_count
323 end
332 end
324
333
325 if session.has_key? :current_problem_id
334 if session.has_key? :current_problem_id
326 @current_problem_id = session[:current_problem_id]
335 @current_problem_id = session[:current_problem_id]
@@ -1,39 +1,42
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 = javascript_include_tag 'codejom_timeout.js'
5
5
6 = user_title_bar(@user)
6 = user_title_bar(@user)
7
7
8 .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")}
8 .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")}
9 %span{:class => 'title'}
9 %span{:class => 'title'}
10 Announcements
10 Announcements
11 #announcementbox-body
11 #announcementbox-body
12 = render :partial => 'announcement', :collection => @announcements
12 = render :partial => 'announcement', :collection => @announcements
13
13
14 %hr/
14 %hr/
15
15
16 - 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)
17 %p=t 'main.start_soon'
17 %p=t 'main.start_soon'
18
18
19 - if Configuration.show_tasks_to?(@user)
19 - if Configuration.show_tasks_to?(@user)
20 - .problem-list
20 + .problem-list{:id => 'problem-list'}
21 = render :partial => 'problem_title', :collection => @problems, :as => :problem
21 = render :partial => 'problem_title', :collection => @problems, :as => :problem
22 .problem-content
22 .problem-content
23 %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" : ""}
24 %h2
24 %h2
25 Welcome to Code Jom
25 Welcome to Code Jom
26 %br/
26 %br/
27 Choose problems from the list on the right.
27 Choose problems from the list on the right.
28 = render :partial => 'problem', :collection => @problems
28 = render :partial => 'problem', :collection => @problems
29
29
30 %br{:clear=>'both'}/
30 %br{:clear=>'both'}/
31 %hr/
31 %hr/
32
32
33 %script{:type => 'text/javascript'}
33 %script{:type => 'text/javascript'}
34 = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';"
34 = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';"
35 Announcement.registerRefreshEventTimer();
35 Announcement.registerRefreshEventTimer();
36 = render :partial => 'submission_timeouts'
36 = render :partial => 'submission_timeouts'
37 CodejomTimeout.updateProblemMessages();
37 CodejomTimeout.updateProblemMessages();
38 CodejomTimeout.registerRefreshEvent();
38 CodejomTimeout.registerRefreshEvent();
39
39
40 + = periodically_call_remote(:url => { :action => 'problems' }, :update => 'problem-list')
41 +
42 +
@@ -290,49 +290,49
290 float: left
290 float: left
291
291
292 .problem-bar
292 .problem-bar
293 margin-top: 5px
293 margin-top: 5px
294 padding: 5px
294 padding: 5px
295 background: #e0e0e0
295 background: #e0e0e0
296
296
297 span.problem-title
297 span.problem-title
298 font-weight: bold
298 font-weight: bold
299 font-size: 110%
299 font-size: 110%
300
300
301 .problem-content
301 .problem-content
302 float: left
302 float: left
303 margin-left: 10px
303 margin-left: 10px
304 width: 700px
304 width: 700px
305
305
306 .problem-panel
306 .problem-panel
307 border: 1px black solid
307 border: 1px black solid
308 padding: 5px
308 padding: 5px
309
309
310 .problem-form
310 .problem-form
311 border: 1px dotted #99aaee
311 border: 1px dotted #99aaee
312 background: #eeeeff
312 background: #eeeeff
313
313
314 .notice-bar
314 .notice-bar
315 margin-top: 3px
315 margin-top: 3px
316 margin-bottom: 3px
316 margin-bottom: 3px
317 text-align: center
317 text-align: center
318
318
319 span.notice
319 span.notice
320 color: white
320 color: white
321 font-weight: bold
321 font-weight: bold
322 background: #000070
322 background: #000070
323 padding: 3px 20px 3px 20px
323 padding: 3px 20px 3px 20px
324 -moz-border-radius: 2px
324 -moz-border-radius: 2px
325 -webkit-border-radius: 5px
325 -webkit-border-radius: 5px
326 border-radius: 5px
326 border-radius: 5px
327
327
328 table.codejom-problems
328 table.codejom-problems
329 th
329 th
330 background: #000070
330 background: #000070
331 color: white
331 color: white
332 td
332 td
333 width: 200px
333 width: 200px
334 vertical-align: top
334 vertical-align: top
335 text-align: center
335 text-align: center
336
336
337 &.random-button
337 &.random-button
338 - background: lightgrey No newline at end of file
338 + background: lightgrey
You need to be logged in to leave comments. Login now