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,77 +1,81
1 class MainController < ApplicationController
1 class MainController < ApplicationController
2
2
3 before_filter :authenticate, :except => [:index, :login]
3 before_filter :authenticate, :except => [:index, :login]
4
4
5 #
5 #
6 # COMMENT OUT: filter in each action instead
6 # COMMENT OUT: filter in each action instead
7 #
7 #
8 # before_filter :verify_time_limit, :only => [:submit]
8 # before_filter :verify_time_limit, :only => [:submit]
9
9
10 verify :method => :post, :only => [:submit],
10 verify :method => :post, :only => [:submit],
11 :redirect_to => { :action => :index }
11 :redirect_to => { :action => :index }
12
12
13
13
14 def index
14 def index
15 redirect_to :action => 'login'
15 redirect_to :action => 'login'
16 end
16 end
17
17
18 def login
18 def login
19 saved_notice = flash[:notice]
19 saved_notice = flash[:notice]
20 reset_session
20 reset_session
21 flash[:notice] = saved_notice
21 flash[:notice] = saved_notice
22
22
23 render :action => 'login', :layout => 'empty'
23 render :action => 'login', :layout => 'empty'
24 end
24 end
25
25
26 def list
26 def list
27 prepare_list_information
27 prepare_list_information
28 end
28 end
29
29
30 + def help
31 + @user = User.find(session[:user_id])
32 + end
33 +
30 def submit
34 def submit
31 user = User.find(session[:user_id])
35 user = User.find(session[:user_id])
32
36
33 @submission = Submission.new(params[:submission])
37 @submission = Submission.new(params[:submission])
34 @submission.user = user
38 @submission.user = user
35 @submission.language_id = 0
39 @submission.language_id = 0
36 if params['file']!=''
40 if params['file']!=''
37 @submission.source = params['file'].read
41 @submission.source = params['file'].read
38 @submission.source_filename = params['file'].original_filename
42 @submission.source_filename = params['file'].original_filename
39 end
43 end
40 @submission.submitted_at = Time.new
44 @submission.submitted_at = Time.new
41
45
42 if user.site!=nil and user.site.finished?
46 if user.site!=nil and user.site.finished?
43 @submission.errors.add_to_base "The contest is over."
47 @submission.errors.add_to_base "The contest is over."
44 prepare_list_information
48 prepare_list_information
45 render :action => 'list' and return
49 render :action => 'list' and return
46 end
50 end
47
51
48 if @submission.valid?
52 if @submission.valid?
49 if @submission.save == false
53 if @submission.save == false
50 flash[:notice] = 'Error saving your submission'
54 flash[:notice] = 'Error saving your submission'
51 elsif Task.create(:submission_id => @submission.id,
55 elsif Task.create(:submission_id => @submission.id,
52 :status => Task::STATUS_INQUEUE) == false
56 :status => Task::STATUS_INQUEUE) == false
53 flash[:notice] = 'Error adding your submission to task queue'
57 flash[:notice] = 'Error adding your submission to task queue'
54 end
58 end
55 else
59 else
56 prepare_list_information
60 prepare_list_information
57 render :action => 'list' and return
61 render :action => 'list' and return
58 end
62 end
59 redirect_to :action => 'list'
63 redirect_to :action => 'list'
60 end
64 end
61
65
62 def source
66 def source
63 submission = Submission.find(params[:id])
67 submission = Submission.find(params[:id])
64 if submission.user_id == session[:user_id]
68 if submission.user_id == session[:user_id]
65 if submission.problem.output_only
69 if submission.problem.output_only
66 fname = submission.source_filename
70 fname = submission.source_filename
67 else
71 else
68 fname = submission.problem.name + '.' + submission.language.ext
72 fname = submission.problem.name + '.' + submission.language.ext
69 end
73 end
70 send_data(submission.source,
74 send_data(submission.source,
71 {:filename => fname,
75 {:filename => fname,
72 :type => 'text/plain'})
76 :type => 'text/plain'})
73 else
77 else
74 flash[:notice] = 'Error viewing source'
78 flash[:notice] = 'Error viewing source'
75 redirect_to :action => 'list'
79 redirect_to :action => 'list'
76 end
80 end
77 end
81 end
@@ -1,75 +1,76
1 # Methods added to this helper will be available to all templates in the application.
1 # Methods added to this helper will be available to all templates in the application.
2 module ApplicationHelper
2 module ApplicationHelper
3
3
4 def user_header
4 def user_header
5 menu_items = ''
5 menu_items = ''
6 user = User.find(session[:user_id])
6 user = User.find(session[:user_id])
7
7
8 if (user!=nil) and (session[:admin])
8 if (user!=nil) and (session[:admin])
9 # admin menu
9 # admin menu
10 menu_items << "<b>Administrative task:</b> "
10 menu_items << "<b>Administrative task:</b> "
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
13 append_to menu_items, '[Problem admin]', 'problems', 'index'
13 append_to menu_items, '[Problem admin]', 'problems', 'index'
14 append_to menu_items, '[User admin]', 'user_admin', 'index'
14 append_to menu_items, '[User admin]', 'user_admin', 'index'
15 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
15 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
16 append_to menu_items, '[Graders]', 'graders', 'list'
16 append_to menu_items, '[Graders]', 'graders', 'list'
17 append_to menu_items, '[Site config]', 'configurations', 'index'
17 append_to menu_items, '[Site config]', 'configurations', 'index'
18 menu_items << "<br/>"
18 menu_items << "<br/>"
19 end
19 end
20
20
21 # main page
21 # main page
22 append_to menu_items, '[Main]', 'main', 'list'
22 append_to menu_items, '[Main]', 'main', 'list'
23 append_to menu_items, '[Messages]', 'messages', 'list'
23 append_to menu_items, '[Messages]', 'messages', 'list'
24 append_to menu_items, '[Tasks]', 'tasks', 'list'
24 append_to menu_items, '[Tasks]', 'tasks', 'list'
25 append_to menu_items, '[Submissions]', 'main', 'submission'
25 append_to menu_items, '[Submissions]', 'main', 'submission'
26 append_to menu_items, '[Test]', 'test', 'index'
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 append_to menu_items, '[Log out]', 'main', 'login'
29 append_to menu_items, '[Log out]', 'main', 'login'
29
30
30 menu_items
31 menu_items
31 end
32 end
32
33
33 def append_to(option,label, controller, action)
34 def append_to(option,label, controller, action)
34 option << ' ' if option!=''
35 option << ' ' if option!=''
35 option << link_to_unless_current(label,
36 option << link_to_unless_current(label,
36 :controller => controller,
37 :controller => controller,
37 :action => action)
38 :action => action)
38 end
39 end
39
40
40 def format_short_time(time)
41 def format_short_time(time)
41 now = Time.now
42 now = Time.now
42 st = ''
43 st = ''
43 if (time.yday != now.yday) or
44 if (time.yday != now.yday) or
44 (time.year != now.year)
45 (time.year != now.year)
45 st = time.strftime("%x ")
46 st = time.strftime("%x ")
46 end
47 end
47 st + time.strftime("%X")
48 st + time.strftime("%X")
48 end
49 end
49
50
50
51
51 def user_title_bar(user)
52 def user_title_bar(user)
52 if user.site!=nil and user.site.finished?
53 if user.site!=nil and user.site.finished?
53 contest_over_string = <<CONTEST_OVER
54 contest_over_string = <<CONTEST_OVER
54 <tr><td colspan="2" align="center">
55 <tr><td colspan="2" align="center">
55 <span class="contest-over-msg">THE CONTEST IS OVER</span>
56 <span class="contest-over-msg">THE CONTEST IS OVER</span>
56 </td></tr>
57 </td></tr>
57 CONTEST_OVER
58 CONTEST_OVER
58 end
59 end
59 <<TITLEBAR
60 <<TITLEBAR
60 <div class="title">
61 <div class="title">
61 <table>
62 <table>
62 #{contest_over_string}
63 #{contest_over_string}
63 <tr>
64 <tr>
64 <td class="left-col">
65 <td class="left-col">
65 #{user.full_name}<br/>
66 #{user.full_name}<br/>
66 Current time is #{format_short_time(Time.new)}<br/>
67 Current time is #{format_short_time(Time.new)}<br/>
67 </td>
68 </td>
68 <td class="right-col">APIO'08</td>
69 <td class="right-col">APIO'08</td>
69 </tr>
70 </tr>
70 </table>
71 </table>
71 </div>
72 </div>
72 TITLEBAR
73 TITLEBAR
73 end
74 end
74
75
75 def read_textfile(fname,max_size=2048)
76 def read_textfile(fname,max_size=2048)
@@ -1,28 +1,28
1 = user_title_bar(@user)
1 = user_title_bar(@user)
2
2
3 - if @announcements.length!=0
3 - if @announcements.length!=0
4 .announcementbox
4 .announcementbox
5 %span{:class => 'title'}
5 %span{:class => 'title'}
6 Announcements
6 Announcements
7 = render :partial => 'announcement', :collection => @announcements
7 = render :partial => 'announcement', :collection => @announcements
8
8
9 .submitbox
9 .submitbox
10 = error_messages_for 'submission'
10 = error_messages_for 'submission'
11 = render :partial => 'submission_box'
11 = render :partial => 'submission_box'
12
12
13
13
14 %hr/
14 %hr/
15
15
16 %table.info
16 %table.info
17 %tr.info-head
17 %tr.info-head
18 %th
18 %th
19 %th Tasks
19 %th Tasks
20 %th # of sub(s)
20 %th # of sub(s)
21 %th Results
21 %th Results
22 = render :partial => 'problem', :collection => @problems
22 = render :partial => 'problem', :collection => @problems
23
23
24 - %hr
24 + %hr/
25
25
26 .submitbox
26 .submitbox
27 = render :partial => 'submission_box'
27 = render :partial => 'submission_box'
28
28
You need to be logged in to leave comments. Login now