Description:
* DRY the toggle button via application_helper.rb#toggle_button and _toggle_button.js.haml
* bootrapize the user_admin
* now considering user.enabled
* tidy up route
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r562:ede66b5a6449 - - 15 files changed: 171 inserted, 52 deleted
@@ -0,0 +1,7 | |||
|
1 | + :plain | |
|
2 | + var t = $("#{button_id}"); | |
|
3 | + t.removeClass('btn-default'); | |
|
4 | + t.removeClass('btn-success'); | |
|
5 | + t.removeClass('btn-warning'); | |
|
6 | + t.addClass("btn-#{button_on ? 'success' : 'default'}"); | |
|
7 | + t.text("#{button_on ? 'Yes' : 'No'}"); |
@@ -0,0 +1,86 | |||
|
1 | + %h1 Listing users | |
|
2 | + .submitbox | |
|
3 | + %b Quick add | |
|
4 | + = form_tag :action => 'create' do | |
|
5 | + %table{:border => "0"} | |
|
6 | + %tr | |
|
7 | + %td | |
|
8 | + %label{:for => "user_login"} Login | |
|
9 | + %td | |
|
10 | + %label{:for => "user_full_name"} Full name | |
|
11 | + %td | |
|
12 | + %label{:for => "user_password"} Password | |
|
13 | + %td | |
|
14 | + %label{:for => "user_password_confirmation"} Confirm | |
|
15 | + %td | |
|
16 | + %label{:for => "user_email"} Email | |
|
17 | + %tr | |
|
18 | + %td= text_field 'user', 'login', :size => 10 | |
|
19 | + %td= text_field 'user', 'full_name', :size => 30 | |
|
20 | + %td= password_field 'user', 'password', :size => 10 | |
|
21 | + %td= password_field 'user', 'password_confirmation', :size => 10 | |
|
22 | + %td= email_field 'user', 'email', :size => 15 | |
|
23 | + %td= submit_tag "Create" | |
|
24 | + %br/ | |
|
25 | + %b Import from site management | |
|
26 | + = form_tag({:action => 'import'}, :multipart => true) do | |
|
27 | + File: #{file_field_tag 'file'} #{submit_tag 'Import'} | |
|
28 | + %br/ | |
|
29 | + %b What else: | |
|
30 | + = link_to 'New user', {:action => 'new'}, { class: 'btn btn-default btn-sm'} | |
|
31 | + = link_to 'New list of users',{ :action => 'new_list'}, { class: 'btn btn-default btn-sm'} | |
|
32 | + = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default btn-sm'} | |
|
33 | + = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default btn-sm'} | |
|
34 | + = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default btn-sm'} | |
|
35 | + = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default btn-sm'} | |
|
36 | + - if GraderConfiguration.multicontests? | |
|
37 | + %br/ | |
|
38 | + %b Multi-contest: | |
|
39 | + = link_to '[Manage bulk users in contests]', :action => 'contest_management' | |
|
40 | + View users in: | |
|
41 | + - @contests.each do |contest| | |
|
42 | + = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id | |
|
43 | + = link_to "[no contest]", :action => 'contests', :id => 'none' | |
|
44 | + Total #{@user_count} users | | |
|
45 | + - if !@paginated | |
|
46 | + Display all users. | |
|
47 | + \#{link_to '[show in pages]', :action => 'index', :page => '1'} | |
|
48 | + - else | |
|
49 | + Display in pages. | |
|
50 | + \#{link_to '[display all]', :action => 'index', :page => 'all'} | | |
|
51 | + \#{will_paginate @users, :container => false} | |
|
52 | + | |
|
53 | + | |
|
54 | + %table.table.table-hover.table-condense | |
|
55 | + %thead | |
|
56 | + %th Login | |
|
57 | + %th Full name | |
|
58 | + %th email | |
|
59 | + %th Remark | |
|
60 | + %th | |
|
61 | + Activated | |
|
62 | + %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'User has already confirmed the email?' } [?] | |
|
63 | + %th | |
|
64 | + Enabled | |
|
65 | + %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'Allow the user to login?' } [?] | |
|
66 | + %th Last IP | |
|
67 | + %th | |
|
68 | + %th | |
|
69 | + %th | |
|
70 | + %th | |
|
71 | + - for user in @users | |
|
72 | + %tr | |
|
73 | + %td= link_to user.login, controller: :users, :action => 'profile', :id => user | |
|
74 | + %td= user.full_name | |
|
75 | + %td= user.email | |
|
76 | + %td= user.remark | |
|
77 | + %td= toggle_button(user.activated?, toggle_activate_user_url(user),"toggle_activate_user_#{user.id}") | |
|
78 | + %td= toggle_button(user.enabled?, toggle_enable_user_url(user),"toggle_enable_user_#{user.id}") | |
|
79 | + %td= user.last_ip | |
|
80 | + %td= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?', class: 'btn btn-default btn-xs btn-block' | |
|
81 | + %td= link_to 'Show', {:action => 'show', :id => user}, class: 'btn btn-default btn-xs btn-block' | |
|
82 | + %td= link_to 'Edit', {:action => 'edit', :id => user}, class: 'btn btn-default btn-xs btn-block' | |
|
83 | + %td= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn-xs btn-block' | |
|
84 | + %br/ | |
|
85 | + = link_to '[New user]', :action => 'new' | |
|
86 | + = link_to '[New list of users]', :action => 'new_list' |
@@ -1,13 +1,5 | |||
|
1 | 1 | #js for announcement |
|
2 | 2 | $ -> |
|
3 | - $('.ajax-toggle').on 'click', (event) -> | |
|
4 | - target = $(event.target) | |
|
5 | - target.removeClass 'btn-default' | |
|
6 | - target.removeClass 'btn-success' | |
|
7 | - target.addClass 'btn-warning' | |
|
8 | - target.text '...' | |
|
9 | - return | |
|
10 | - | |
|
11 | 3 | $(document).ajaxError (event, jqxhr, settings, exception) -> |
|
12 | 4 | if jqxhr.status |
|
13 | 5 | alert 'We\'re sorry, but something went wrong (' + jqxhr.status + ')' |
@@ -30,6 +30,12 | |||
|
30 | 30 | if url |
|
31 | 31 | window.location.href = url |
|
32 | 32 | return |
|
33 | - return | |
|
33 | + $('.ajax-toggle').on 'click', (event) -> | |
|
34 | + target = $(event.target) | |
|
35 | + target.removeClass 'btn-default' | |
|
36 | + target.removeClass 'btn-success' | |
|
37 | + target.addClass 'btn-warning' | |
|
38 | + target.text '...' | |
|
39 | + return | |
|
34 | 40 | |
|
35 | - | |
|
41 | + return |
@@ -83,7 +83,8 | |||
|
83 | 83 | @announcement = Announcement.find(params[:id]) |
|
84 | 84 | @announcement.update_attributes( published: !@announcement.published? ) |
|
85 | 85 | respond_to do |format| |
|
86 | - format.js {} | |
|
86 | + format.js { render partial: 'toggle_button', | |
|
87 | + locals: {button_id: "#announcement_toggle_#{@announcement.id}",button_on: @announcement.published? } } | |
|
87 | 88 | end |
|
88 | 89 | end |
|
89 | 90 |
@@ -47,12 +47,17 | |||
|
47 | 47 | |
|
48 | 48 | # check if run in single user mode |
|
49 | 49 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
50 | - user = User.find(session[:user_id]) | |
|
50 | + user = User.find_by_id(session[:user_id]) | |
|
51 | 51 | if user==nil or (not user.admin?) |
|
52 | 52 | flash[:notice] = 'You cannot log in at this time' |
|
53 | 53 | redirect_to :controller => 'main', :action => 'login' |
|
54 | 54 | return false |
|
55 | 55 | end |
|
56 | + unless user.enabled? | |
|
57 | + flash[:notice] = 'Your account is disabled' | |
|
58 | + redirect_to :controller => 'main', :action => 'login' | |
|
59 | + return false | |
|
60 | + end | |
|
56 | 61 | return true |
|
57 | 62 | end |
|
58 | 63 |
@@ -123,7 +123,7 | |||
|
123 | 123 | @problem = Problem.find(params[:id]) |
|
124 | 124 | @problem.update_attributes(available: !(@problem.available) ) |
|
125 | 125 | respond_to do |format| |
|
126 | - format.js {} | |
|
126 | + format.js { } | |
|
127 | 127 | end |
|
128 | 128 | end |
|
129 | 129 |
@@ -17,7 +17,6 | |||
|
17 | 17 | |
|
18 | 18 | def index |
|
19 | 19 | list |
|
20 | - render :action => 'list' | |
|
21 | 20 | end |
|
22 | 21 | |
|
23 | 22 | def list |
@@ -133,6 +133,24 | |||
|
133 | 133 | problem.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | + def toggle_activate | |
|
137 | + @user = User.find(params[:id]) | |
|
138 | + @user.update_attributes( activated: !@user.activated? ) | |
|
139 | + respond_to do |format| | |
|
140 | + format.js { render partial: 'toggle_button', | |
|
141 | + locals: {button_id: "#toggle_activate_user_#{@user.id}",button_on: @user.activated? } } | |
|
142 | + end | |
|
143 | + end | |
|
144 | + | |
|
145 | + def toggle_enable | |
|
146 | + @user = User.find(params[:id]) | |
|
147 | + @user.update_attributes( enabled: !@user.enabled? ) | |
|
148 | + respond_to do |format| | |
|
149 | + format.js { render partial: 'toggle_button', | |
|
150 | + locals: {button_id: "#toggle_enable_user_#{@user.id}",button_on: @user.enabled? } } | |
|
151 | + end | |
|
152 | + end | |
|
153 | + | |
|
136 | 154 | protected |
|
137 | 155 | |
|
138 | 156 | def verify_online_registration |
@@ -192,4 +210,5 | |||
|
192 | 210 | admin_authorization |
|
193 | 211 | end |
|
194 | 212 | |
|
213 | + | |
|
195 | 214 | end |
@@ -107,16 +107,11 | |||
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | - def problem_select(problems, options = {}) | |
|
111 | - prefix = options[:with_specific_in_header] ? [[(t 'main.specified_in_header'),'-1']] : [] | |
|
112 | - selected = options[:selected] || (options[:with_specific_in_header] ? -1 : nil) | |
|
113 | - puts "selected = #{selected} hehe" | |
|
114 | - html_options = {class: 'select2 form-control'} | |
|
115 | - html_options[:id] = options[:id]if options[:id] | |
|
116 | - select 'submission', | |
|
117 | - 'problem_id', prefix + problems.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}, | |
|
118 | - (selected ? { selected: "#{selected}"} : {} ), | |
|
119 | - html_options | |
|
110 | + def toggle_button(on,toggle_url,id) | |
|
111 | + link_to (on ? "Yes" : "No"), toggle_url, | |
|
112 | + {class: "btn btn-block btn-xs btn-#{on ? 'success' : 'default'} ajax-toggle", | |
|
113 | + id: id, | |
|
114 | + data: {remote: true, method: 'get'}} | |
|
120 | 115 | end |
|
121 | 116 | |
|
122 | 117 | def user_title_bar(user) |
@@ -27,9 +27,8 | |||
|
27 | 27 | %br/ |
|
28 | 28 | = h announcement.body |
|
29 | 29 | %td= h announcement.author |
|
30 | - // %td= check_box_tag :published, 1, announcement.published, { class: 'bootstrap-toggle', id: "published-#{announcement.id}", data: {remote: true, method: 'PUT', url: url_for(controller: :announcements, action: :toggle, id: announcement), size: 'small', toggle: 'toggle' } } | |
|
31 | - // <td><haml_loud> in_place_editor_field :announcement, :published, {}, :rows => 1 </haml_loud></td> | |
|
32 | - %td= link_to (announcement.published? ? "Yes" : "No"), url_for(controller: :announcements, action: :toggle, id: announcement), { class: "btn btn-block btn-sm btn-#{(announcement.published? ? 'success' : 'default')} ajax-toggle", id: "published-#{announcement.id}", data: {remote: true, method: 'post' } } | |
|
30 | + %td= toggle_button(announcement.published?, toggle_announcement_url(@announcement), "announcement_toggle_#{@announcement.id}") | |
|
31 | + //%td= link_to (announcement.published? ? "Yes" : "No"), url_for(controller: :announcements, action: :toggle, id: announcement), { class: "btn btn-block btn-sm btn-#{(announcement.published? ? 'success' : 'default')} ajax-toggle", id: "published-#{announcement.id}", data: {remote: true, method: 'post' } } | |
|
33 | 32 | %td= link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-block btn-sm btn-info' |
|
34 | 33 | %td= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete, class: "btn btn-block btn-sm btn-danger" |
|
35 | 34 | %br |
@@ -16,7 +16,7 | |||
|
16 | 16 | %label{:for => "problem_full_name"} Full name |
|
17 | 17 | = text_field 'problem', 'full_name' |
|
18 | 18 | = submit_tag "Create" |
|
19 |
- %table.table.table-condense |
|
|
19 | + %table.table.table-condense.table-hover | |
|
20 | 20 | %thead |
|
21 | 21 | %th Name |
|
22 | 22 | %th Full name |
@@ -33,14 +33,15 | |||
|
33 | 33 | %td= in_place_editor_field :problem, :full_name, {}, :rows=>1 |
|
34 | 34 | %td= in_place_editor_field :problem, :full_score, {}, :rows=>1 |
|
35 | 35 | %td= problem.date_added |
|
36 | - %td{}= link_to (@problem.available? ? "Yes" : "No"), url_for(controller: :problems, action: :toggle, id: @problem), { class: "btn btn-block btn-sm btn-#{(@problem.available? ? 'success' : 'default')} ajax-toggle", id: "prob-#{@problem.id}-avail", data: {remote: true, method: 'post' } } | |
|
36 | + %td= toggle_button(@problem.available?, url_for(controller: :problems, action: :toggle, id: @problem), "problem-avail-#{@problem.id}") | |
|
37 | + //%td{}= link_to (@problem.available? ? "Yes" : "No"), url_for(controller: :problems, action: :toggle, id: @problem), { class: "btn btn-block btn-sm btn-#{(@problem.available? ? 'success' : 'default')} ajax-toggle", id: "problem-avail-#{@problem.id}", data: {remote: true, method: 'post' } } | |
|
37 | 38 | %td= problem.test_allowed |
|
38 | 39 | - if GraderConfiguration.multicontests? |
|
39 | 40 | %td |
|
40 | 41 | = problem.contests.collect { |c| c.name }.join(', ') |
|
41 |
- %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn- |
|
|
42 |
- %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn- |
|
|
43 |
- %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn- |
|
|
44 |
- %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn- |
|
|
42 | + %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-info btn-xs btn-block' | |
|
43 | + %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-info btn-xs btn-block' | |
|
44 | + %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-info btn-xs btn-block' | |
|
45 | + %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn-xs btn-block' | |
|
45 | 46 | %br/ |
|
46 | 47 | = link_to '[New problem]', :action => 'new' |
@@ -1,10 +1,6 | |||
|
1 | + = render partial: 'toggle_button', | |
|
2 | + locals: {button_id: "#problem-avail-#{@problem.id}",button_on: @problem.available } | |
|
1 | 3 | :plain |
|
2 | - b = $("#prob-#{@problem.id}-avail"); | |
|
3 | - b.removeClass('btn-default'); | |
|
4 | - b.removeClass('btn-success'); | |
|
5 | - b.removeClass('btn-warning'); | |
|
6 | - b.addClass("btn-#{@problem.available? ? 'success' : 'default'}"); | |
|
7 | - b.text("#{@problem.available? ? 'Yes' : 'No'}"); | |
|
8 | 4 | r = $("#prob-#{@problem.id}"); |
|
9 | 5 | r.removeClass('success'); |
|
10 | 6 | r.removeClass('danger'); |
@@ -1,19 +1,39 | |||
|
1 | 1 | CafeGrader::Application.routes.draw do |
|
2 | 2 | root :to => 'main#login' |
|
3 | 3 | |
|
4 | - get "report/login" | |
|
5 | 4 | |
|
6 | 5 | resources :contests |
|
7 | 6 | |
|
8 | - resources :announcements | |
|
9 | - match 'announcements/toggle/:id' => 'announcements#toggle' | |
|
10 | - | |
|
11 | 7 | resources :sites |
|
12 | 8 | |
|
13 |
- resources : |
|
|
9 | + resources :announcements do | |
|
10 | + member do | |
|
11 | + get 'toggle' | |
|
12 | + end | |
|
13 | + end | |
|
14 | + | |
|
15 | + | |
|
16 | + resources :problems do | |
|
17 | + member do | |
|
18 | + get 'toggle' | |
|
19 | + end | |
|
20 | + collection do | |
|
21 | + get 'turn_all_off' | |
|
22 | + get 'turn_all_on' | |
|
23 | + get 'import' | |
|
24 | + get 'manage' | |
|
25 | + end | |
|
26 | + end | |
|
14 | 27 | |
|
15 | 28 | resources :grader_configuration, controller: 'configurations' |
|
16 | 29 | |
|
30 | + resources :users do | |
|
31 | + member do | |
|
32 | + get 'toggle_activate', 'toggle_enable' | |
|
33 | + end | |
|
34 | + end | |
|
35 | + | |
|
36 | + | |
|
17 | 37 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
18 | 38 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
19 | 39 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
@@ -24,6 +44,7 | |||
|
24 | 44 | |
|
25 | 45 | #report |
|
26 | 46 | get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
47 | + get "report/login" | |
|
27 | 48 | |
|
28 | 49 | # See how all your routes lay out with "rake routes" |
|
29 | 50 |
deleted file |
You need to be logged in to leave comments.
Login now