Description:
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
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r44:826893c27cee - - 11 files changed: 146 inserted, 99 deleted
@@ -0,0 +1,49 | |||
|
1 | + class TestController < ApplicationController | |
|
2 | + | |
|
3 | + before_filter :authenticate | |
|
4 | + | |
|
5 | + verify :method => :post, :only => [:test_submit], | |
|
6 | + :redirect_to => { :action => :index } | |
|
7 | + | |
|
8 | + def index | |
|
9 | + @user = User.find(session[:user_id]) | |
|
10 | + prepare_index_information | |
|
11 | + end | |
|
12 | + | |
|
13 | + def submit | |
|
14 | + @user = User.find(session[:user_id]) | |
|
15 | + test_request = TestRequest.new_from_form_params(@user,params[:test_request]) | |
|
16 | + if test_request.save | |
|
17 | + redirect_to :action => 'index' | |
|
18 | + else | |
|
19 | + flash[:notice] = 'Error saving your test submission' | |
|
20 | + redirect_to :action => 'index' | |
|
21 | + end | |
|
22 | + end | |
|
23 | + | |
|
24 | + def read | |
|
25 | + user = User.find(session[:user_id]) | |
|
26 | + test_request = TestRequest.find(params[:id]) | |
|
27 | + if test_request.user_id != user.id | |
|
28 | + flash[:notice] = 'Invalid output' | |
|
29 | + redirect_to :action => 'index' | |
|
30 | + return | |
|
31 | + end | |
|
32 | + if test_request.output_file_name!=nil | |
|
33 | + data = File.open(test_request.output_file_name).read(2048) | |
|
34 | + send_data(data, | |
|
35 | + {:filename => 'output.txt', | |
|
36 | + :type => 'text/plain'}) | |
|
37 | + return | |
|
38 | + end | |
|
39 | + redirect_to :action => 'index' | |
|
40 | + end | |
|
41 | + | |
|
42 | + protected | |
|
43 | + | |
|
44 | + def prepare_index_information | |
|
45 | + @submissions = Submission.find_last_for_all_available_problems(@user.id) | |
|
46 | + @problems = @submissions.collect { |submission| submission.problem } | |
|
47 | + end | |
|
48 | + | |
|
49 | + end |
@@ -0,0 +1,11 | |||
|
1 | + %tr.test-request | |
|
2 | + %td= test_request_counter +1 | |
|
3 | + %td= test_request.problem.full_name | |
|
4 | + %td= test_request.submission_id | |
|
5 | + %td= test_request.status_str | |
|
6 | + %td= test_request.grader_comment or '' | |
|
7 | + %td= test_request.compiler_message or '' | |
|
8 | + %td= test_request.running_stat or '' | |
|
9 | + %td | |
|
10 | + - if test_request.output_file_name!=nil | |
|
11 | + = link_to '[output]', :action => 'read', :id => test_request.id |
@@ -0,0 +1,69 | |||
|
1 | + <h2>Test Interface</h2> | |
|
2 | + | |
|
3 | + <% if @problems.length==0 %> | |
|
4 | + There is no submission | |
|
5 | + <% else %> | |
|
6 | + | |
|
7 | + <script type="text/javascript"> | |
|
8 | + var submissionCount = { | |
|
9 | + <% @submissions.each do |submission| %> | |
|
10 | + <%= submission.problem_id %> : <%= submission.number %>, | |
|
11 | + <% end %> | |
|
12 | + }; | |
|
13 | + function updateSubmissionList() { | |
|
14 | + currentProb = document.getElementById("test_request_problem_id").value; | |
|
15 | + count = submissionCount[currentProb]; | |
|
16 | + submissionSelect = document.getElementById("test_request_submission_number"); | |
|
17 | + submissionSelect.options.length = 0; | |
|
18 | + for(i=0; i<count; i++) { | |
|
19 | + submissionSelect.options[i] = new Option(""+(i+1),""+(i+1),false,false); | |
|
20 | + } | |
|
21 | + } | |
|
22 | + </script> | |
|
23 | + | |
|
24 | + <% form_for :test_request, nil, | |
|
25 | + :url => { :action => 'submit'}, | |
|
26 | + :html => { :multipart => true } do |f| %> | |
|
27 | + <table> | |
|
28 | + <tr> | |
|
29 | + <td>Task:</td> | |
|
30 | + <td> | |
|
31 | + <%= select(:test_request, | |
|
32 | + :problem_id, | |
|
33 | + @problems.collect {|p| [p.name, p.id]}, {}, | |
|
34 | + { :onclick => "updateSubmissionList();" }) %> | |
|
35 | + </td> | |
|
36 | + </tr> | |
|
37 | + <tr> | |
|
38 | + <td>Submission:</td> | |
|
39 | + <td> | |
|
40 | + <%= select(:test_request, | |
|
41 | + :submission_number, | |
|
42 | + (1..@submissions[0].number).collect {|n| [n,n]}) %> | |
|
43 | + </td> | |
|
44 | + </tr> | |
|
45 | + <tr> | |
|
46 | + <td>Input data:</td> | |
|
47 | + <td><%= f.file_field :input_file %></td> | |
|
48 | + <tr> | |
|
49 | + <td colspan="2"> | |
|
50 | + <%= submit_tag 'submit' %> | |
|
51 | + </td> | |
|
52 | + </tr> | |
|
53 | + </table> | |
|
54 | + <% end %> | |
|
55 | + | |
|
56 | + <h3>Previous requests</h3> | |
|
57 | + | |
|
58 | + <table border="1"> | |
|
59 | + <tr> | |
|
60 | + <th></td> | |
|
61 | + <th>problem</th> | |
|
62 | + <th>#</th> | |
|
63 | + <th>status</th> | |
|
64 | + </tr> | |
|
65 | + <%= render :partial => 'test_request', :collection => @user.test_requests %> | |
|
66 | + </table> | |
|
67 | + | |
|
68 | + <% end %> | |
|
69 | + |
@@ -0,0 +1,8 | |||
|
1 | + require File.dirname(__FILE__) + '/../test_helper' | |
|
2 | + | |
|
3 | + class TestControllerTest < ActionController::TestCase | |
|
4 | + # Replace this with your real tests. | |
|
5 | + def test_truth | |
|
6 | + assert true | |
|
7 | + end | |
|
8 | + end |
@@ -39,41 +39,25 | |||
|
39 | 39 | redirect_to :action => 'list' |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def get_source |
|
43 | 43 | submission = Submission.find(params[:id]) |
|
44 | 44 | if submission.user_id == session[:user_id] |
|
45 | 45 | fname = submission.problem.name + '.' + submission.language.ext |
|
46 | 46 | send_data(submission.source, |
|
47 | 47 | {:filename => fname, |
|
48 | 48 | :type => 'text/plain'}) |
|
49 | 49 | else |
|
50 | 50 | flash[:notice] = 'Error viewing source' |
|
51 | - end | |
|
52 | - end | |
|
53 | - | |
|
54 | - def test | |
|
55 | - @user = User.find(session[:user_id]) | |
|
56 | - @submissions = Submission.find_last_for_all_available_problems(@user.id) | |
|
57 | - @problems = @submissions.collect { |submission| submission.problem } | |
|
58 | - end | |
|
59 | - | |
|
60 | - def test_submit | |
|
61 | - @user = User.find(session[:user_id]) | |
|
62 | - test_request = TestRequest.new_from_form_params(@user,params[:test_request]) | |
|
63 | - if test_request.save | |
|
64 | - redirect_to :action => 'test' | |
|
65 | - else | |
|
66 | - flash[:notice] = 'Error saving your test submission' | |
|
67 | - render :action => 'test' | |
|
51 | + redirect_to :action => 'list' | |
|
68 | 52 | end |
|
69 | 53 | end |
|
70 | 54 | |
|
71 | 55 | protected |
|
72 | 56 | def prepare_list_information |
|
73 | 57 | @problems = Problem.find_available_problems |
|
74 | 58 | @prob_submissions = Array.new |
|
75 | 59 | @user = User.find(session[:user_id]) |
|
76 | 60 | @problems.each do |p| |
|
77 | 61 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
78 | 62 | if sub!=nil |
|
79 | 63 | @prob_submissions << { :count => sub.number, :submission => sub } |
@@ -1,22 +1,22 | |||
|
1 | 1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | 2 | module ApplicationHelper |
|
3 | 3 | |
|
4 | 4 | def user_header |
|
5 | 5 | menu_items = '' |
|
6 | 6 | user = User.find(session[:user_id]) |
|
7 | 7 | |
|
8 | 8 | # main page |
|
9 | 9 | append_to menu_items, '[Main]', 'main', 'list' |
|
10 |
- append_to menu_items, '[Test]', ' |
|
|
10 | + append_to menu_items, '[Test]', 'test', 'index' | |
|
11 | 11 | |
|
12 | 12 | # admin menu |
|
13 | 13 | if (user!=nil) and (user.admin?) |
|
14 | 14 | append_to menu_items, '[Problem admin]', 'problems', 'index' |
|
15 | 15 | append_to menu_items, '[User admin]', 'user_admin', 'index' |
|
16 | 16 | append_to menu_items, '[User stat]', 'user_admin', 'user_stat' |
|
17 | 17 | end |
|
18 | 18 | |
|
19 | 19 | # general options |
|
20 | 20 | append_to menu_items, '[Settings]', 'users', 'index' |
|
21 | 21 | append_to menu_items, '[Log out]', 'main', 'login' |
|
22 | 22 |
@@ -26,33 +26,33 | |||
|
26 | 26 | def problem_name |
|
27 | 27 | TestRequest.name_of(self.problem) |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def language |
|
31 | 31 | self.submission.language |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def self.get_inqueue_and_change_status(status) |
|
35 | 35 | # since there will be only one grader grading TestRequest |
|
36 | 36 | # we do not need locking (hopefully) |
|
37 | 37 | |
|
38 |
- t |
|
|
38 | + test_request = TestRequest.find(:first, | |
|
39 | 39 | :order => "created_at", |
|
40 | 40 | :conditions => {:status=> Task::STATUS_INQUEUE}) |
|
41 |
- if t |
|
|
42 |
- t |
|
|
43 |
- t |
|
|
41 | + if test_request!=nil | |
|
42 | + test_request.status = status | |
|
43 | + test_request.save! | |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | - task | |
|
46 | + test_request | |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | # interfacing with form |
|
50 | 50 | def self.new_from_form_params(user,params) |
|
51 | 51 | test_request = TestRequest.new |
|
52 | 52 | test_request.user = user |
|
53 | 53 | problem = Problem.find(params[:problem_id]) |
|
54 | 54 | test_request.problem = problem |
|
55 | 55 | test_request.submission = |
|
56 | 56 | Submission.find_by_user_problem_number(user.id, |
|
57 | 57 | problem.id, |
|
58 | 58 | params[:submission_number]) |
@@ -1,22 +1,20 | |||
|
1 | 1 | <div class="title">Hello <%=h @user.full_name %></div> |
|
2 | 2 | Current time is <%= format_short_time(Time.new) %>. |
|
3 | 3 | |
|
4 | 4 | <div class="submitbox"> |
|
5 | 5 | <%= error_messages_for 'submission' %> |
|
6 | 6 | <%= render :partial => 'submission_box' %> |
|
7 | 7 | </div> |
|
8 | 8 | |
|
9 | 9 | <hr/> |
|
10 | 10 | |
|
11 | - <p style="color: red"><%= flash[:notice] %></p> | |
|
12 | - | |
|
13 | 11 | <div class="problist"> |
|
14 | 12 | <%= render :partial => 'problem', :collection => @problems %> |
|
15 | 13 | </div> |
|
16 | 14 | |
|
17 | 15 | <hr /> |
|
18 | 16 | |
|
19 | 17 | <div class="submitbox"> |
|
20 | 18 | <%= render :partial => 'submission_box' %> |
|
21 | 19 | </div> |
|
22 | 20 |
deleted file |
deleted file |
You need to be logged in to leave comments.
Login now