Description:
enable user settings, remove APIO header git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@277 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

r138:0f4011aaed34 - - 4 files changed: 7 inserted, 6 deleted

@@ -59,49 +59,49
59 if @user.update_attributes(params[:user])
59 if @user.update_attributes(params[:user])
60 flash[:notice] = 'User was successfully updated.'
60 flash[:notice] = 'User was successfully updated.'
61 redirect_to :action => 'show', :id => @user
61 redirect_to :action => 'show', :id => @user
62 else
62 else
63 render :action => 'edit'
63 render :action => 'edit'
64 end
64 end
65 end
65 end
66
66
67 def destroy
67 def destroy
68 User.find(params[:id]).destroy
68 User.find(params[:id]).destroy
69 redirect_to :action => 'list'
69 redirect_to :action => 'list'
70 end
70 end
71
71
72 def user_stat
72 def user_stat
73 @problems = Problem.find_available_problems
73 @problems = Problem.find_available_problems
74 @users = User.find(:all)
74 @users = User.find(:all)
75 @scorearray = Array.new
75 @scorearray = Array.new
76 @users.each do |u|
76 @users.each do |u|
77 ustat = Array.new
77 ustat = Array.new
78 ustat[0] = u.login
78 ustat[0] = u.login
79 ustat[1] = u.full_name
79 ustat[1] = u.full_name
80 @problems.each do |p|
80 @problems.each do |p|
81 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
81 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
82 if (sub!=nil) and (sub.points!=nil)
82 if (sub!=nil) and (sub.points!=nil)
83 - ustat << [sub.points, (sub.points>=p.full_score)]
83 + ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
84 else
84 else
85 ustat << [0,false]
85 ustat << [0,false]
86 end
86 end
87 end
87 end
88 @scorearray << ustat
88 @scorearray << ustat
89 end
89 end
90 end
90 end
91
91
92 def import
92 def import
93 if params[:file]==''
93 if params[:file]==''
94 flash[:notice] = 'Error importing no file'
94 flash[:notice] = 'Error importing no file'
95 redirect_to :action => 'list' and return
95 redirect_to :action => 'list' and return
96 end
96 end
97 import_from_file(params[:file])
97 import_from_file(params[:file])
98 end
98 end
99
99
100 protected
100 protected
101
101
102 def import_from_file(f)
102 def import_from_file(f)
103 data_hash = YAML.load(f)
103 data_hash = YAML.load(f)
104 @import_log = ""
104 @import_log = ""
105
105
106 country_data = data_hash[:countries]
106 country_data = data_hash[:countries]
107 site_data = data_hash[:sites]
107 site_data = data_hash[:sites]
@@ -1,29 +1,30
1 class UsersController < ApplicationController
1 class UsersController < ApplicationController
2
2
3 before_filter :authenticate
3 before_filter :authenticate
4
4
5 verify :method => :post, :only => [:chg_passwd],
5 verify :method => :post, :only => [:chg_passwd],
6 :redirect_to => { :action => :index }
6 :redirect_to => { :action => :index }
7
7
8 in_place_edit_for :user, :alias_for_editing
8 in_place_edit_for :user, :alias_for_editing
9 in_place_edit_for :user, :email_for_editing
9 in_place_edit_for :user, :email_for_editing
10
10
11 def index
11 def index
12 - # ... disable in this contest ...
12 + # uncomment below to disable settings
13 - # @user = User.find(session[:user_id])
13 + #redirect_to :controller => 'main', :action => 'list'
14 - redirect_to :controller => 'main', :action => 'list'
14 +
15 + @user = User.find(session[:user_id])
15 end
16 end
16
17
17 def chg_passwd
18 def chg_passwd
18 user = User.find(session[:user_id])
19 user = User.find(session[:user_id])
19 user.password = params[:passwd]
20 user.password = params[:passwd]
20 user.password_confirmation = params[:passwd_verify]
21 user.password_confirmation = params[:passwd_verify]
21 if user.save
22 if user.save
22 flash[:notice] = 'password changed'
23 flash[:notice] = 'password changed'
23 else
24 else
24 flash[:notice] = 'Error: password changing failed'
25 flash[:notice] = 'Error: password changing failed'
25 end
26 end
26 redirect_to :action => 'index'
27 redirect_to :action => 'index'
27 end
28 end
28
29
29 end
30 end
@@ -9,49 +9,49
9
9
10 if (user!=nil) and (session[:admin])
10 if (user!=nil) and (session[:admin])
11 # admin menu
11 # admin menu
12 menu_items << "<b>Administrative task:</b> "
12 menu_items << "<b>Administrative task:</b> "
13 append_to menu_items, '[Announcements]', 'announcements', 'index'
13 append_to menu_items, '[Announcements]', 'announcements', 'index'
14 append_to menu_items, '[Msg console]', 'messages', 'console'
14 append_to menu_items, '[Msg console]', 'messages', 'console'
15 append_to menu_items, '[Problem admin]', 'problems', 'index'
15 append_to menu_items, '[Problem admin]', 'problems', 'index'
16 append_to menu_items, '[User admin]', 'user_admin', 'index'
16 append_to menu_items, '[User admin]', 'user_admin', 'index'
17 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
17 append_to menu_items, '[User stat]', 'user_admin', 'user_stat'
18 append_to menu_items, '[Graders]', 'graders', 'list'
18 append_to menu_items, '[Graders]', 'graders', 'list'
19 append_to menu_items, '[Site config]', 'configurations', 'index'
19 append_to menu_items, '[Site config]', 'configurations', 'index'
20 menu_items << "<br/>"
20 menu_items << "<br/>"
21 end
21 end
22
22
23 # main page
23 # main page
24 append_to menu_items, '[Main]', 'main', 'list'
24 append_to menu_items, '[Main]', 'main', 'list'
25 append_to menu_items, '[Messages]', 'messages', 'list'
25 append_to menu_items, '[Messages]', 'messages', 'list'
26
26
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
28 append_to menu_items, '[Tasks]', 'tasks', 'list'
28 append_to menu_items, '[Tasks]', 'tasks', 'list'
29 append_to menu_items, '[Submissions]', 'main', 'submission'
29 append_to menu_items, '[Submissions]', 'main', 'submission'
30 append_to menu_items, '[Test]', 'test', 'index'
30 append_to menu_items, '[Test]', 'test', 'index'
31 end
31 end
32 append_to menu_items, '[Help]', 'main', 'help'
32 append_to menu_items, '[Help]', 'main', 'help'
33 - #append_to menu_items, '[Settings]', 'users', 'index'
33 + append_to menu_items, '[Settings]', 'users', 'index'
34 append_to menu_items, '[Log out]', 'main', 'login'
34 append_to menu_items, '[Log out]', 'main', 'login'
35
35
36 menu_items
36 menu_items
37 end
37 end
38
38
39 def append_to(option,label, controller, action)
39 def append_to(option,label, controller, action)
40 option << ' ' if option!=''
40 option << ' ' if option!=''
41 option << link_to_unless_current(label,
41 option << link_to_unless_current(label,
42 :controller => controller,
42 :controller => controller,
43 :action => action)
43 :action => action)
44 end
44 end
45
45
46 def format_short_time(time)
46 def format_short_time(time)
47 now = Time.now.gmtime
47 now = Time.now.gmtime
48 st = ''
48 st = ''
49 if (time.yday != now.yday) or
49 if (time.yday != now.yday) or
50 (time.year != now.year)
50 (time.year != now.year)
51 st = time.strftime("%x ")
51 st = time.strftime("%x ")
52 end
52 end
53 st + time.strftime("%X")
53 st + time.strftime("%X")
54 end
54 end
55
55
56 def read_textfile(fname,max_size=2048)
56 def read_textfile(fname,max_size=2048)
57 begin
57 begin
@@ -1,22 +1,22
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
3
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
5 <head>
6 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7 - <title>APIO'08</title>
7 + <title>Grader</title>
8 <%= stylesheet_link_tag 'application' %>
8 <%= stylesheet_link_tag 'application' %>
9 <%= yield :head %>
9 <%= yield :head %>
10 </head>
10 </head>
11 <body>
11 <body>
12
12
13 <div class="userbar">
13 <div class="userbar">
14 <%= user_header %>
14 <%= user_header %>
15 </div>
15 </div>
16
16
17 <%= content_tag(:p,flash[:notice],:style => "color:green") if flash[:notice]!=nil %>
17 <%= content_tag(:p,flash[:notice],:style => "color:green") if flash[:notice]!=nil %>
18
18
19 <%= yield %>
19 <%= yield %>
20
20
21 </body>
21 </body>
22 </html>
22 </html>
You need to be logged in to leave comments. Login now