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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r138:0f4011aaed34 - - 4 files changed: 7 inserted, 6 deleted
@@ -1,158 +1,158 | |||
|
1 | 1 | class UserAdminController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | list |
|
7 | 7 | render :action => 'list' |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | 10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | 11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
12 | 12 | :redirect_to => { :action => :list } |
|
13 | 13 | |
|
14 | 14 | def list |
|
15 | 15 | @users = User.find(:all) |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def show |
|
19 | 19 | @user = User.find(params[:id]) |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def new |
|
23 | 23 | @user = User.new |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def create |
|
27 | 27 | @user = User.new(params[:user]) |
|
28 | 28 | if @user.save |
|
29 | 29 | flash[:notice] = 'User was successfully created.' |
|
30 | 30 | redirect_to :action => 'list' |
|
31 | 31 | else |
|
32 | 32 | render :action => 'new' |
|
33 | 33 | end |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def create_from_list |
|
37 | 37 | lines = params[:user_list] |
|
38 | 38 | lines.split("\n").each do |line| |
|
39 | 39 | items = line.split(',') |
|
40 | 40 | if items.length==4 |
|
41 | 41 | user = User.new |
|
42 | 42 | user.login = items[0] |
|
43 | 43 | user.full_name = items[1] |
|
44 | 44 | user.alias = items[2] |
|
45 | 45 | user.password = items[3] |
|
46 | 46 | user.password_confirmation = items[3] |
|
47 | 47 | user.save |
|
48 | 48 | end |
|
49 | 49 | end |
|
50 | 50 | redirect_to :action => 'list' |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def edit |
|
54 | 54 | @user = User.find(params[:id]) |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def update |
|
58 | 58 | @user = User.find(params[:id]) |
|
59 | 59 | if @user.update_attributes(params[:user]) |
|
60 | 60 | flash[:notice] = 'User was successfully updated.' |
|
61 | 61 | redirect_to :action => 'show', :id => @user |
|
62 | 62 | else |
|
63 | 63 | render :action => 'edit' |
|
64 | 64 | end |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def destroy |
|
68 | 68 | User.find(params[:id]).destroy |
|
69 | 69 | redirect_to :action => 'list' |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def user_stat |
|
73 | 73 | @problems = Problem.find_available_problems |
|
74 | 74 | @users = User.find(:all) |
|
75 | 75 | @scorearray = Array.new |
|
76 | 76 | @users.each do |u| |
|
77 | 77 | ustat = Array.new |
|
78 | 78 | ustat[0] = u.login |
|
79 | 79 | ustat[1] = u.full_name |
|
80 | 80 | @problems.each do |p| |
|
81 | 81 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
82 | 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 | 84 | else |
|
85 | 85 | ustat << [0,false] |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 | 88 | @scorearray << ustat |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def import |
|
93 | 93 | if params[:file]=='' |
|
94 | 94 | flash[:notice] = 'Error importing no file' |
|
95 | 95 | redirect_to :action => 'list' and return |
|
96 | 96 | end |
|
97 | 97 | import_from_file(params[:file]) |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | protected |
|
101 | 101 | |
|
102 | 102 | def import_from_file(f) |
|
103 | 103 | data_hash = YAML.load(f) |
|
104 | 104 | @import_log = "" |
|
105 | 105 | |
|
106 | 106 | country_data = data_hash[:countries] |
|
107 | 107 | site_data = data_hash[:sites] |
|
108 | 108 | user_data = data_hash[:users] |
|
109 | 109 | |
|
110 | 110 | # import country |
|
111 | 111 | countries = {} |
|
112 | 112 | country_data.each_pair do |id,country| |
|
113 | 113 | c = Country.find_by_name(country[:name]) |
|
114 | 114 | if c!=nil |
|
115 | 115 | countries[id] = c |
|
116 | 116 | @import_log << "Found #{country[:name]}\n" |
|
117 | 117 | else |
|
118 | 118 | countries[id] = Country.new(:name => country[:name]) |
|
119 | 119 | countries[id].save |
|
120 | 120 | @import_log << "Created #{country[:name]}\n" |
|
121 | 121 | end |
|
122 | 122 | end |
|
123 | 123 | |
|
124 | 124 | # import sites |
|
125 | 125 | sites = {} |
|
126 | 126 | site_data.each_pair do |id,site| |
|
127 | 127 | s = Site.find_by_name(site[:name]) |
|
128 | 128 | if s!=nil |
|
129 | 129 | @import_log << "Found #{site[:name]}\n" |
|
130 | 130 | else |
|
131 | 131 | s = Site.new(:name => site[:name]) |
|
132 | 132 | @import_log << "Created #{site[:name]}\n" |
|
133 | 133 | end |
|
134 | 134 | s.password = site[:password] |
|
135 | 135 | s.country = countries[site[:country_id]] |
|
136 | 136 | s.save |
|
137 | 137 | sites[id] = s |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | # import users |
|
141 | 141 | user_data.each_pair do |id,user| |
|
142 | 142 | u = User.find_by_login(user[:login]) |
|
143 | 143 | if u!=nil |
|
144 | 144 | @import_log << "Found #{user[:login]}\n" |
|
145 | 145 | else |
|
146 | 146 | u = User.new(:login => user[:login]) |
|
147 | 147 | @import_log << "Created #{user[:login]}\n" |
|
148 | 148 | end |
|
149 | 149 | u.full_name = user[:name] |
|
150 | 150 | u.password = user[:password] |
|
151 | 151 | u.country = countries[user[:country_id]] |
|
152 | 152 | u.site = sites[user[:site_id]] |
|
153 | 153 | u.save |
|
154 | 154 | end |
|
155 | 155 | |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | end |
@@ -1,29 +1,30 | |||
|
1 | 1 | class UsersController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate |
|
4 | 4 | |
|
5 | 5 | verify :method => :post, :only => [:chg_passwd], |
|
6 | 6 | :redirect_to => { :action => :index } |
|
7 | 7 | |
|
8 | 8 | in_place_edit_for :user, :alias_for_editing |
|
9 | 9 | in_place_edit_for :user, :email_for_editing |
|
10 | 10 | |
|
11 | 11 | def index |
|
12 | - # ... disable in this contest ... | |
|
13 | - # @user = User.find(session[:user_id]) | |
|
14 | - redirect_to :controller => 'main', :action => 'list' | |
|
12 | + # uncomment below to disable settings | |
|
13 | + #redirect_to :controller => 'main', :action => 'list' | |
|
14 | + | |
|
15 | + @user = User.find(session[:user_id]) | |
|
15 | 16 | end |
|
16 | 17 | |
|
17 | 18 | def chg_passwd |
|
18 | 19 | user = User.find(session[:user_id]) |
|
19 | 20 | user.password = params[:passwd] |
|
20 | 21 | user.password_confirmation = params[:passwd_verify] |
|
21 | 22 | if user.save |
|
22 | 23 | flash[:notice] = 'password changed' |
|
23 | 24 | else |
|
24 | 25 | flash[:notice] = 'Error: password changing failed' |
|
25 | 26 | end |
|
26 | 27 | redirect_to :action => 'index' |
|
27 | 28 | end |
|
28 | 29 | |
|
29 | 30 | end |
@@ -1,113 +1,113 | |||
|
1 | 1 | # Methods added to this helper will be available to all templates in the application. |
|
2 | 2 | module ApplicationHelper |
|
3 | 3 | |
|
4 | 4 | SYSTEM_MODE_CONF_KEY = 'system.mode' |
|
5 | 5 | |
|
6 | 6 | def user_header |
|
7 | 7 | menu_items = '' |
|
8 | 8 | user = User.find(session[:user_id]) |
|
9 | 9 | |
|
10 | 10 | if (user!=nil) and (session[:admin]) |
|
11 | 11 | # admin menu |
|
12 | 12 | menu_items << "<b>Administrative task:</b> " |
|
13 | 13 | append_to menu_items, '[Announcements]', 'announcements', 'index' |
|
14 | 14 | append_to menu_items, '[Msg console]', 'messages', 'console' |
|
15 | 15 | append_to menu_items, '[Problem admin]', 'problems', 'index' |
|
16 | 16 | append_to menu_items, '[User admin]', 'user_admin', 'index' |
|
17 | 17 | append_to menu_items, '[User stat]', 'user_admin', 'user_stat' |
|
18 | 18 | append_to menu_items, '[Graders]', 'graders', 'list' |
|
19 | 19 | append_to menu_items, '[Site config]', 'configurations', 'index' |
|
20 | 20 | menu_items << "<br/>" |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | # main page |
|
24 | 24 | append_to menu_items, '[Main]', 'main', 'list' |
|
25 | 25 | append_to menu_items, '[Messages]', 'messages', 'list' |
|
26 | 26 | |
|
27 | 27 | if (user!=nil) and (Configuration.show_tasks_to?(user)) |
|
28 | 28 | append_to menu_items, '[Tasks]', 'tasks', 'list' |
|
29 | 29 | append_to menu_items, '[Submissions]', 'main', 'submission' |
|
30 | 30 | append_to menu_items, '[Test]', 'test', 'index' |
|
31 | 31 | end |
|
32 | 32 | append_to menu_items, '[Help]', 'main', 'help' |
|
33 |
- |
|
|
33 | + append_to menu_items, '[Settings]', 'users', 'index' | |
|
34 | 34 | append_to menu_items, '[Log out]', 'main', 'login' |
|
35 | 35 | |
|
36 | 36 | menu_items |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def append_to(option,label, controller, action) |
|
40 | 40 | option << ' ' if option!='' |
|
41 | 41 | option << link_to_unless_current(label, |
|
42 | 42 | :controller => controller, |
|
43 | 43 | :action => action) |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def format_short_time(time) |
|
47 | 47 | now = Time.now.gmtime |
|
48 | 48 | st = '' |
|
49 | 49 | if (time.yday != now.yday) or |
|
50 | 50 | (time.year != now.year) |
|
51 | 51 | st = time.strftime("%x ") |
|
52 | 52 | end |
|
53 | 53 | st + time.strftime("%X") |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def read_textfile(fname,max_size=2048) |
|
57 | 57 | begin |
|
58 | 58 | File.open(fname).read(max_size) |
|
59 | 59 | rescue |
|
60 | 60 | nil |
|
61 | 61 | end |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def user_title_bar(user) |
|
65 | 65 | header = '' |
|
66 | 66 | time_left = '' |
|
67 | 67 | |
|
68 | 68 | # |
|
69 | 69 | # if the contest is over |
|
70 | 70 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' |
|
71 | 71 | if user.site!=nil and user.site.finished? |
|
72 | 72 | header = <<CONTEST_OVER |
|
73 | 73 | <tr><td colspan="2" align="center"> |
|
74 | 74 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
75 | 75 | </td></tr> |
|
76 | 76 | CONTEST_OVER |
|
77 | 77 | end |
|
78 | 78 | if user.site!=nil |
|
79 | 79 | time_left = ". Time left: #{Time.at(user.site.time_left).gmtime.strftime("%X")}" |
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | # |
|
84 | 84 | # if the contest is in the anaysis mode |
|
85 | 85 | if Configuration[SYSTEM_MODE_CONF_KEY]=='analysis' |
|
86 | 86 | header = <<ANALYSISMODE |
|
87 | 87 | <tr><td colspan="2" align="center"> |
|
88 | 88 | <span class="contest-over-msg">ANALYSIS MODE</span> |
|
89 | 89 | </td></tr> |
|
90 | 90 | ANALYSISMODE |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | # |
|
94 | 94 | # build real title bar |
|
95 | 95 | <<TITLEBAR |
|
96 | 96 | <div class="title"> |
|
97 | 97 | <table> |
|
98 | 98 | #{header} |
|
99 | 99 | <tr> |
|
100 | 100 | <td class="left-col"> |
|
101 | 101 | #{user.full_name}<br/> |
|
102 | 102 | Current time is #{format_short_time(Time.new.gmtime)} UTC |
|
103 | 103 | #{time_left} |
|
104 | 104 | <br/> |
|
105 | 105 | </td> |
|
106 | 106 | <td class="right-col">APIO'08</td> |
|
107 | 107 | </tr> |
|
108 | 108 | </table> |
|
109 | 109 | </div> |
|
110 | 110 | TITLEBAR |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | end |
@@ -1,22 +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 |
- <title> |
|
|
7 | + <title>Grader</title> | |
|
8 | 8 | <%= stylesheet_link_tag 'application' %> |
|
9 | 9 | <%= yield :head %> |
|
10 | 10 | </head> |
|
11 | 11 | <body> |
|
12 | 12 | |
|
13 | 13 | <div class="userbar"> |
|
14 | 14 | <%= user_header %> |
|
15 | 15 | </div> |
|
16 | 16 | |
|
17 | 17 | <%= content_tag(:p,flash[:notice],:style => "color:green") if flash[:notice]!=nil %> |
|
18 | 18 | |
|
19 | 19 | <%= yield %> |
|
20 | 20 | |
|
21 | 21 | </body> |
|
22 | 22 | </html> |
You need to be logged in to leave comments.
Login now