Description:
add current score by group
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r762:c6677423b846 - - 10 files changed: 165 inserted, 84 deleted
@@ -0,0 +1,45 | |||
|
1 | + .container-fluid | |
|
2 | + .row | |
|
3 | + .col-md-6 | |
|
4 | + %h1 Adding list of users | |
|
5 | + .row | |
|
6 | + .col-md-6 | |
|
7 | + .panel.panel-default | |
|
8 | + .panel-heading | |
|
9 | + .panel-title Info | |
|
10 | + .panel-body | |
|
11 | + %ul | |
|
12 | + %li | |
|
13 | + List of user information in this format: | |
|
14 | + %tt user_id,name(,passwd(,alias(,remark))) | |
|
15 | + %li | |
|
16 | + Note that | |
|
17 | + %tt passwd, alias | |
|
18 | + and | |
|
19 | + %tt remark | |
|
20 | + is optional. | |
|
21 | + %li | |
|
22 | + When | |
|
23 | + %tt passwd | |
|
24 | + or | |
|
25 | + %tt alias | |
|
26 | + is empty, the original value will be used instead. | |
|
27 | + %li | |
|
28 | + If the users with the same user_id already exists, existing information will be overwritten. | |
|
29 | + | |
|
30 | + .row | |
|
31 | + .col-md-6 | |
|
32 | + = form_tag :action => 'create_from_list' do | |
|
33 | + .form-group | |
|
34 | + = submit_tag 'Create following users',class: 'btn btn-success' | |
|
35 | + .form-group | |
|
36 | + .div.checkbox | |
|
37 | + %label | |
|
38 | + = check_box_tag :add_to_group | |
|
39 | + Also add these users to the following group | |
|
40 | + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2' | |
|
41 | + .form-group | |
|
42 | + = text_area_tag 'user_list', nil, :rows => 50, :cols => 80 | |
|
43 | + .col-md-6 | |
|
44 | + | |
|
45 | + |
@@ -14,13 +14,18 | |||
|
14 | 14 | |
|
15 | 15 | def max_score |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def current_score |
|
19 | 19 | @problems = Problem.available_problems |
|
20 | - @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) | |
|
20 | + if params[:group_id] | |
|
21 | + @group = Group.find(params[:group_id]) | |
|
22 | + @users = @group.users.where(enabled: true) | |
|
23 | + else | |
|
24 | + @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) | |
|
25 | + end | |
|
21 | 26 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
22 | 27 | |
|
23 | 28 | #rencer accordingly |
|
24 | 29 | if params[:button] == 'download' then |
|
25 | 30 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
26 | 31 | send_data csv, filename: 'max_score.csv' |
@@ -24,26 +24,25 | |||
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | # this has problem-level access control |
|
27 | 27 | def download |
|
28 | 28 | problem = Problem.find(params[:id]) |
|
29 | 29 | unless @current_user.can_view_problem? problem |
|
30 | + flash[:notice] = 'You are not authorized to access this file' | |
|
30 | 31 | redirect_to :action => 'index' and return |
|
31 | 32 | end |
|
32 | 33 | |
|
33 | 34 | base_name = params[:file] |
|
34 | 35 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
35 | 36 | filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}" |
|
36 | - puts "SENDING: #{filename}" | |
|
37 | 37 | |
|
38 | 38 | if !FileTest.exists?(filename) |
|
39 | + flash[:notice] = 'File does not exists' | |
|
39 | 40 | redirect_to :action => 'index' and return |
|
40 | 41 | end |
|
41 | 42 | |
|
42 | - puts "SENDING: #{filename}" | |
|
43 | - | |
|
44 | 43 | send_file_to_user(filename, base_filename) |
|
45 | 44 | end |
|
46 | 45 | |
|
47 | 46 | protected |
|
48 | 47 | |
|
49 | 48 | def send_file_to_user(filename, base_filename) |
@@ -57,12 +57,14 | |||
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def create_from_list |
|
60 | 60 | lines = params[:user_list] |
|
61 | 61 | |
|
62 | 62 | note = [] |
|
63 | + error_note = [] | |
|
64 | + ok_user = [] | |
|
63 | 65 | |
|
64 | 66 | lines.split("\n").each do |line| |
|
65 | 67 | items = line.chomp.split(',') |
|
66 | 68 | if items.length>=2 |
|
67 | 69 | login = items[0] |
|
68 | 70 | full_name = items[1] |
@@ -98,24 +100,42 | |||
|
98 | 100 | :password => password, |
|
99 | 101 | :password_confirmation => password, |
|
100 | 102 | :alias => user_alias, |
|
101 | 103 | :remark => remark}) |
|
102 | 104 | end |
|
103 | 105 | user.activated = true |
|
104 | - user.save | |
|
105 | 106 | |
|
106 | - if added_random_password | |
|
107 | - note << "'#{login}' (+)" | |
|
107 | + if user.save | |
|
108 | + if added_random_password | |
|
109 | + note << "'#{login}' (+)" | |
|
110 | + else | |
|
111 | + note << login | |
|
112 | + end | |
|
113 | + ok_user << user | |
|
108 | 114 | else |
|
109 | - note << login | |
|
115 | + error_note << "#{login}" | |
|
110 | 116 | end |
|
117 | + | |
|
111 | 118 | end |
|
112 | 119 | end |
|
120 | + | |
|
121 | + #add to group | |
|
122 | + if params[:add_to_group] | |
|
123 | + group = Group.where(id: params[:group_id]).first | |
|
124 | + if group | |
|
125 | + group.users << ok_user | |
|
126 | + end | |
|
127 | + end | |
|
128 | + | |
|
129 | + # show flash | |
|
113 | 130 | flash[:success] = 'User(s) ' + note.join(', ') + |
|
114 | 131 | ' were successfully created. ' + |
|
115 | 132 | '( (+) - created with random passwords.)' |
|
133 | + if error_note.size > 0 | |
|
134 | + flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') | |
|
135 | + end | |
|
116 | 136 | redirect_to :action => 'index' |
|
117 | 137 | end |
|
118 | 138 | |
|
119 | 139 | def edit |
|
120 | 140 | @user = User.find(params[:id]) |
|
121 | 141 | end |
@@ -1,12 +1,13 | |||
|
1 | 1 | module MainHelper |
|
2 | 2 | |
|
3 | 3 | def link_to_description_if_any(name, problem, options={}) |
|
4 | 4 | if !problem.url.blank? |
|
5 | 5 | return link_to name, problem.url, options |
|
6 | 6 | elsif !problem.description_filename.blank? |
|
7 | + #build a link to a problem (via task controller) | |
|
7 | 8 | basename, ext = problem.description_filename.split('.') |
|
8 | 9 | options[:controller] = 'tasks' |
|
9 | 10 | options[:action] = 'download' |
|
10 | 11 | options[:id] = problem.id |
|
11 | 12 | options[:file] = basename |
|
12 | 13 | options[:ext] = ext |
@@ -243,19 +243,24 | |||
|
243 | 243 | end |
|
244 | 244 | return true |
|
245 | 245 | end |
|
246 | 246 | |
|
247 | 247 | #get a list of available problem |
|
248 | 248 | def available_problems |
|
249 | + # first, we check if this is normal mode | |
|
249 | 250 | if not GraderConfiguration.multicontests? |
|
251 | + | |
|
252 | + #if this is a normal mode | |
|
253 | + #we show problem based on problem_group, if the config said so | |
|
250 | 254 | if GraderConfiguration.use_problem_group? |
|
251 | 255 | return available_problems_in_group |
|
252 | 256 | else |
|
253 | 257 | return Problem.available_problems |
|
254 | 258 | end |
|
255 | 259 | else |
|
260 | + #this is multi contest mode | |
|
256 | 261 | contest_problems = [] |
|
257 | 262 | pin = {} |
|
258 | 263 | contests.enabled.each do |contest| |
|
259 | 264 | contest.problems.available.each do |problem| |
|
260 | 265 | if not pin.has_key? problem.id |
|
261 | 266 | contest_problems << problem |
@@ -1,73 +1,80 | |||
|
1 | - %p | |
|
2 | - %b Name: | |
|
3 | - = @group.name | |
|
4 | - %p | |
|
5 | - %b Description: | |
|
6 | - = @group.description | |
|
7 | - | |
|
8 | - %br | |
|
9 | - = link_to 'Edit', edit_group_path(@group) | |
|
10 | - \| | |
|
11 | - = link_to 'Back', groups_path | |
|
12 | - | |
|
13 | - .row | |
|
14 | - .col-md-12 | |
|
15 | - %h1 Group details | |
|
16 | - .row | |
|
17 | - .col-md-6 | |
|
18 | - .panel.panel-default | |
|
19 |
- .panel- |
|
|
20 | - .panel-title Users in this group | |
|
21 | - .panel-body | |
|
22 | - =form_tag add_user_group_path(@group), class: 'form-inline' do | |
|
23 | - .form-group | |
|
24 | - =label_tag :user_id, "User" | |
|
25 | - =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2' | |
|
26 | - =submit_tag "Add",class: 'btn btn-primary' | |
|
1 | + .container-fluid | |
|
2 | + .row | |
|
3 | + .col-md-6 | |
|
4 | + %h1 Group #{@group.name} | |
|
5 | + .row | |
|
6 | + .col-md-6 | |
|
7 | + %b Description: | |
|
8 | + = @group.description | |
|
9 | + %br | |
|
10 | + = link_to 'Edit', edit_group_path(@group), class: 'btn btn-primary' | |
|
11 | + .row | |
|
12 | + .col-md-12 | |
|
13 | + %h1 Group details | |
|
14 | + .row | |
|
15 | + .col-md-6 | |
|
16 | + .panel.panel-default | |
|
17 | + .panel-heading | |
|
18 | + .panel-title Users in this group | |
|
19 | + .panel-body | |
|
20 | + %ul | |
|
21 | + %li | |
|
22 | + If you want to add several users to a group, it may be easier to just re-import those users in | |
|
23 | + = link_to 'New list of users', new_list_user_admin_index_path | |
|
24 | + page | |
|
25 | + =form_tag add_user_group_path(@group), class: 'form-inline' do | |
|
26 | + .form-group | |
|
27 | + =label_tag :user_id, "User" | |
|
28 | + =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2' | |
|
29 | + =submit_tag "Add",class: 'btn btn-primary' | |
|
27 | 30 | |
|
28 | 31 | |
|
29 | - %table.table.table-hover | |
|
30 | - %thead | |
|
31 | - %tr | |
|
32 | - %th Login | |
|
33 | - %th Full name | |
|
34 | - %th Remark | |
|
35 | - %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm' | |
|
36 | - | |
|
37 | - %tbody | |
|
38 | - - @group.users.each do |user| | |
|
32 | + %table.table.table-hover | |
|
33 | + %thead | |
|
39 | 34 | %tr |
|
40 |
- %t |
|
|
41 |
- %t |
|
|
42 |
- %t |
|
|
43 |
- %t |
|
|
44 | - .col-md-6 | |
|
45 | - .panel.panel-default | |
|
46 | - .panel-heading | |
|
47 | - .panel-title Problems | |
|
48 | - .panel-body | |
|
35 | + %th Login | |
|
36 | + %th Full name | |
|
37 | + %th Remark | |
|
38 | + %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm' | |
|
49 | 39 | |
|
50 | - =form_tag add_problem_group_path(@group), class: 'form-inline' do | |
|
51 | - .form-group | |
|
52 | - =label_tag :problem_id, "Problem" | |
|
53 | - =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2' | |
|
54 | - =submit_tag "Add",class: 'btn btn-primary' | |
|
40 | + %tbody | |
|
41 | + - @group.users.each do |user| | |
|
42 | + %tr | |
|
43 | + %td= user.login | |
|
44 | + %td= user.full_name | |
|
45 | + %td= user.remark | |
|
46 | + %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm' | |
|
47 | + .col-md-6 | |
|
48 | + .panel.panel-default | |
|
49 | + .panel-heading | |
|
50 | + .panel-title Problems | |
|
51 | + .panel-body | |
|
52 | + %ul | |
|
53 | + %li | |
|
54 | + If you want to add several problem to a group, it may be easier to bulk manage them in the | |
|
55 | + = link_to 'Bulk Manage', manage_problems_path | |
|
56 | + page | |
|
57 | + =form_tag add_problem_group_path(@group), class: 'form-inline' do | |
|
58 | + .form-group | |
|
59 | + =label_tag :problem_id, "Problem" | |
|
60 | + =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2' | |
|
61 | + =submit_tag "Add",class: 'btn btn-primary' | |
|
55 | 62 | |
|
56 | 63 | |
|
57 | - %table.table.table-hover | |
|
58 | - %thead | |
|
59 | - %tr | |
|
60 | - %th name | |
|
61 | - %th Full name | |
|
62 | - %th Full score | |
|
63 | - %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm' | |
|
64 | + %table.table.table-hover | |
|
65 | + %thead | |
|
66 | + %tr | |
|
67 | + %th name | |
|
68 | + %th Full name | |
|
69 | + %th Full score | |
|
70 | + %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm' | |
|
64 | 71 | |
|
65 | - %tbody | |
|
66 | - - @group.problems.each do |problem| | |
|
67 | - %tr | |
|
68 | - %td= problem.name | |
|
69 | - %td= problem.full_name | |
|
70 | - %td= problem.full_score | |
|
71 | - %td= link_to 'Remove', remove_problem_group_path(@group,problem), :method => :delete, :data => { :confirm => "Remove #{problem.full_name}?" }, class: 'btn btn-danger btn-sm' | |
|
72 | + %tbody | |
|
73 | + - @group.problems.each do |problem| | |
|
74 | + %tr | |
|
75 | + %td= problem.name | |
|
76 | + %td= problem.full_name | |
|
77 | + %td= problem.full_score | |
|
78 | + %td= link_to 'Remove', remove_problem_group_path(@group,problem), :method => :delete, :data => { :confirm => "Remove #{problem.full_name}?" }, class: 'btn btn-danger btn-sm' | |
|
72 | 79 | |
|
73 | 80 |
@@ -1,3 +1,11 | |||
|
1 | - %h1 Current Score | |
|
1 | + .container-fluid | |
|
2 | + %h1 Current Score | |
|
3 | + = form_tag current_score_report_path, method: 'get' do | |
|
4 | + Show only users from this group | |
|
5 | + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2' | |
|
6 | + = submit_tag 'Apply',class: 'btn btn-default' | |
|
2 | 7 | |
|
3 | - = render "score_table" | |
|
8 | + %br | |
|
9 | + | |
|
10 | + | |
|
11 | + = render "score_table" |
@@ -132,13 +132,13 | |||
|
132 | 132 | #---- BEWARE ---- singular resource maps to plural controller by default, we can override by provide controller name directly |
|
133 | 133 | #report |
|
134 | 134 | resource :report, only: [], controller: 'report' do |
|
135 | 135 | get 'login' |
|
136 | 136 | get 'multiple_login' |
|
137 | 137 | get 'problem_hof/:id', action: 'problem_hof' |
|
138 | - get 'current_score' | |
|
138 | + get 'current_score(/:group_id)', action: 'current_score', as: 'current_score' | |
|
139 | 139 | get 'max_score' |
|
140 | 140 | post 'show_max_score' |
|
141 | 141 | end |
|
142 | 142 | #get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
143 | 143 | #get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
144 | 144 | #get "report/login" |
deleted file |
You need to be logged in to leave comments.
Login now