Description:
group enable
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r795:08d968fa05d5 - - 11 files changed: 54 inserted, 17 deleted
@@ -0,0 +1,8 | |||
|
1 | + = render partial: 'toggle_button', | |
|
2 | + locals: {button_id: "#group-enabled-#{@group.id}",button_on: @group.enabled } | |
|
3 | + :plain | |
|
4 | + r = $("#group-#{@group.id}"); | |
|
5 | + r.removeClass('success'); | |
|
6 | + r.removeClass('danger'); | |
|
7 | + r.addClass("#{@group.enabled? ? 'success' : 'danger'}"); | |
|
8 | + |
@@ -0,0 +1,5 | |||
|
1 | + class AddEnabledToGroup < ActiveRecord::Migration[5.2] | |
|
2 | + def change | |
|
3 | + add_column :groups, :enabled, :boolean, default: true | |
|
4 | + end | |
|
5 | + end |
@@ -2,6 +2,7 | |||
|
2 | 2 | before_action :set_group, only: [:show, :edit, :update, :destroy, |
|
3 | 3 | :add_user, :remove_user,:remove_all_user, |
|
4 | 4 | :add_problem, :remove_problem,:remove_all_problem, |
|
5 | + :toggle, | |
|
5 | 6 | ] |
|
6 | 7 | before_action :admin_authorization |
|
7 | 8 | |
@@ -49,6 +50,11 | |||
|
49 | 50 | redirect_to groups_url, notice: 'Group was successfully destroyed.' |
|
50 | 51 | end |
|
51 | 52 | |
|
53 | + def toggle | |
|
54 | + @group.enabled = @group.enabled? ? false : true | |
|
55 | + @group.save | |
|
56 | + end | |
|
57 | + | |
|
52 | 58 | def remove_user |
|
53 | 59 | user = User.find(params[:user_id]) |
|
54 | 60 | @group.users.delete(user) |
@@ -99,6 +105,6 | |||
|
99 | 105 | |
|
100 | 106 | # Only allow a trusted parameter "white list" through. |
|
101 | 107 | def group_params |
|
102 | - params.require(:group).permit(:name, :description) | |
|
108 | + params.require(:group).permit(:name, :description, :enabled) | |
|
103 | 109 | end |
|
104 | 110 | end |
@@ -188,7 +188,7 | |||
|
188 | 188 | @user = user |
|
189 | 189 | end |
|
190 | 190 | end |
|
191 | - | |
|
191 | + | |
|
192 | 192 | protected |
|
193 | 193 | |
|
194 | 194 | def prepare_announcements(recent=nil) |
@@ -113,8 +113,9 | |||
|
113 | 113 | |
|
114 | 114 | def toggle_button(on,toggle_url,id, option={}) |
|
115 | 115 | btn_size = option[:size] || 'btn-xs' |
|
116 | + btn_block = option[:block] || 'btn-block' | |
|
116 | 117 | link_to (on ? "Yes" : "No"), toggle_url, |
|
117 |
- {class: "btn |
|
|
118 | + {class: "btn #{btn_block} #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", | |
|
118 | 119 | id: id, |
|
119 | 120 | data: {remote: true, method: 'get'}} |
|
120 | 121 | end |
@@ -273,9 +273,10 | |||
|
273 | 273 | end |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | + # new feature, get list of available problem in all enabled group that the user belongs to | |
|
276 | 277 | def available_problems_in_group |
|
277 | 278 | problem = [] |
|
278 | - self.groups.each do |group| | |
|
279 | + self.groups.where(enabled: true).each do |group| | |
|
279 | 280 | group.problems.where(available: true).each { |p| problem << p } |
|
280 | 281 | end |
|
281 | 282 | problem.uniq! |
@@ -296,6 +297,8 | |||
|
296 | 297 | end |
|
297 | 298 | end |
|
298 | 299 | |
|
300 | + #check if the user has the right to view that problem | |
|
301 | + #this also consider group based problem policy | |
|
299 | 302 | def can_view_problem?(problem) |
|
300 | 303 | return true if admin? |
|
301 | 304 | return available_problems.include? problem |
@@ -10,7 +10,7 | |||
|
10 | 10 | %td |
|
11 | 11 | = submission.source_filename |
|
12 | 12 | = " (#{submission.language.pretty_name}) " |
|
13 | - = link_to('[load]',{:action => 'source', :id => submission.id}) | |
|
13 | + = link_to '[load]', download_submission_path(submission) | |
|
14 | 14 | %td |
|
15 | 15 | - if submission.graded_at |
|
16 | 16 | = "Graded at #{format_short_time(submission.graded_at)}." |
@@ -5,12 +5,23 | |||
|
5 | 5 | %ul |
|
6 | 6 | - @group.errors.full_messages.each do |msg| |
|
7 | 7 | %li= msg |
|
8 | - | |
|
9 | - .form-group.field | |
|
10 | - = f.label :name | |
|
11 | - = f.text_field :name, class: 'form-control' | |
|
12 | - .form-group.field | |
|
13 | - = f.label :description | |
|
14 | - = f.text_field :description, class: 'form-control' | |
|
15 |
- .form-group. |
|
|
16 | - = f.submit 'Save', class: 'btn btn-primary' | |
|
8 | + .row | |
|
9 | + .col-md-6 | |
|
10 | + .form-group.field | |
|
11 | + = f.label :name | |
|
12 | + = f.text_field :name, class: 'form-control' | |
|
13 | + .row | |
|
14 | + .col-md-6 | |
|
15 | + .form-group.field | |
|
16 | + = f.label :description | |
|
17 | + = f.text_field :description, class: 'form-control' | |
|
18 | + .row | |
|
19 | + .col-md-6 | |
|
20 | + .checkbox | |
|
21 | + = f.label :enabled do | |
|
22 | + = f.check_box :enabled | |
|
23 | + Enabled | |
|
24 | + .row | |
|
25 | + .col-md-6 | |
|
26 | + .form-group.actions | |
|
27 | + = f.submit 'Save', class: 'btn btn-primary' |
@@ -7,14 +7,16 | |||
|
7 | 7 | %tr |
|
8 | 8 | %th Name |
|
9 | 9 | %th Description |
|
10 | + %th Enabled? | |
|
10 | 11 | %th |
|
11 | 12 | %th |
|
12 | 13 | |
|
13 | 14 | %tbody |
|
14 | 15 | - @groups.each do |group| |
|
15 | - %tr | |
|
16 | + %tr{:class => "#{(group.enabled?) ? "success" : "danger"}", id: "group-#{group.id}"} | |
|
16 | 17 | %td= group.name |
|
17 | 18 | %td= group.description |
|
19 | + %td= toggle_button(group.enabled?, toggle_group_path(group), "group-enabled-#{group.id}", size: ' ', block: ' ') | |
|
18 | 20 | %td= link_to 'View', group, class: 'btn btn-default' |
|
19 | 21 | %td= link_to 'Destroy', group, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' |
|
20 | 22 |
@@ -54,6 +54,7 | |||
|
54 | 54 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
55 | 55 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
56 | 56 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
57 | + get 'toggle' | |
|
57 | 58 | end |
|
58 | 59 | collection do |
|
59 | 60 | |
@@ -92,7 +93,6 | |||
|
92 | 93 | get 'download' |
|
93 | 94 | get 'compiler_msg' |
|
94 | 95 | get 'rejudge' |
|
95 | - get 'source' | |
|
96 | 96 | end |
|
97 | 97 | collection do |
|
98 | 98 | get 'prob/:problem_id', to: 'submissions#index', as: 'problem' |
@@ -10,7 +10,7 | |||
|
10 | 10 | # |
|
11 | 11 | # It's strongly recommended that you check this file into your version control system. |
|
12 | 12 | |
|
13 |
- ActiveRecord::Schema.define(version: 20 |
|
|
13 | + ActiveRecord::Schema.define(version: 2020_08_13_083020) do | |
|
14 | 14 | |
|
15 | 15 | create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
16 | 16 | t.string "author" |
@@ -80,6 +80,7 | |||
|
80 | 80 | create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
81 | 81 | t.string "name" |
|
82 | 82 | t.string "description" |
|
83 | + t.boolean "enabled", default: true | |
|
83 | 84 | end |
|
84 | 85 | |
|
85 | 86 | create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
You need to be logged in to leave comments.
Login now