Description:
[web] added help page git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@225 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r107:be38116d08d3 - - 4 files changed: 63 inserted, 2 deleted

@@ -0,0 +1,56
1 + = user_title_bar(@user)
2 +
3 + .announcementbox
4 + %span{:class => 'title'}
5 + How to submit
6 + .announcement
7 + %p
8 + You <b>must</b> specify the language you are using
9 + in your program header. You can optionally
10 + specify the task you are submitting to.
11 +
12 + %p
13 + The possible language options are
14 + <tt>C</tt>, <tt>C++</tt>, and <tt>Pascal</tt>.
15 + The follow are examples.
16 +
17 + %table{:border => '1'}
18 + %tr
19 + %th{:width => '100px'} C
20 + %th{:width => '100px'} C++
21 + %th{:width => '100px'} Pascal
22 + %tr
23 + %td= "<tt>/*<br/>LANG: C<br/>*/</tt>"
24 + %td= "<tt>/*<br/>LANG: C++<br/>*/</tt>"
25 + %td= "<tt>{<br/>LANG: Pascal<br/>}</tt>"
26 +
27 + %p
28 + The server <b>will not</b> accept your submission,
29 + if you do not specify the language.
30 +
31 + %p
32 + Optionally, you can also specify
33 + the task with <tt>TASK:</tt> <i>taskname</i>.
34 + On the first page, the taskname for each task is
35 + shown in parentheses.
36 +
37 + %p
38 + For example, suppose you are using <tt>C++</tt>
39 + to write task <b>mobiles</b>, you put
40 +
41 + %table{:border => '1'}
42 + %tr
43 + %td{:width => '100px'}
44 + %tt <tt>/*<br/>LANG: C++<br/>TASK: mobiles<br/>*/</tt>
45 +
46 + %p
47 + on top of your source code.
48 + If you are using <tt>Pascal</tt> to write the same task,
49 + you'll use
50 +
51 + %table{:border => '1'}
52 + %tr
53 + %td{:width => '100px'}
54 + %tt <tt>{<br/>LANG: Pascal<br/>TASK: mobiles<br/>}</tt>
55 +
56 +
@@ -1,121 +1,125
1 1 class MainController < ApplicationController
2 2
3 3 before_filter :authenticate, :except => [:index, :login]
4 4
5 5 #
6 6 # COMMENT OUT: filter in each action instead
7 7 #
8 8 # before_filter :verify_time_limit, :only => [:submit]
9 9
10 10 verify :method => :post, :only => [:submit],
11 11 :redirect_to => { :action => :index }
12 12
13 13
14 14 def index
15 15 redirect_to :action => 'login'
16 16 end
17 17
18 18 def login
19 19 saved_notice = flash[:notice]
20 20 reset_session
21 21 flash[:notice] = saved_notice
22 22
23 23 render :action => 'login', :layout => 'empty'
24 24 end
25 25
26 26 def list
27 27 prepare_list_information
28 28 end
29 29
30 + def help
31 + @user = User.find(session[:user_id])
32 + end
33 +
30 34 def submit
31 35 user = User.find(session[:user_id])
32 36
33 37 @submission = Submission.new(params[:submission])
34 38 @submission.user = user
35 39 @submission.language_id = 0
36 40 if params['file']!=''
37 41 @submission.source = params['file'].read
38 42 @submission.source_filename = params['file'].original_filename
39 43 end
40 44 @submission.submitted_at = Time.new
41 45
42 46 if user.site!=nil and user.site.finished?
43 47 @submission.errors.add_to_base "The contest is over."
44 48 prepare_list_information
45 49 render :action => 'list' and return
46 50 end
47 51
48 52 if @submission.valid?
49 53 if @submission.save == false
50 54 flash[:notice] = 'Error saving your submission'
51 55 elsif Task.create(:submission_id => @submission.id,
52 56 :status => Task::STATUS_INQUEUE) == false
53 57 flash[:notice] = 'Error adding your submission to task queue'
54 58 end
55 59 else
56 60 prepare_list_information
57 61 render :action => 'list' and return
58 62 end
59 63 redirect_to :action => 'list'
60 64 end
61 65
62 66 def source
63 67 submission = Submission.find(params[:id])
64 68 if submission.user_id == session[:user_id]
65 69 if submission.problem.output_only
66 70 fname = submission.source_filename
67 71 else
68 72 fname = submission.problem.name + '.' + submission.language.ext
69 73 end
70 74 send_data(submission.source,
71 75 {:filename => fname,
72 76 :type => 'text/plain'})
73 77 else
74 78 flash[:notice] = 'Error viewing source'
75 79 redirect_to :action => 'list'
76 80 end
77 81 end
78 82
79 83 def compiler_msg
80 84 @submission = Submission.find(params[:id])
81 85 if @submission.user_id == session[:user_id]
82 86 render :action => 'compiler_msg', :layout => 'empty'
83 87 else
84 88 flash[:notice] = 'Error viewing source'
85 89 redirect_to :action => 'list'
86 90 end
87 91 end
88 92
89 93 def submission
90 94 @user = User.find(session[:user_id])
91 95 @problems = Problem.find_available_problems
92 96 if params[:id]==nil
93 97 @problem = nil
94 98 @submissions = nil
95 99 else
96 100 @problem = Problem.find_by_name(params[:id])
97 101 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id)
98 102 end
99 103 end
100 104
101 105 protected
102 106 def prepare_list_information
103 107 @problems = Problem.find_available_problems
104 108 @prob_submissions = Array.new
105 109 @user = User.find(session[:user_id])
106 110 @problems.each do |p|
107 111 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
108 112 if sub!=nil
109 113 @prob_submissions << { :count => sub.number, :submission => sub }
110 114 else
111 115 @prob_submissions << { :count => 0, :submission => nil }
112 116 end
113 117 end
114 118
115 119 @announcements = Announcement.find(:all,
116 120 :conditions => "published = 1",
117 121 :order => "created_at DESC")
118 122 end
119 123
120 124 end
121 125
@@ -1,83 +1,84
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 if (user!=nil) and (session[:admin])
9 9 # admin menu
10 10 menu_items << "<b>Administrative task:</b> "
11 11 append_to menu_items, '[Announcements]', 'announcements', 'index'
12 12 append_to menu_items, '[Msg console]', 'messages', 'console'
13 13 append_to menu_items, '[Problem admin]', 'problems', 'index'
14 14 append_to menu_items, '[User admin]', 'user_admin', 'index'
15 15 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
16 16 append_to menu_items, '[Graders]', 'graders', 'list'
17 17 append_to menu_items, '[Site config]', 'configurations', 'index'
18 18 menu_items << "<br/>"
19 19 end
20 20
21 21 # main page
22 22 append_to menu_items, '[Main]', 'main', 'list'
23 23 append_to menu_items, '[Messages]', 'messages', 'list'
24 24 append_to menu_items, '[Tasks]', 'tasks', 'list'
25 25 append_to menu_items, '[Submissions]', 'main', 'submission'
26 26 append_to menu_items, '[Test]', 'test', 'index'
27 - append_to menu_items, '[Settings]', 'users', 'index'
27 + append_to menu_items, '[Help]', 'main', 'help'
28 + #append_to menu_items, '[Settings]', 'users', 'index'
28 29 append_to menu_items, '[Log out]', 'main', 'login'
29 30
30 31 menu_items
31 32 end
32 33
33 34 def append_to(option,label, controller, action)
34 35 option << ' ' if option!=''
35 36 option << link_to_unless_current(label,
36 37 :controller => controller,
37 38 :action => action)
38 39 end
39 40
40 41 def format_short_time(time)
41 42 now = Time.now
42 43 st = ''
43 44 if (time.yday != now.yday) or
44 45 (time.year != now.year)
45 46 st = time.strftime("%x ")
46 47 end
47 48 st + time.strftime("%X")
48 49 end
49 50
50 51
51 52 def user_title_bar(user)
52 53 if user.site!=nil and user.site.finished?
53 54 contest_over_string = <<CONTEST_OVER
54 55 <tr><td colspan="2" align="center">
55 56 <span class="contest-over-msg">THE CONTEST IS OVER</span>
56 57 </td></tr>
57 58 CONTEST_OVER
58 59 end
59 60 <<TITLEBAR
60 61 <div class="title">
61 62 <table>
62 63 #{contest_over_string}
63 64 <tr>
64 65 <td class="left-col">
65 66 #{user.full_name}<br/>
66 67 Current time is #{format_short_time(Time.new)}<br/>
67 68 </td>
68 69 <td class="right-col">APIO'08</td>
69 70 </tr>
70 71 </table>
71 72 </div>
72 73 TITLEBAR
73 74 end
74 75
75 76 def read_textfile(fname,max_size=2048)
76 77 begin
77 78 File.open(fname).read(max_size)
78 79 rescue
79 80 nil
80 81 end
81 82 end
82 83
83 84 end
@@ -1,28 +1,28
1 1 = user_title_bar(@user)
2 2
3 3 - if @announcements.length!=0
4 4 .announcementbox
5 5 %span{:class => 'title'}
6 6 Announcements
7 7 = render :partial => 'announcement', :collection => @announcements
8 8
9 9 .submitbox
10 10 = error_messages_for 'submission'
11 11 = render :partial => 'submission_box'
12 12
13 13
14 14 %hr/
15 15
16 16 %table.info
17 17 %tr.info-head
18 18 %th
19 19 %th Tasks
20 20 %th # of sub(s)
21 21 %th Results
22 22 = render :partial => 'problem', :collection => @problems
23 23
24 - %hr
24 + %hr/
25 25
26 26 .submitbox
27 27 = render :partial => 'submission_box'
28 28
You need to be logged in to leave comments. Login now