Description:
added user settings git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@37 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

r13:a663af8c2813 - - 15 files changed: 163 inserted, 108 deleted

@@ -0,0 +1,15
1 + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 +
4 + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 + <head>
6 + <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7 + <title>Grader!</title>
8 + <%= stylesheet_link_tag 'application' %>
9 + </head>
10 + <body>
11 +
12 + <%= yield %>
13 +
14 + </body>
15 + </html>
@@ -0,0 +1,92
1 + # This file is auto-generated from the current state of the database. Instead of editing this file,
2 + # please use the migrations feature of ActiveRecord to incrementally modify your database, and
3 + # then regenerate this schema definition.
4 + #
5 + # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 + # to create the application database on another system, you should be using db:schema:load, not running
7 + # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 + # you'll amass, the slower it'll run and the greater likelihood for issues).
9 + #
10 + # It's strongly recommended to check this file into your version control system.
11 +
12 + ActiveRecord::Schema.define(:version => 11) do
13 +
14 + create_table "languages", :force => true do |t|
15 + t.string "name", :limit => 10
16 + t.string "pretty_name"
17 + t.string "ext", :limit => 10
18 + end
19 +
20 + create_table "problems", :force => true do |t|
21 + t.string "name", :limit => 30
22 + t.string "full_name"
23 + t.integer "full_score"
24 + t.date "date_added"
25 + t.boolean "available"
26 + end
27 +
28 + create_table "rights", :force => true do |t|
29 + t.string "name"
30 + t.string "controller"
31 + t.string "action"
32 + end
33 +
34 + create_table "rights_roles", :id => false, :force => true do |t|
35 + t.integer "right_id"
36 + t.integer "role_id"
37 + end
38 +
39 + add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
40 +
41 + create_table "roles", :force => true do |t|
42 + t.string "name"
43 + end
44 +
45 + create_table "roles_users", :id => false, :force => true do |t|
46 + t.integer "role_id"
47 + t.integer "user_id"
48 + end
49 +
50 + add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
51 +
52 + create_table "sessions", :force => true do |t|
53 + t.string "session_id"
54 + t.text "data"
55 + t.datetime "updated_at"
56 + end
57 +
58 + add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
59 + add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
60 +
61 + create_table "submissions", :force => true do |t|
62 + t.integer "user_id"
63 + t.integer "problem_id"
64 + t.integer "language_id"
65 + t.text "source"
66 + t.binary "binary"
67 + t.datetime "submitted_at"
68 + t.datetime "compiled_at"
69 + t.text "compiler_message"
70 + t.datetime "graded_at"
71 + t.integer "points"
72 + t.text "grader_comment"
73 + end
74 +
75 + add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
76 +
77 + create_table "tasks", :force => true do |t|
78 + t.integer "submission_id"
79 + t.datetime "created_at"
80 + end
81 +
82 + create_table "users", :force => true do |t|
83 + t.string "login", :limit => 10
84 + t.string "full_name"
85 + t.string "hashed_password"
86 + t.string "salt", :limit => 5
87 + t.string "alias"
88 + end
89 +
90 + add_index "users", ["login"], :name => "index_users_on_login", :unique => true
91 +
92 + end
@@ -0,0 +1,2
1 + require 'haml'
2 + Haml.init_rails(binding)
@@ -1,60 +1,61
1 1 class MainController < ApplicationController
2 2
3 3 before_filter :authenticate, :except => [:index, :login]
4 4
5 5 verify :method => :post, :only => [:submit],
6 6 :redirect_to => { :action => :index }
7 7
8 8 def index
9 9 redirect_to :action => 'login'
10 10 end
11 11
12 12 def login
13 + MainController.layout 'login'
13 14 reset_session
14 15 end
15 16
16 17 def list
17 18 @problems = Problem.find_available_problems
18 19 @prob_submissions = Array.new
19 20 @user = User.find(session[:user_id])
20 21 @problems.each do |p|
21 22 c, sub = Submission.find_by_user_and_problem(@user.id,p.id)
22 23 @prob_submissions << [c,sub]
23 24 end
24 25 end
25 26
26 27 def submit
27 28 submission = Submission.new(params[:submission])
28 29 submission.user_id = session[:user_id]
29 30 submission.language_id = 0
30 31 source = params['file'].read
31 32 if source.length > 100_000
32 33 flash[:notice] = 'Error: file too long'
33 34 elsif (lang = Submission.find_language_in_source(source))==nil
34 35 flash[:notice] = 'Error: cannot determine language used'
35 36 elsif ((submission.problem_id==-1) and
36 37 !(problem=Submission.find_problem_in_source(source)))
37 38 flash[:notice] = 'Error: cannot determine problem submitted'
38 39 elsif ((submission.problem_id==-1) and
39 40 (problem.available == false))
40 41 flash[:notice] = 'Error: problem is not available'
41 42 else
42 43 submission.problem_id = problem.id if submission.problem_id == -1
43 44 submission.source = source
44 45 submission.language_id = lang.id
45 46 submission.submitted_at = Time.new
46 47 if submission.save == false
47 48 flash[:notice] = 'Error saving your submission'
48 49 elsif Task.create(:submission_id => submission.id) == false
49 50 flash[:notice] = 'Error adding your submission to task queue'
50 51 end
51 52 end
52 53 redirect_to :action => 'list'
53 54 end
54 55
55 56 def get_source
56 57 submission = Submission.find(params[:id])
57 58 if submission.user_id == session[:user_id]
58 59 fname = submission.problem.name + '.' + submission.language.ext
59 60 send_data(submission.source,
60 61 {:filename => fname,
@@ -1,2 +1,27
1 1 class UsersController < ApplicationController
2 +
3 + before_filter :authenticate
4 +
5 + verify :method => :post, :only => [:chg_passwd],
6 + :redirect_to => { :action => :index }
7 +
8 + in_place_edit_for :user, :full_name
9 + in_place_edit_for :user, :alias
10 +
11 + def index
12 + @user = User.find(session[:user_id])
2 13 end
14 +
15 + def chg_passwd
16 + user = User.find(session[:user_id])
17 + user.password = params[:passwd]
18 + user.password_confirmation = params[:passwd_verify]
19 + if user.save
20 + flash[:notice] = 'password changed'
21 + else
22 + flash[:notice] = 'Error: password changing failed'
23 + end
24 + redirect_to :action => 'index'
25 + end
26 +
27 + end
@@ -1,3 +1,24
1 1 # Methods added to this helper will be available to all templates in the application.
2 2 module ApplicationHelper
3 +
4 + def user_options
5 + options = ''
6 + user = User.find(session[:user_id])
7 + if user.admin?
8 + options = options + ' ' +
9 + (link_to_unless_current '[Problem admin]',
10 + :controller => 'problems', :action => 'index')
11 + options = options + ' ' +
12 + (link_to_unless_current '[User admin]',
13 + :controller => 'user_admin', :action => 'index')
3 14 end
15 + options += link_to_unless_current '[Main]',
16 + :controller => 'main', :action => 'list'
17 + options += link_to_unless_current '[Settings]',
18 + :controller => 'users', :action => 'index'
19 + options = options + ' ' +
20 + link_to('[Log out]', {:controller => 'main', :action => 'login'})
21 + options
22 + end
23 +
24 + end
@@ -1,61 +1,45
1 1 module MainHelper
2 2
3 - def user_options
4 - options = ''
5 - user = User.find(session[:user_id])
6 - if user.admin?
7 - options = options + ' ' +
8 - link_to('[Problem admin]',
9 - {:controller => 'problems', :action => 'index'})
10 - options = options + ' ' +
11 - link_to('[User admin]',
12 - {:controller => 'user_admin', :action => 'index'})
13 - end
14 - options = options + ' ' +
15 - link_to('[Log out]', {:controller => 'main', :action => 'login'})
16 - options
17 - end
18 -
19 3 def format_short_time(time)
20 4 now = Time.now
21 5 st = ''
22 6 if (time.yday != now.yday) or
23 7 (time.year != now.year)
24 8 st = time.strftime("%x")
25 9 end
26 10 st + time.strftime("%X")
27 11 end
28 12
29 13 def format_compiler_msg(sub)
30 14 <<cmpmsg
31 15 <div>
32 16 <div><a href="#" onClick="n = this.parentNode.parentNode.lastChild;
33 17 if(n.style.display == 'none') { n.style.display = 'block'; }
34 18 else {n.style.display ='none'; } return false;">
35 19 Compiler message</a> (click to see)</div>
36 20 <div style="display: none">
37 21 <div class="compilermsgbody" style="border: thin solid grey; margin: 2px">
38 22 #{h(sub.compiler_message).gsub(/\n/,'<br/>')}
39 23 </div>
40 24 </div></div>
41 25 cmpmsg
42 26 end
43 27
44 28 def format_submission(sub, count)
45 29 msg = "#{count} submission(s)<br />"
46 30 if count>0
47 31 msg = msg + "Last on " +
48 32 format_short_time(sub.submitted_at) + ' ' +
49 33 link_to('[source]',{:action => 'get_source', :id => sub.id}) +
50 34 "<br />"
51 35 end
52 36 if sub!=nil and sub.graded_at!=nil
53 37 msg = msg + 'Graded at ' + format_short_time(sub.graded_at) + ', score: '+
54 38 sub.points.to_s +
55 39 ' [' + sub.grader_comment + "]<br />" +
56 40 format_compiler_msg(sub)
57 41 end
58 42 msg
59 43 end
60 44
61 45 end
@@ -1,15 +1,22
1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 3
4 4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 5 <head>
6 6 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7 7 <title>Grader!</title>
8 8 <%= stylesheet_link_tag 'application' %>
9 + <%= javascript_include_tag :defaults %>
9 10 </head>
10 11 <body>
11 12
13 + <div class="usermenu">
14 + <%= user_options %>
15 + </div>
16 +
17 + <p style="color: green"><%= flash[:notice] %></p>
18 +
12 19 <%= yield %>
13 20
14 21 </body>
15 22 </html>
@@ -1,53 +1,49
1 1 <h1>Hello <%=h @user.full_name %></h1>
2 2 (<%= Time.new %>)
3 3
4 - <div class="usermenu">
5 - <%= user_options %>
6 - </div>
7 -
8 4 <div class="submitbox">
9 5 <% form_tag({:action => 'submit'}, :multipart => true) do %>
10 6 Problem: <%= select 'submission', 'problem_id',
11 7 [['Specified in header','-1']] +
12 8 @problems.collect {|p| [p.full_name, p.id]},
13 9 :selected => '-1' %>
14 10 File: <%= file_field_tag 'file' %>
15 11 <%= submit_tag 'Submit' %>
16 12 <% end %>
17 13 </div>
18 14
19 15 <hr/>
20 16
21 17 <p style="color: red"><%= flash[:notice] %></p>
22 18
23 19 <div class="problist">
24 20 <% i = 0 %>
25 21 <% @problems.each do |p| %>
26 22 <div class="problist-each">
27 23 <div class="probname">
28 24 <%= "#{i+1}: #{p.full_name} (#{p.name})" %>
29 25 </div>
30 26 <div class="subinfo">
31 27 <%= format_submission(@prob_submissions[i][1],
32 28 @prob_submissions[i][0]) %>
33 29 </div>
34 30 </div>
35 31 <% i = i+1 %>
36 32 <% end %>
37 33 </div>
38 34
39 35 <br />
40 36 <hr />
41 37 <br />
42 38
43 39 <div class="submitbox">
44 40 <% form_tag({:action => 'submit'}, :multipart => true) do %>
45 41 Problem: <%= select 'submission', 'problem_id',
46 42 [['Specified in header','-1']] +
47 43 @problems.collect {|p| [p.full_name, p.id]},
48 44 :selected => '-1' %>
49 45 File: <%= file_field_tag 'file' %>
50 46 <%= submit_tag 'Submit' %>
51 47 <% end %>
52 48 </div>
53 49
deleted file
deleted file
deleted file
deleted file
deleted file
deleted file
You need to be logged in to leave comments. Login now