# HG changeset patch # User jittat # Date 2008-03-08 22:11:55 # Node ID 826893c27cee4e69ca7795dd6cc0ff73b1510292 # Parent 305f703e60aa87bb5173c198c6b0df0153587086 moved test interface functionality to test_controller git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@95 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 @@ -48,23 +48,7 @@ :type => 'text/plain'}) else flash[:notice] = 'Error viewing source' - end - end - - def test - @user = User.find(session[:user_id]) - @submissions = Submission.find_last_for_all_available_problems(@user.id) - @problems = @submissions.collect { |submission| submission.problem } - end - - def test_submit - @user = User.find(session[:user_id]) - test_request = TestRequest.new_from_form_params(@user,params[:test_request]) - if test_request.save - redirect_to :action => 'test' - else - flash[:notice] = 'Error saving your test submission' - render :action => 'test' + redirect_to :action => 'list' end end diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb new file mode 100644 --- /dev/null +++ b/app/controllers/test_controller.rb @@ -0,0 +1,49 @@ +class TestController < ApplicationController + + before_filter :authenticate + + verify :method => :post, :only => [:test_submit], + :redirect_to => { :action => :index } + + def index + @user = User.find(session[:user_id]) + prepare_index_information + end + + def submit + @user = User.find(session[:user_id]) + test_request = TestRequest.new_from_form_params(@user,params[:test_request]) + if test_request.save + redirect_to :action => 'index' + else + flash[:notice] = 'Error saving your test submission' + redirect_to :action => 'index' + end + end + + def read + user = User.find(session[:user_id]) + test_request = TestRequest.find(params[:id]) + if test_request.user_id != user.id + flash[:notice] = 'Invalid output' + redirect_to :action => 'index' + return + end + if test_request.output_file_name!=nil + data = File.open(test_request.output_file_name).read(2048) + send_data(data, + {:filename => 'output.txt', + :type => 'text/plain'}) + return + end + redirect_to :action => 'index' + end + + protected + + def prepare_index_information + @submissions = Submission.find_last_for_all_available_problems(@user.id) + @problems = @submissions.collect { |submission| submission.problem } + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,7 +7,7 @@ # main page append_to menu_items, '[Main]', 'main', 'list' - append_to menu_items, '[Test]', 'main', 'test' + append_to menu_items, '[Test]', 'test', 'index' # admin menu if (user!=nil) and (user.admin?) diff --git a/app/helpers/test_helper.rb b/app/helpers/test_helper.rb new file mode 100644 --- /dev/null +++ b/app/helpers/test_helper.rb @@ -0,0 +1,2 @@ +module TestHelper +end diff --git a/app/models/test_request.rb b/app/models/test_request.rb --- a/app/models/test_request.rb +++ b/app/models/test_request.rb @@ -35,15 +35,15 @@ # since there will be only one grader grading TestRequest # we do not need locking (hopefully) - task = Task.find(:first, - :order => "created_at", - :conditions => {:status=> Task::STATUS_INQUEUE}) - if task!=nil - task.status = status - task.save! + test_request = TestRequest.find(:first, + :order => "created_at", + :conditions => {:status=> Task::STATUS_INQUEUE}) + if test_request!=nil + test_request.status = status + test_request.save! end - task + test_request end # interfacing with form diff --git a/app/views/main/_test_request.html.haml b/app/views/main/_test_request.html.haml deleted file mode 100644 --- a/app/views/main/_test_request.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%tr.test-request - %td= test_request_counter +1 - %td= test_request.problem.full_name - %td= test_request.submission_id - %td= test_request.status_str 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 @@ -8,8 +8,6 @@
-

<%= flash[:notice] %>

-
<%= render :partial => 'problem', :collection => @problems %>
diff --git a/app/views/main/test.html.erb b/app/views/main/test.html.erb deleted file mode 100644 --- a/app/views/main/test.html.erb +++ /dev/null @@ -1,69 +0,0 @@ -

Test Interface

- -<% if @problems.length==0 %> - There is no submission -<% else %> - - - -<% form_for :test_request, nil, - :url => { :action => 'test_submit'}, - :html => { :multipart => true } do |f| %> - - - - - - - - - - - - - - - -
Task: - <%= select(:test_request, - :problem_id, - @problems.collect {|p| [p.name, p.id]}, {}, - { :onclick => "updateSubmissionList();" }) %> -
Submission: - <%= select(:test_request, - :submission_number, - (1..@submissions[0].number).collect {|n| [n,n]}) %> -
Input data:<%= f.file_field :input_file %>
- <%= submit_tag 'submit' %> -
-<% end %> - -

Previous requests

- - - - - - - -<%= render :partial => 'test_request', :collection => @user.test_requests %> -
- problem#status
- -<% end %> - diff --git a/app/views/test/_test_request.html.haml b/app/views/test/_test_request.html.haml new file mode 100644 --- /dev/null +++ b/app/views/test/_test_request.html.haml @@ -0,0 +1,11 @@ +%tr.test-request + %td= test_request_counter +1 + %td= test_request.problem.full_name + %td= test_request.submission_id + %td= test_request.status_str + %td= test_request.grader_comment or '' + %td= test_request.compiler_message or '' + %td= test_request.running_stat or '' + %td + - if test_request.output_file_name!=nil + = link_to '[output]', :action => 'read', :id => test_request.id diff --git a/app/views/test/index.html.erb b/app/views/test/index.html.erb new file mode 100644 --- /dev/null +++ b/app/views/test/index.html.erb @@ -0,0 +1,69 @@ +

Test Interface

+ +<% if @problems.length==0 %> + There is no submission +<% else %> + + + +<% form_for :test_request, nil, + :url => { :action => 'submit'}, + :html => { :multipart => true } do |f| %> + + + + + + + + + + + + + + + +
Task: + <%= select(:test_request, + :problem_id, + @problems.collect {|p| [p.name, p.id]}, {}, + { :onclick => "updateSubmissionList();" }) %> +
Submission: + <%= select(:test_request, + :submission_number, + (1..@submissions[0].number).collect {|n| [n,n]}) %> +
Input data:<%= f.file_field :input_file %>
+ <%= submit_tag 'submit' %> +
+<% end %> + +

Previous requests

+ + + + + + + +<%= render :partial => 'test_request', :collection => @user.test_requests %> +
+ problem#status
+ +<% end %> + diff --git a/test/functional/test_controller_test.rb b/test/functional/test_controller_test.rb new file mode 100644 --- /dev/null +++ b/test/functional/test_controller_test.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TestControllerTest < ActionController::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end