diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b0025d6..f7382bf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,14 +2,24 @@ class UsersController < ApplicationController load_and_authorize_resource before_filter :authenticate_user! + def sort_by_cert(certs,id) + result = 0 + certs.each do |c| + if c.id == id + result = 1 + end + end + return result + end + # GET /users # GET /users.json def index case params[:sort] when "name" @users = @users.sort_by(&:name) - when "certifications" - @users = @users.sort_by{ |u| [-u.certifications.count,u.name] } + when "cert" + @users = @users.sort_by{ |u| [-sort_by_cert(u.certifications,params[:cert].to_i),u.name] } when "orientation" @users = @users.sort_by{ |u| [-u.orientation.to_i,u.name] } when "waiver" diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e49a361..941dbdd 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -10,30 +10,37 @@ | <%= link_to 'Inactive Users', users_inactive_path %> | <%= link_to 'Recent Activity', users_activity_path %> <% end %> +<% @certifications = Certification.all.sort_by(&:id) %>
Name | +Member? | <% if current_user.admin? then %>Certifications | <% if current_user.admin? then %>Orientation? | <% end %>Waiver? | -Member? | Card? | Instructor? | <% if current_user.admin? then %>Admin? | <% end %> + <% @certifications.each do |c| %> +<%= c.name %> | + <% end %>||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<%= image_tag user.gravatar_url(:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %> | <%= link_to user.name, user %> | +<%= raw(user.member_status_symbol) %> | <% 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 %> | <% if current_user.admin? then %><%= unless user.orientation.blank? then raw("✓") end %> | <% end %><%= unless user.waiver.blank? then raw("✓") end %> | -<%= raw(user.member_status_symbol) %> | <%= unless user.cards.blank? then raw("✓") end %> | <%= if user.instructor? then raw("✓") end %> | <% if current_user.admin? then %><%= if user.admin? then raw("✓") end %> | <% end %> + <% @certifications.each do |c| %> ++ <% user.user_certifications.each do |u| %> + <% if u.certification_id == c.id %> + <%= link_to raw("✓"), u %> + <% end %> + <% end %> + | + <% end %><%= link_to 'Edit', edit_user_path(user) if can? :update, user %> | <%= link_to 'Destroy', user, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete if can? :destroy, user %> |