diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -131,7 +131,7 @@ if !@problem.available redirect_to :controller => 'main', :action => 'list' else - @submissions = Submission.find_all_last_by_problem(params[:id]) + @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) end end diff --git a/app/models/submission.rb b/app/models/submission.rb --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -25,7 +25,7 @@ def self.find_all_last_by_problem(problem_id) # need to put in SQL command, maybe there's a better way - Submission.find_by_sql("SELECT * FROM submissions " + + Submission.includes(:user).find_by_sql("SELECT * FROM submissions " + "WHERE id = " + "(SELECT MAX(id) FROM submissions AS subs " + "WHERE subs.user_id = submissions.user_id AND " + diff --git a/app/views/problems/stat.html.erb b/app/views/problems/stat.html.erb deleted file mode 100644 --- a/app/views/problems/stat.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -

Problem stat: <%= @problem.name %>

- -This is just a hack. Really not efficient.

- -<% if @submissions!=nil %> - - - - - - - - - <% count = 0 %> - <% @submissions.each do |sub| %> - <% next unless sub.user %> - "> - - - - - - - <% count += 1 %> - <% end %> -
loginnamesubmitted_atpointscomment
<%= sub.user.login %><%= sub.user.full_name if sub.user %><%= sub.submitted_at.to_s %><%= sub.points %>
<%= sub.grader_comment %>
-<% else %> -No submission -<% end %> diff --git a/app/views/problems/stat.html.haml b/app/views/problems/stat.html.haml new file mode 100644 --- /dev/null +++ b/app/views/problems/stat.html.haml @@ -0,0 +1,34 @@ +:css + .fix-width { + font-family: "Consolas, Monaco, Droid Sans Mono,Mono, Monospace,Courier" + } + +%h1 Problem stat: #{@problem.name} +%h2 Overview + +%h2 Submissions +- if @submissions and @submissions.count > 0 + %table.info#main_table + %thead + %tr.info-head + %th ID + %th Login + %th Name + %th Submitted_at + %th Points + %th comment + %tbody + - row_odd,curr = true,'' + - @submissions.each do |sub| + - next unless sub.user + - row_odd,curr = !row_odd, sub.user if curr != sub.user + %tr{class: row_odd ? "info-odd" : "info-even"} + %td= link_to sub.id, controller: 'graders', action: 'submission', id: sub.id + %td= link_to sub.user.login, controller: :users, action: :profile, id: sub.user.id + %td= sub.user.full_name + %td= time_ago_in_words(sub.submitted_at) + " ago" + %td= sub.points + %td.fix-width= sub.grader_comment +- else + No submission +