diff --git a/app/controllers/certifications_controller.rb b/app/controllers/certifications_controller.rb index 8dd456b..ac8cb88 100644 --- a/app/controllers/certifications_controller.rb +++ b/app/controllers/certifications_controller.rb @@ -20,7 +20,7 @@ class CertificationsController < ApplicationController @certification_users = [] #TODO: make a better SQL query for this - @certification.users.each do |user| + @certification.users.sort_by(&:name).each do |user| @certification_users.push user if can? :read, user end diff --git a/app/controllers/user_certifications_controller.rb b/app/controllers/user_certifications_controller.rb index 0d59664..8b43e18 100644 --- a/app/controllers/user_certifications_controller.rb +++ b/app/controllers/user_certifications_controller.rb @@ -13,7 +13,7 @@ class UserCertificationsController < ApplicationController # GET /user_certifications # GET /user_certifications.json def index - @grouped_user_certs = @user_certifications.group_by { |u| u.user.name } + @grouped_user_certs = @user_certifications.group_by { |uc| uc.certification } respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c0c8c8c..b026cac 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,7 +5,27 @@ class UsersController < ApplicationController # GET /users # GET /users.json def index - @users = @users.sort_by(&:name) + case params[:sort] + when "name" + @users = @users.sort_by(&:name) + when "certifications" + @users = @users.sort_by{ |u| [-u.certifications.count,u.name] } + when "orientation" + @users = @users.sort_by{ |u| [-u.orientation.to_i,u.name] } + when "waiver" + @users = @users.sort_by{ |u| [-u.waiver.to_i,u.name] } + when "member" + @users = @users.sort_by{ |u| [-u.member.to_i,u.name] } + when "card" + @users = @users.sort_by{ |u| [-u.cards.count,u.name] } + when "instructor" + @users = @users.sort{ |a,b| [b.instructor.to_s,a.name] <=> [a.instructor.to_s,b.name] } + when "admin" + @users = @users.sort{ |a,b| [b.admin.to_s,a.name] <=> [a.admin.to_s,b.name] } + else + @users = @users.sort_by(&:name) + end + respond_to do |format| format.html # index.html.erb diff --git a/app/views/user_certifications/index.html.erb b/app/views/user_certifications/index.html.erb index b84bcd5..372be3c 100644 --- a/app/views/user_certifications/index.html.erb +++ b/app/views/user_certifications/index.html.erb @@ -3,13 +3,11 @@ <%= link_to 'New User Certification', new_user_certification_path %>
+<%= link_to 'Destroy', @user_certification, :confirm => "Are you sure you want to destroy this user's certification?", :method => :delete %> +
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index be8d1c3..da10d93 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -5,7 +5,7 @@ <% end %>Name | -Certifications | +Name | + <% if current_user.admin? then %>Certifications | <% if current_user.admin? then %> -Orientation? | +Orientation? | <% end %> -Waiver? | -Member? | -Card? | -Instructor? | -Admin? | +Waiver? | +Member? | +Card? | +Instructor? | +Admin? | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<%= link_to user.name, user %> | -<%= user.email %> | + <% if current_user.admin? then %><%= user.email %> | <% end %><% user.certifications.each do |c| %> <%= link_to c.name, c %><%= "," unless c.id == user.certifications.last.id %> <% end %> | diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index d6da0a1..678bb76 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -4,23 +4,37 @@ <%= @user.name %> +