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 %>
- <% @grouped_user_certs.sort.each do |user, user_certifications| %> -
<%= user %>
- <% user_certifications.each do |user_certification| %> + <% @grouped_user_certs.sort.each do |cert, user_certifications| %> +
<%= cert.name %>
+ <% user_certifications.sort{|a,b| a.user.name <=> b.user.name}.each do |user_certification| %>
- <%= link_to user_certification.certification.name, user_certification %> | - <%= link_to 'Edit', edit_user_certification_path(user_certification) %> | - <%= link_to 'Destroy', user_certification, :confirm => 'Are you sure?', :method => :delete %> + <%= link_to user_certification.user.name, user_certification %>
<% end %> <% end %> diff --git a/app/views/user_certifications/show.html.erb b/app/views/user_certifications/show.html.erb index 7ffc0db..ebd167a 100644 --- a/app/views/user_certifications/show.html.erb +++ b/app/views/user_certifications/show.html.erb @@ -20,3 +20,6 @@ <%= link_to 'Edit', edit_user_certification_path(@user_certification) %> | <%= link_to 'Back', user_certifications_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 %> - + <% if current_user.admin? then %><% end %> <% if current_user.admin? %><% end %> @@ -14,17 +14,17 @@ - - - + + <% if current_user.admin? then %><% end %> + <% if current_user.admin? then %> - + <% end %> - - - - - + + + + + @@ -33,7 +33,7 @@ <% @users.each do |user| %> - + <% if current_user.admin? then %><% 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 %>

+

+ Waiver? + <%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %> +

+ +

+ Current Member? + <%= raw(@user.member_status) %> +

+ +

+ Instructor? + <%= @user.instructor? %> +

+ +

+ Admin? + <%= @user.admin? %> +

+ + +<% if current_user.admin? then %>

Email: <%= @user.email %>

-

- Waiver? - <%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %> -

- -<% if current_user.admin? then %>

Orientation? <%= @user.orientation.strftime("%B %d %Y") unless @user.orientation.blank? %>

-<% end %> -

Emergency Name: <%= @user.emergency_name %> @@ -45,6 +59,7 @@ Phone: <%= @user.phone %>

+<% end %>

Current Skills: <%= simple_format @user.current_skills %> @@ -53,30 +68,16 @@ Desired Skills: <%= simple_format @user.desired_skills %>

-

- Current Member? - <%= raw(@user.member_status) %> -

- -

- Instructor? - <%= @user.instructor? %> -

- -

- Admin? - <%= @user.admin? %> -

- -<% if current_user.admin? then %> -

- Cards: - <% @user.cards.each do |c| %> - <%= link_to c.card_number, c %><%= "," unless c == @user.cards.last %> + Card: + <% if current_user.admin? then %> + <% @user.cards.each do |c| %> + <%= link_to c.card_number, c %><%= "," unless c == @user.cards.last %> + <% end %> + <% else %> + <%= unless @user.cards.blank? then raw("✓") end %> <% end %>

-<% end %> Certifications:
NameEmailCertificationsNameEmailCertificationsOrientation?Orientation?Waiver?Member?Card?Instructor?Admin?Waiver?Member?Card?Instructor?Admin?
<%= link_to user.name, user %><%= user.email %><%= user.email %><% user.certifications.each do |c| %> <%= link_to c.name, c %><%= "," unless c.id == user.certifications.last.id %> <% end %>