Separating certs into columns

This commit is contained in:
Will Bradley 2013-09-23 20:24:38 -07:00
parent c5e02a51be
commit ec139a97a8
2 changed files with 33 additions and 10 deletions

View File

@ -2,14 +2,24 @@ class UsersController < ApplicationController
load_and_authorize_resource load_and_authorize_resource
before_filter :authenticate_user! 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
# GET /users.json # GET /users.json
def index def index
case params[:sort] case params[:sort]
when "name" when "name"
@users = @users.sort_by(&:name) @users = @users.sort_by(&:name)
when "certifications" when "cert"
@users = @users.sort_by{ |u| [-u.certifications.count,u.name] } @users = @users.sort_by{ |u| [-sort_by_cert(u.certifications,params[:cert].to_i),u.name] }
when "orientation" when "orientation"
@users = @users.sort_by{ |u| [-u.orientation.to_i,u.name] } @users = @users.sort_by{ |u| [-u.orientation.to_i,u.name] }
when "waiver" when "waiver"

View File

@ -10,30 +10,37 @@
| <%= link_to 'Inactive Users', users_inactive_path %> | <%= link_to 'Inactive Users', users_inactive_path %>
| <%= link_to 'Recent Activity', users_activity_path %> | <%= link_to 'Recent Activity', users_activity_path %>
<% end %> <% end %>
<% @certifications = Certification.all.sort_by(&:id) %>
<table> <table>
<col /> <col />
<col /> <col />
<% if current_user.admin? then %><col /><% end %> <% if current_user.admin? then %><col /><% end %>
<col /> <col class="col_highlight" />
<% if current_user.admin? %><col /> <% if current_user.admin? %><col />
<col class="col_highlight" /><% end %> <col class="col_highlight" /><% end %>
<col /> <col />
<col class="col_highlight" /> <col class="col_highlight" />
<col /> <col />
<col class="col_highlight" /> <% col_count = 0 %>
<% @certifications.each do |c| %>
<col <% if col_count.even? %>class="col_highlight"<% end %> />
<% col_count = col_count + 1 %>
<% end %>
<tr> <tr>
<th></th> <th></th>
<th><a href="?sort=name">Name</a></th> <th><a href="?sort=name">Name</a></th>
<th><a href="?sort=member">Member?</a></th>
<% if current_user.admin? then %><th><a href="?sort=email">Email</a></th><% end %> <% if current_user.admin? then %><th><a href="?sort=email">Email</a></th><% end %>
<th><a href="?sort=certifications">Certifications</a></th>
<% if current_user.admin? then %> <% if current_user.admin? then %>
<th><a href="?sort=orientation">Orientation?</a></th> <th><a href="?sort=orientation">Orientation?</a></th>
<% end %> <% end %>
<th><a href="?sort=waiver">Waiver?</a></th> <th><a href="?sort=waiver">Waiver?</a></th>
<th><a href="?sort=member">Member?</a></th>
<th><a href="?sort=card">Card?</a></th> <th><a href="?sort=card">Card?</a></th>
<th><a href="?sort=instructor">Instructor?</a></th> <th><a href="?sort=instructor">Instructor?</a></th>
<% if current_user.admin? then %><th><a href="?sort=admin">Admin?</a></th><% end %> <% if current_user.admin? then %><th><a href="?sort=admin">Admin?</a></th><% end %>
<% @certifications.each do |c| %>
<th><a href="?sort=cert&cert=<%= c.id %>"><%= c.name %></a></th>
<% end %>
<th></th> <th></th>
<th></th> <th></th>
</tr> </tr>
@ -43,18 +50,24 @@
<tr<%= " class='hidden'" if user.hidden? %>> <tr<%= " class='hidden'" if user.hidden? %>>
<td><%= image_tag user.gravatar_url(:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %></td> <td><%= image_tag user.gravatar_url(:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %></td>
<td><%= link_to user.name, user %></td> <td><%= link_to user.name, user %></td>
<td><%= raw(user.member_status_symbol) %></td>
<% if current_user.admin? then %><td><%= user.email %></td><% end %> <% if current_user.admin? then %><td><%= user.email %></td><% end %>
<td><% user.certifications.each do |c| %>
<%= link_to c.name, c %><%= "," unless c.id == user.certifications.last.id %>
<% end %></td>
<% if current_user.admin? then %><td> <% if current_user.admin? then %><td>
<%= unless user.orientation.blank? then raw("<span class='hoverinfo' title='"+user.orientation.strftime("%B %d %Y")+"'>&#x2713;</span>") end %> <%= unless user.orientation.blank? then raw("<span class='hoverinfo' title='"+user.orientation.strftime("%B %d %Y")+"'>&#x2713;</span>") end %>
</td><% end %> </td><% end %>
<td><%= unless user.waiver.blank? then raw("<span class='hoverinfo' title='"+user.waiver.strftime("%B %d %Y")+"'>&#x2713;</span>") end %></td> <td><%= unless user.waiver.blank? then raw("<span class='hoverinfo' title='"+user.waiver.strftime("%B %d %Y")+"'>&#x2713;</span>") end %></td>
<td><%= raw(user.member_status_symbol) %></td>
<td><%= unless user.cards.blank? then raw("<span class='iconinfo'>&#x2713;</span>") end %></td> <td><%= unless user.cards.blank? then raw("<span class='iconinfo'>&#x2713;</span>") end %></td>
<td><%= if user.instructor? then raw("<span class='iconinfo'>&#x2713;</a>") end %></td> <td><%= if user.instructor? then raw("<span class='iconinfo'>&#x2713;</a>") end %></td>
<% if current_user.admin? then %><td><%= if user.admin? then raw("<span class='iconinfo'>&#x2713;</a>") end %></td><% end %> <% if current_user.admin? then %><td><%= if user.admin? then raw("<span class='iconinfo'>&#x2713;</a>") end %></td><% end %>
<% @certifications.each do |c| %>
<td>
<% user.user_certifications.each do |u| %>
<% if u.certification_id == c.id %>
<%= link_to raw("<span class='iconinfo'>&#x2713;</span>"), u %>
<% end %>
<% end %>
</td>
<% end %>
<td><%= link_to 'Edit', edit_user_path(user) if can? :update, user %></td> <td><%= link_to 'Edit', edit_user_path(user) if can? :update, user %></td>
<td><%= 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 %></td> <td><%= 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 %></td>
</tr> </tr>