# HG changeset patch # User Jittat Fakcharoenphol # Date 2015-01-29 02:04:17 # Node ID c141e39c91184fa8044ad363e5d1423726eeee68 # Parent abc583474e72bb376ecaa7179f3708f822784810 shows submission timeouts diff --git a/app/assets/javascripts/toicontest.js b/app/assets/javascripts/toicontest.js new file mode 100644 --- /dev/null +++ b/app/assets/javascripts/toicontest.js @@ -0,0 +1,37 @@ +var TOIContest = { + NO_TIMEOUT: -1, + + timeOuts: {}, + + problemSelectClick: function() { + $$(".submission-submit-divs").each(function(item) { + item.hide(); + }); + var problem_id = $('submission_problem_id').value; + if ( problem_id < 0 ) { + return; + } + $("submission_submit_div_" + problem_id + "_id").show(); + }, + + confirmDownload: function() { + return confirm("แน่ใจ?"); + }, + + refreshTimeOutMessages: function() { + for ( var pid in TOIContest.timeOuts ) { + var timeOut = TOIContest.timeOuts[ pid ]; + if ( timeOut != TOIContest.NO_TIMEOUT ) { + if ( timeOut > 0 ) { + var minLeft = parseInt(timeOut / 60); + var secLeft = parseInt(timeOut % 60); + $('submission_time_left_' + pid + '_id').innerHTML = '| เหลือเวลาอีก ' + minLeft + ':' + secLeft + ' นาที'; + } else { + $('submission_time_left_' + pid + '_id').innerHTML = '| หมดเวลาส่ง'; + $('submission_form_'+ pid + '_id').hide(); + } + } + } + } +}; + 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 @@ -272,14 +272,18 @@ out_items = output.split sol_items = solution.split res = '' + f = 0 + s = 0 sol_items.length.times do |i| + f += 1 if out_items[i] == sol_items[i] res = res + 'P' + s += 1 else res = res + '-' end end - return res + return { :score => s, :full_score => f, :msg => res } end def prepare_announcements(recent=nil) diff --git a/app/views/main/_submission_box.html.erb b/app/views/main/_submission_box.html.erb --- a/app/views/main/_submission_box.html.erb +++ b/app/views/main/_submission_box.html.erb @@ -3,20 +3,20 @@ [['กรุณาเลือกข้อที่ต้องการส่งหรือทดสอบ','-1']] + @problems.collect {|p| [p.full_name, p.id]}, { :selected => '-1' }, - { :onchange => 'select_click()' } %> + { :onchange => 'TOIContest.problemSelectClick()' } %> <% @problems.each do |problem| %>
- <%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้): + <%= problem.full_name %>: ข้อมูลสำหรับตรวจสอบ (สามารถดาวน์โหลดและส่งกี่ครั้งก็ได้,ไม่มีคะแนน): <%= link_to 'ดาวน์โหลด input', :action => 'verifying_testcase', :id => problem.id %> - <% if @current_problem.id == problem.id %> + <% if @current_problem and @current_problem.id == problem.id %> <% if @grading_result %> - | ผลการตรวจ: <%= @grading_result %> + | ผลการตรวจ: <%= "#{@grading_result[:score]}/#{@grading_result[:full_score]} [#{@grading_result[:msg]}]" %> <% end %> <% end %> - <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true}) do %> + <%= form_tag({:controller => 'main', :action => 'verifying_submit', :id => problem.id}, {:method => 'post', :multipart => true }) do %> ส่งคำตอบของข้อมูลสำหรับตรวจสอบ: <%= file_field_tag 'output_file' %> <%= submit_tag 'Submit' %> @@ -24,9 +24,9 @@
<%= problem.full_name %>: ข้อมูลทดสอบจริง (ส่งกี่ครั้งก็ได้ภายในเวลา 5 นาทีหลังดาวน์โหลด): - <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => 'return confirm_download()' } %> + <%= link_to 'ดาวน์โหลด input และเริ่มจับเวลา', { :action => 'testcase', :id => problem.id}, { :onclick => 'return TOIContest.confirmDownload()' } %> - <%= form_tag do %> + <%= form_tag({:controller => 'main', :action => 'submit', :id => problem.id}, {:method => 'post', :multipart => true, :id => "submission_form_#{problem.id}_id" }) do %> ข้อมูลส่งออก: <%= file_field_tag 'output_file' %> โปรแกรมคำตอบ: <%= file_field_tag 'source_file' %> <%= submit_tag 'Submit' %> @@ -34,18 +34,3 @@
<% end %> - diff --git a/app/views/main/list.html.haml b/app/views/main/list.html.haml --- a/app/views/main/list.html.haml +++ b/app/views/main/list.html.haml @@ -1,5 +1,6 @@ - content_for :head do = javascript_include_tag "announcement_refresh" + = javascript_include_tag "toicontest" = user_title_bar(@user) @@ -48,3 +49,11 @@ = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';" Announcement.registerRefreshEventTimer(); + TOIContest.timeOuts = {}; + - @problems.each do |p| + - if (@submission_timeouts.has_key? p.id) and (@submission_timeouts[p.id] != nil) + = "TOIContest.timeOuts[#{p.id}] = #{@submission_timeouts[p.id]};" + - else + = "TOIContest.timeOuts[#{p.id}] = TOIContest.NO_TIMEOUT;" + + TOIContest.refreshTimeOutMessages();