# HG changeset patch # User jittat # Date 2008-02-24 15:42:10 # Node ID 0fc0c11d6fb0a1ea9ca13e4ab2f06da0b3f80f6d # Parent b72d6a6d5e32c0ccb3f8b2db23033baf6b9ce3ee refactor to partials git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@62 6386c4cd-e34a-4fa8-8920-d93eb39b512e 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 @@ -58,7 +58,7 @@ @user = User.find(session[:user_id]) @problems.each do |p| c, sub = Submission.find_by_user_and_problem(@user.id,p.id) - @prob_submissions << [c,sub] + @prob_submissions << { :count => c, :submission => sub } end end diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb --- a/app/helpers/main_helper.rb +++ b/app/helpers/main_helper.rb @@ -10,36 +10,4 @@ st + time.strftime("%X") end - def format_compiler_msg(sub) - < -
-Compiler message (click to see)
-
-
-#{h(sub.compiler_message).gsub(/\n/,'
')} -
-
-cmpmsg - end - - def format_submission(sub, count) - msg = "#{count} submission(s)." - if count>0 - msg = msg + "Last on " + - format_short_time(sub.submitted_at) + ' ' + - link_to('[source]',{:action => 'get_source', :id => sub.id}) - end - msg += "
" - if sub!=nil and sub.graded_at!=nil - msg = msg + 'Graded at ' + format_short_time(sub.graded_at) + ', score: '+ - sub.points.to_s + - ' [' + sub.grader_comment + "]
" + - format_compiler_msg(sub) - end - msg - end - end diff --git a/app/views/main/_compiler_message.html.erb b/app/views/main/_compiler_message.html.erb new file mode 100644 --- /dev/null +++ b/app/views/main/_compiler_message.html.erb @@ -0,0 +1,10 @@ +
+ Compiler message (click to see) +
+
+
+ <%=h(compiler_message).gsub(/\n/,'
') %> +
+
diff --git a/app/views/main/_problem.html.erb b/app/views/main/_problem.html.erb new file mode 100644 --- /dev/null +++ b/app/views/main/_problem.html.erb @@ -0,0 +1,11 @@ +
+
+ <%= "#{problem_counter + 1}: #{problem.full_name} (#{problem.name})" %> + <%= link_to '[task description]', problem.url, :popup => true if (problem.url!=nil) and (problem.url!='') %> +
+
+ <%= render :partial => 'submission', + :locals => { :submission => @prob_submissions[problem_counter][:submission], + :count => @prob_submissions[problem_counter][:count] } %> +
+
diff --git a/app/views/main/_submission.html.haml b/app/views/main/_submission.html.haml new file mode 100644 --- /dev/null +++ b/app/views/main/_submission.html.haml @@ -0,0 +1,16 @@ + +- if count==0 + 0 submission +- else + = count + submission(s). + Last on + = format_short_time(submission.submitted_at) + = link_to('[source]',{:action => 'get_source', :id => submission.id}) + %br/ + - if submission!=nil and submission.graded_at!=nil + = "Graded at #{format_short_time(submission.graded_at)}, " + = "score: #{submission.points} " + = " [" + submission.grader_comment + "]" + %br/ + = render :partial => 'compiler_message', :locals => {:compiler_message => submission.compiler_message } diff --git a/app/views/main/_submission_box.html.erb b/app/views/main/_submission_box.html.erb new file mode 100644 --- /dev/null +++ b/app/views/main/_submission_box.html.erb @@ -0,0 +1,8 @@ +<% form_tag({:action => 'submit'}, :multipart => true) do %> +Problem: <%= select 'submission', 'problem_id', + [['Specified in header','-1']] + + @problems.collect {|p| [p.full_name, p.id]}, + :selected => '-1' %> +File: <%= file_field_tag 'file' %> +<%= submit_tag 'Submit' %> +<% end %> diff --git a/app/views/main/list.rhtml b/app/views/main/list.rhtml --- a/app/views/main/list.rhtml +++ b/app/views/main/list.rhtml @@ -2,17 +2,8 @@ Current time is <%= format_short_time(Time.new) %>.
- -<%= error_messages_for 'submission' %> - -<% form_tag({:action => 'submit'}, :multipart => true) do %> -Problem: <%= select 'submission', 'problem_id', - [['Specified in header','-1']] + - @problems.collect {|p| [p.full_name, p.id]}, - :selected => '-1' %> -File: <%= file_field_tag 'file' %> -<%= submit_tag 'Submit' %> -<% end %> + <%= error_messages_for 'submission' %> + <%= render :partial => 'submission_box' %>

@@ -20,21 +11,12 @@

<%= flash[:notice] %>

-<% i = 0 %> -<% @problems.each do |p| %> -
-
- <%= "#{i+1}: #{p.full_name} (#{p.name})" %> - <%= link_to '[task description]', p.url, :popup => true if (p.url!=nil) and (p.url!='') %> -
-
- <%= format_submission(@prob_submissions[i][1], - @prob_submissions[i][0]) %> -
-
- <% i = i+1 %> -<% end %> + <%= render :partial => 'problem', :collection => @problems %>

+
+ <%= render :partial => 'submission_box' %> +
+