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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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 | 1 | class UserAdminController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :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 | + 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 | 53 | def edit |
|
37 | 54 | @user = User.find(params[:id]) |
|
38 | 55 | end |
|
39 | 56 | |
|
40 | 57 | def update |
|
41 | 58 | @user = User.find(params[:id]) |
|
42 | 59 | if @user.update_attributes(params[:user]) |
|
43 | 60 | flash[:notice] = 'User was successfully updated.' |
|
44 | 61 | redirect_to :action => 'show', :id => @user |
|
45 | 62 | else |
|
46 | 63 | render :action => 'edit' |
|
47 | 64 | end |
|
48 | 65 | end |
|
49 | 66 | |
|
50 | 67 | def destroy |
|
51 | 68 | User.find(params[:id]).destroy |
|
52 | 69 | redirect_to :action => 'list' |
|
53 | 70 | end |
|
54 | 71 | |
|
55 | 72 | def user_stat |
|
56 | 73 | @problems = Problem.find_available_problems |
|
57 | 74 | @users = User.find(:all) |
|
58 | 75 | @scorearray = Array.new |
|
59 | 76 | @users.each do |u| |
|
60 | 77 | ustat = Array.new |
|
61 | 78 | ustat[0] = u.login |
|
62 | 79 | @problems.each do |p| |
|
63 | 80 | c, sub = Submission.find_by_user_and_problem(u.id,p.id) |
|
64 | 81 | if c!=0 |
|
65 | 82 | ustat << sub.points |
|
66 | 83 | else |
|
67 | 84 | ustat << 0 |
|
68 | 85 | end |
|
69 | 86 | end |
|
70 | 87 | @scorearray << ustat |
|
71 | 88 | end |
|
72 | 89 | end |
|
73 | 90 | end |
@@ -6,48 +6,49 | |||
|
6 | 6 | </div> |
|
7 | 7 | |
|
8 | 8 | <div style="border: solid 1px; margin: 2px"> |
|
9 | 9 | <b>Quick add</b> |
|
10 | 10 | <% form_tag :action => 'create' do %> |
|
11 | 11 | <table border="0"> |
|
12 | 12 | <tr> |
|
13 | 13 | <td><label for="user_name">Login</label></td> |
|
14 | 14 | <td><label for="user_name">Full name</label></td> |
|
15 | 15 | <td><label for="user_alias">Alias</label></td> |
|
16 | 16 | <td><label for="password">Password</label></td> |
|
17 | 17 | <td><label for="password_confirmation">confirm</label></td> |
|
18 | 18 | </tr> |
|
19 | 19 | <tr> |
|
20 | 20 | <td><%= text_field 'user', 'login', :size => 10 %></td> |
|
21 | 21 | <td><%= text_field 'user', 'full_name', :size => 30 %></td> |
|
22 | 22 | <td><%= text_field 'user', 'alias', :size => 10 %></td> |
|
23 | 23 | <td><%= password_field 'user', 'password', :size => 10 %></td> |
|
24 | 24 | <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td> |
|
25 | 25 | <td><%= submit_tag "Create" %></td> |
|
26 | 26 | </tr></table> |
|
27 | 27 | <% end %> |
|
28 | 28 | |
|
29 | 29 | </div> |
|
30 | 30 | |
|
31 | 31 | <table> |
|
32 | 32 | <tr> |
|
33 | 33 | <% for column in User.content_columns %> |
|
34 | 34 | <th><%= column.human_name %></th> |
|
35 | 35 | <% end %> |
|
36 | 36 | </tr> |
|
37 | 37 | |
|
38 | 38 | <% for user in @users %> |
|
39 | 39 | <tr> |
|
40 | 40 | <% for column in User.content_columns %> |
|
41 | 41 | <td><%=h user.send(column.name) %></td> |
|
42 | 42 | <% end %> |
|
43 | 43 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
44 | 44 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
45 | 45 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
46 | 46 | </tr> |
|
47 | 47 | <% end %> |
|
48 | 48 | </table> |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | <br /> |
|
52 | 52 | |
|
53 | 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