Description:
commited
Commit status:
[Not Reviewed]
References:
merge java
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r689:124074894d4b - - 16 files changed: 126 inserted, 41 deleted

new file 100644
new file 100644
new file 100644
new file 100644
@@ -0,0 +1,7
1 + class GroupProblem < ActiveRecord::Base
2 + self.table_name = 'groups_problems'
3 +
4 + belongs_to :problem
5 + belongs_to :group
6 + validates_uniqueness_of :problem_id, scope: :group_id, message: ->(object, data) { "'#{Problem.find(data[:value]).full_name}' is already in the group" }
7 + end
@@ -0,0 +1,7
1 + class GroupUser < ActiveRecord::Base
2 + self.table_name = 'groups_users'
3 +
4 + belongs_to :user
5 + belongs_to :group
6 + validates_uniqueness_of :user_id, scope: :group_id, message: ->(object, data) { "'#{User.find(data[:value]).full_name}' is already in the group" }
7 + end
@@ -0,0 +1,23
1 + # Be sure to restart your server when you modify this file.
2 +
3 + # Version of your assets, change this if you want to expire all your assets.
4 + Rails.application.config.assets.version = '1.0'
5 +
6 + # Add additional assets to the asset load path.
7 + # Rails.application.config.assets.paths << Emoji.images_path
8 + # Add Yarn node_modules folder to the asset load path.
9 + Rails.application.config.assets.paths << Rails.root.join('node_modules')
10 + Rails.application.config.assets.paths << Rails.root.join('vendor/assets/fonts')
11 +
12 + # Precompile additional assets.
13 + # application.js, application.css, and all non-JS/CSS in the app/assets
14 + # folder are already added.
15 + # Rails.application.config.assets.precompile += %w( admin.js admin.css )
16 +
17 + Rails.application.config.assets.precompile += ['announcement_refresh.js','effects.js','site_update.js']
18 + Rails.application.config.assets.precompile += ['local_jquery.js','tablesorter-theme.cafe.css']
19 + %w( announcements submissions configurations contests contest_management graders heartbeat
20 + login main messages problems report site sites sources tasks groups
21 + test user_admin users ).each do |controller|
22 + Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"]
23 + end
@@ -52,25 +52,33
52 def remove_user
52 def remove_user
53 user = User.find(params[:user_id])
53 user = User.find(params[:user_id])
54 @group.users.delete(user)
54 @group.users.delete(user)
55 - redirect_to group_path(@group), notice: "User #{user.login} was removed from the group #{@group.name}"
55 + redirect_to group_path(@group), flash: {success: "User #{user.login} was removed from the group #{@group.name}"}
56 end
56 end
57
57
58 def add_user
58 def add_user
59 user = User.find(params[:user_id])
59 user = User.find(params[:user_id])
60 - @group.users << user
60 + begin
61 - redirect_to group_path(@group), notice: "User #{user.login} was add to the group #{@group.name}"
61 + @group.users << user
62 + redirect_to group_path(@group), flash: { success: "User #{user.login} was add to the group #{@group.name}"}
63 + rescue => e
64 + redirect_to group_path(@group), alert: e.message
65 + end
62 end
66 end
63
67
64 def remove_problem
68 def remove_problem
65 problem = Problem.find(params[:problem_id])
69 problem = Problem.find(params[:problem_id])
66 @group.problems.delete(problem)
70 @group.problems.delete(problem)
67 - redirect_to group_path(@group), notice: "Problem #{problem.name} was removed from the group #{@group.name}"
71 + redirect_to group_path(@group), flash: {success: "Problem #{problem.name} was removed from the group #{@group.name}" }
68 end
72 end
69
73
70 def add_problem
74 def add_problem
71 problem = Problem.find(params[:problem_id])
75 problem = Problem.find(params[:problem_id])
72 - @group.problems << problem
76 + begin
73 - redirect_to group_path(@group), notice: "Problem #{problem.name} was add to the group #{@group.name}"
77 + @group.problems << problem
78 + redirect_to group_path(@group), flash: {success: "Problem #{problem.name} was add to the group #{@group.name}" }
79 + rescue => e
80 + redirect_to group_path(@group), alert: e.message
81 + end
74 end
82 end
75
83
76 private
84 private
@@ -197,10 +197,20
197 set_available(false)
197 set_available(false)
198 elsif params.has_key? 'add_group'
198 elsif params.has_key? 'add_group'
199 group = Group.find(params[:group_id])
199 group = Group.find(params[:group_id])
200 + ok = []
201 + failed = []
200 get_problems_from_params.each do |p|
202 get_problems_from_params.each do |p|
201 - group.problems << p
203 + begin
204 + group.problems << p
205 + ok << p.full_name
206 + rescue => e
207 + failed << p.full_name
208 + end
202 end
209 end
210 + flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
211 + flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
203 end
212 end
213 +
204 redirect_to :action => 'manage'
214 redirect_to :action => 'manage'
205 end
215 end
206
216
@@ -442,7 +442,18
442 end
442 end
443 if @action[:add_group] and @action[:group_name]
443 if @action[:add_group] and @action[:group_name]
444 @group = Group.find(@action[:group_name])
444 @group = Group.find(@action[:group_name])
445 - @users.each { |user| @group.users << user }
445 + ok = []
446 + failed = []
447 + @users.each do |user|
448 + begin
449 + @group.users << user
450 + ok << user.login
451 + rescue => e
452 + failed << user.login
453 + end
454 + end
455 + flash[:success] = "The following users are added to the 'group #{@group.name}': " + ok.join(', ') if ok.count > 0
456 + flash[:alert] = "The following users are already in the 'group #{@group.name}': " + failed.join(', ') if failed.count > 0
446 end
457 end
447 end
458 end
448 end
459 end
@@ -200,7 +200,7
200 BOOTSTRAP_FLASH_MSG = {
200 BOOTSTRAP_FLASH_MSG = {
201 success: 'alert-success',
201 success: 'alert-success',
202 error: 'alert-danger',
202 error: 'alert-danger',
203 - alert: 'alert-block',
203 + alert: 'alert-danger',
204 notice: 'alert-info'
204 notice: 'alert-info'
205 }
205 }
206
206
@@ -1,5 +1,13
1 class Group < ActiveRecord::Base
1 class Group < ActiveRecord::Base
2 - has_and_belongs_to_many :problems
2 + has_many :groups_problems, class_name: GroupProblem
3 - has_and_belongs_to_many :users
3 + has_many :problems, :through => :groups_problems
4 +
5 + has_many :groups_users, class_name: GroupUser
6 + has_many :users, :through => :groups_users
7 +
8 + #has_and_belongs_to_many :problems
9 + #has_and_belongs_to_many :users
10 +
11 +
4 end
12 end
5
13
@@ -2,7 +2,11
2
2
3 belongs_to :description
3 belongs_to :description
4 has_and_belongs_to_many :contests, :uniq => true
4 has_and_belongs_to_many :contests, :uniq => true
5 - has_and_belongs_to_many :groups
5 +
6 + #has_and_belongs_to_many :groups
7 + has_many :groups_problems, class_name: GroupProblem
8 + has_many :groups, :through => :groups_problems
9 +
6 has_many :test_pairs, :dependent => :delete_all
10 has_many :test_pairs, :dependent => :delete_all
7 has_many :testcases, :dependent => :destroy
11 has_many :testcases, :dependent => :destroy
8
12
@@ -7,7 +7,10
7 class User < ActiveRecord::Base
7 class User < ActiveRecord::Base
8
8
9 has_and_belongs_to_many :roles
9 has_and_belongs_to_many :roles
10 - has_and_belongs_to_many :groups
10 +
11 + #has_and_belongs_to_many :groups
12 + has_many :groups_users, class_name: GroupUser
13 + has_many :groups, :through => :groups_users
11
14
12 has_many :test_requests, -> {order(submitted_at: DESC)}
15 has_many :test_requests, -> {order(submitted_at: DESC)}
13
16
@@ -1,10 +1,10
1 - content_for :head do
1 - content_for :head do
2 = stylesheet_link_tag 'problems'
2 = stylesheet_link_tag 'problems'
3 - %h1 Listing problems
3 + %h1 Problems
4 %p
4 %p
5 - = link_to 'New problem', new_problem_path, class: 'btn btn-default btn-sm'
5 + = link_to 'Import problems', {:action => 'import'}, class: 'btn btn-success btn-sm'
6 - = link_to 'Manage problems', { action: 'manage'}, class: 'btn btn-default btn-sm'
6 + = link_to 'New problem', new_problem_path, class: 'btn btn-success btn-sm'
7 - = link_to 'Import problems', {:action => 'import'}, class: 'btn btn-default btn-sm'
7 + = link_to 'Bulk Manage', { action: 'manage'}, class: 'btn btn-info btn-sm'
8 = link_to 'Turn off all problems', {:action => 'turn_all_off'}, class: 'btn btn-default btn-sm'
8 = link_to 'Turn off all problems', {:action => 'turn_all_off'}, class: 'btn btn-default btn-sm'
9 = link_to 'Turn on all problems', {:action => 'turn_all_on'}, class: 'btn btn-default btn-sm'
9 = link_to 'Turn on all problems', {:action => 'turn_all_on'}, class: 'btn btn-default btn-sm'
10 .submitbox
10 .submitbox
@@ -36,33 +36,37
36
36
37 %h1 Manage problems
37 %h1 Manage problems
38
38
39 - %p= link_to '[Back to problem list]', :action => 'list'
39 + %p= link_to '[Back to problem list]', problems_path
40
40
41 = form_tag :action=>'do_manage' do
41 = form_tag :action=>'do_manage' do
42 - .submitbox.panel
42 + .panel.panel-primary
43 - What do you want to do to the selected problem?
43 + .panel-heading
44 - %br/
44 + Action
45 - (You can shift-click to select a range of problems)
45 + .panel-body
46 - %ul
46 + .submit-box
47 - %li
47 + What do you want to do to the selected problem?
48 - Change date added to
48 + %br/
49 - = select_date Date.current, :prefix => 'date_added'
49 + (You can shift-click to select a range of problems)
50 - &nbsp;&nbsp;&nbsp;
50 + %ul
51 - = submit_tag 'Change', :name => 'change_date_added'
51 + %li
52 - %li
52 + Change date added to
53 - Set available to
53 + = select_date Date.current, :prefix => 'date_added'
54 - = submit_tag 'True', :name => 'enable_problem'
54 + &nbsp;&nbsp;&nbsp;
55 - = submit_tag 'False', :name => 'disable_problem'
55 + = submit_tag 'Change', :name => 'change_date_added', class: 'btn btn-default'
56 + %li
57 + Set available to
58 + = submit_tag 'True', :name => 'enable_problem', class: 'btn btn-default'
59 + = submit_tag 'False', :name => 'disable_problem', class: 'btn btn-default'
56
60
57 - - if GraderConfiguration.multicontests?
61 + - if GraderConfiguration.multicontests?
58 - %li
62 + %li
59 - Add to
63 + Add to
60 - = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
64 + = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
61 - = submit_tag 'Add', :name => 'add_to_contest'
65 + = submit_tag 'Add', :name => 'add_to_contest', class: 'btn btn-default'
62 - %li
66 + %li
63 - Add problems to group
67 + Add problems to group
64 - = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
68 + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
65 - = submit_tag 'Add', name: 'add_group'
69 + = submit_tag 'Add', name: 'add_group', class: 'btn btn-default'
66
70
67
71
68 %table.table.table-hover
72 %table.table.table-hover
You need to be logged in to leave comments. Login now