Description:
add adding list of users git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@7 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

r4:7ca7b874f4d4 - - 3 files changed: 30 inserted, 0 deleted

@@ -0,0 +1,12
1 + <h1>Adding list of users</h1>
2 +
3 + <div class="usermenu">
4 + <%= link_to 'User admin', :action => 'list' %>
5 + <%= link_to 'Main', :controller => 'main', :action => 'list' %>
6 + </div>
7 +
8 + <% form_tag :action => 'create_from_list' do %>
9 + <%= submit_tag 'create users' %><br/>
10 + List of user information: user_id,name,alias,passwd<br/>
11 + <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %>
12 + <% end %>
@@ -1,73 +1,90
1 class UserAdminController < ApplicationController
1 class UserAdminController < ApplicationController
2
2
3 before_filter :authenticate, :authorization
3 before_filter :authenticate, :authorization
4
4
5 def index
5 def index
6 list
6 list
7 render :action => 'list'
7 render :action => 'list'
8 end
8 end
9
9
10 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
10 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
11 verify :method => :post, :only => [ :destroy, :create, :update ],
11 verify :method => :post, :only => [ :destroy, :create, :update ],
12 :redirect_to => { :action => :list }
12 :redirect_to => { :action => :list }
13
13
14 def list
14 def list
15 @users = User.find(:all)
15 @users = User.find(:all)
16 end
16 end
17
17
18 def show
18 def show
19 @user = User.find(params[:id])
19 @user = User.find(params[:id])
20 end
20 end
21
21
22 def new
22 def new
23 @user = User.new
23 @user = User.new
24 end
24 end
25
25
26 def create
26 def create
27 @user = User.new(params[:user])
27 @user = User.new(params[:user])
28 if @user.save
28 if @user.save
29 flash[:notice] = 'User was successfully created.'
29 flash[:notice] = 'User was successfully created.'
30 redirect_to :action => 'list'
30 redirect_to :action => 'list'
31 else
31 else
32 render :action => 'new'
32 render :action => 'new'
33 end
33 end
34 end
34 end
35
35
36 + def create_from_list
37 + lines = params[:user_list]
38 + lines.split("\n").each do |line|
39 + items = line.split
40 + if items.length==5
41 + user = User.new
42 + user.login = items[0]
43 + user.full_name = "#{items[1]} #{items[2]}"
44 + user.alias = items[3]
45 + user.password = items[4]
46 + user.password_confirmation = items[4]
47 + user.save
48 + end
49 + end
50 + redirect_to :action => 'list'
51 + end
52 +
36 def edit
53 def edit
37 @user = User.find(params[:id])
54 @user = User.find(params[:id])
38 end
55 end
39
56
40 def update
57 def update
41 @user = User.find(params[:id])
58 @user = User.find(params[:id])
42 if @user.update_attributes(params[:user])
59 if @user.update_attributes(params[:user])
43 flash[:notice] = 'User was successfully updated.'
60 flash[:notice] = 'User was successfully updated.'
44 redirect_to :action => 'show', :id => @user
61 redirect_to :action => 'show', :id => @user
45 else
62 else
46 render :action => 'edit'
63 render :action => 'edit'
47 end
64 end
48 end
65 end
49
66
50 def destroy
67 def destroy
51 User.find(params[:id]).destroy
68 User.find(params[:id]).destroy
52 redirect_to :action => 'list'
69 redirect_to :action => 'list'
53 end
70 end
54
71
55 def user_stat
72 def user_stat
56 @problems = Problem.find_available_problems
73 @problems = Problem.find_available_problems
57 @users = User.find(:all)
74 @users = User.find(:all)
58 @scorearray = Array.new
75 @scorearray = Array.new
59 @users.each do |u|
76 @users.each do |u|
60 ustat = Array.new
77 ustat = Array.new
61 ustat[0] = u.login
78 ustat[0] = u.login
62 @problems.each do |p|
79 @problems.each do |p|
63 c, sub = Submission.find_by_user_and_problem(u.id,p.id)
80 c, sub = Submission.find_by_user_and_problem(u.id,p.id)
64 if c!=0
81 if c!=0
65 ustat << sub.points
82 ustat << sub.points
66 else
83 else
67 ustat << 0
84 ustat << 0
68 end
85 end
69 end
86 end
70 @scorearray << ustat
87 @scorearray << ustat
71 end
88 end
72 end
89 end
73 end
90 end
@@ -1,53 +1,54
1 <h1>Listing users</h1>
1 <h1>Listing users</h1>
2
2
3 <div class="usermenu">
3 <div class="usermenu">
4 <%= link_to 'Stat', :action => 'user_stat' %>
4 <%= link_to 'Stat', :action => 'user_stat' %>
5 <%= link_to 'Main', :controller => 'main', :action => 'list' %>
5 <%= link_to 'Main', :controller => 'main', :action => 'list' %>
6 </div>
6 </div>
7
7
8 <div style="border: solid 1px; margin: 2px">
8 <div style="border: solid 1px; margin: 2px">
9 <b>Quick add</b>
9 <b>Quick add</b>
10 <% form_tag :action => 'create' do %>
10 <% form_tag :action => 'create' do %>
11 <table border="0">
11 <table border="0">
12 <tr>
12 <tr>
13 <td><label for="user_name">Login</label></td>
13 <td><label for="user_name">Login</label></td>
14 <td><label for="user_name">Full name</label></td>
14 <td><label for="user_name">Full name</label></td>
15 <td><label for="user_alias">Alias</label></td>
15 <td><label for="user_alias">Alias</label></td>
16 <td><label for="password">Password</label></td>
16 <td><label for="password">Password</label></td>
17 <td><label for="password_confirmation">confirm</label></td>
17 <td><label for="password_confirmation">confirm</label></td>
18 </tr>
18 </tr>
19 <tr>
19 <tr>
20 <td><%= text_field 'user', 'login', :size => 10 %></td>
20 <td><%= text_field 'user', 'login', :size => 10 %></td>
21 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
21 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
22 <td><%= text_field 'user', 'alias', :size => 10 %></td>
22 <td><%= text_field 'user', 'alias', :size => 10 %></td>
23 <td><%= password_field 'user', 'password', :size => 10 %></td>
23 <td><%= password_field 'user', 'password', :size => 10 %></td>
24 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
24 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
25 <td><%= submit_tag "Create" %></td>
25 <td><%= submit_tag "Create" %></td>
26 </tr></table>
26 </tr></table>
27 <% end %>
27 <% end %>
28
28
29 </div>
29 </div>
30
30
31 <table>
31 <table>
32 <tr>
32 <tr>
33 <% for column in User.content_columns %>
33 <% for column in User.content_columns %>
34 <th><%= column.human_name %></th>
34 <th><%= column.human_name %></th>
35 <% end %>
35 <% end %>
36 </tr>
36 </tr>
37
37
38 <% for user in @users %>
38 <% for user in @users %>
39 <tr>
39 <tr>
40 <% for column in User.content_columns %>
40 <% for column in User.content_columns %>
41 <td><%=h user.send(column.name) %></td>
41 <td><%=h user.send(column.name) %></td>
42 <% end %>
42 <% end %>
43 <td><%= link_to 'Show', :action => 'show', :id => user %></td>
43 <td><%= link_to 'Show', :action => 'show', :id => user %></td>
44 <td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
44 <td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
45 <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td>
45 <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td>
46 </tr>
46 </tr>
47 <% end %>
47 <% end %>
48 </table>
48 </table>
49
49
50
50
51 <br />
51 <br />
52
52
53 <%= link_to 'New user', :action => 'new' %>
53 <%= link_to 'New user', :action => 'new' %>
54 + <%= link_to 'New list of users', :action => 'new_list' %>
You need to be logged in to leave comments. Login now