# HG changeset patch # User Nattee Niparnan # Date 2014-09-22 15:46:26 # Node ID 4a0989b96ef20f76ba13f25855feda7c33601e15 # Parent d90a3f1b39d03e31d8ad5f5b37819ac7d9bba8c2 # Parent d955a53137acb8565b4b19942da03c1e1e465509 merge diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -80,6 +80,7 @@ when "ruby" then Rouge::Lexers::Ruby.new when "python" then Rouge::Lexers::Python.new when "java" then Rouge::Lexers::Java.new + when "php" then Rouge::Lexers::PHP.new end @formatted_code = formatter.format(lexer.lex(@submission.source)) @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight') 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 @@ -89,8 +89,30 @@ render :action => 'edit' and return end end + if params[:file] and params[:file].content_type != 'application/pdf' + flash[:notice] = 'Error: Uploaded file is not PDF' + render :action => 'edit' and return + end if @problem.update_attributes(params[:problem]) flash[:notice] = 'Problem was successfully updated.' + unless params[:file] == nil or params[:file] == '' + flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' + out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" + if not FileTest.exists? out_dirname + Dir.mkdir out_dirname + end + + out_filename = "#{out_dirname}/#{@problem.name}.pdf" + if FileTest.exists? out_filename + File.delete out_filename + end + + File.open(out_filename,"wb") do |file| + file.write(params[:file].read) + end + @problem.description_filename = "#{@problem.name}.pdf" + @problem.save + end redirect_to :action => 'show', :id => @problem else render :action => 'edit' diff --git a/app/views/main/_submission.html.haml b/app/views/main/_submission.html.haml --- a/app/views/main/_submission.html.haml +++ b/app/views/main/_submission.html.haml @@ -2,6 +2,8 @@ %tr{:class => ((submission_counter%2==0) ? "info-even" : "info-odd")} %td.info{:align => "center"} = submission_counter+1 + %td.info{:align => "center"} + = link_to "##{submission.id}", controller: :graders, action: :submission, id: submission.id %td.info= format_short_time(submission.submitted_at) %td.info{:align => "center"} = link_to('[load]',{:action => 'source', :id => submission.id}) diff --git a/app/views/main/submission.html.haml b/app/views/main/submission.html.haml --- a/app/views/main/submission.html.haml +++ b/app/views/main/submission.html.haml @@ -13,6 +13,7 @@ - if @submissions.length>0 %table.info %tr.info-head + %th.info No. %th.info # %th.info At %th.info Source diff --git a/app/views/problems/_form.html.erb b/app/views/problems/_form.html.erb --- a/app/views/problems/_form.html.erb +++ b/app/views/problems/_form.html.erb @@ -48,5 +48,7 @@


<%= text_field 'problem', 'url' %>

+

Task PDF <%= file_field_tag 'file' %>

+ diff --git a/app/views/problems/edit.html.erb b/app/views/problems/edit.html.erb --- a/app/views/problems/edit.html.erb +++ b/app/views/problems/edit.html.erb @@ -1,6 +1,6 @@

Editing problem

-<%= form_tag :action => 'update', :id => @problem do %> +<%= form_tag({action: 'update', id: @problem},multipart: true) do %> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <% end %> diff --git a/app/views/user_admin/list.html.erb b/app/views/user_admin/list.html.erb --- a/app/views/user_admin/list.html.erb +++ b/app/views/user_admin/list.html.erb @@ -68,8 +68,9 @@ <% for user in @users %> "> + <%= link_to user.login, controller: :users, :action => 'profile', :id => user %> <% for column in User.content_columns %> - <% if !@hidden_columns.index(column.name) %> + <% if !@hidden_columns.index(column.name) and column.name != 'login' %> <%=h user.send(column.name) %> <% end %> <% end %> diff --git a/app/views/users/profile.html.haml b/app/views/users/profile.html.haml --- a/app/views/users/profile.html.haml +++ b/app/views/users/profile.html.haml @@ -3,7 +3,7 @@ %script{:type=>"text/javascript"} $(function () { - $('#submission_table').tablesorter({widgets: ['zebra','filter']}); + $('#submission_table').tablesorter({widgets: ['zebra']}); }); :css @@ -27,8 +27,9 @@ %tr %th ID %th Problem code - %th Problem name + %th Problem full name %th Language + %th Submitted at %th Result %th Score - if session[:admin] @@ -41,6 +42,7 @@ %td= s.problem.name %td= s.problem.full_name %td= s.language.pretty_name + %td #{s.submitted_at.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(s.submitted_at)} ago) %td.fix-width= s.grader_comment %td= (s.points*100)/s.problem.full_score - if session[:admin]