More UI tweaks and sorting

This commit is contained in:
Will Bradley 2013-01-25 11:11:39 -07:00
parent 0b6975a655
commit 2327340b71
7 changed files with 71 additions and 49 deletions

View File

@ -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

View File

@ -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

View File

@ -5,7 +5,27 @@ class UsersController < ApplicationController
# 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 "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

View File

@ -3,13 +3,11 @@
<%= link_to 'New User Certification', new_user_certification_path %>
<dl>
<% @grouped_user_certs.sort.each do |user, user_certifications| %>
<dt><%= user %></dt>
<% user_certifications.each do |user_certification| %>
<% @grouped_user_certs.sort.each do |cert, user_certifications| %>
<dt><%= cert.name %></dt>
<% user_certifications.sort{|a,b| a.user.name <=> b.user.name}.each do |user_certification| %>
<dd>
<%= 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 %>
</dd>
<% end %>
<% end %>

View File

@ -20,3 +20,6 @@
<%= link_to 'Edit', edit_user_certification_path(@user_certification) %> |
<%= link_to 'Back', user_certifications_path %>
<p>
<%= link_to 'Destroy', @user_certification, :confirm => "Are you sure you want to destroy this user's certification?", :method => :delete %>
</p>

View File

@ -5,7 +5,7 @@
<% end %>
<table>
<col />
<col />
<% if current_user.admin? then %><col /><% end %>
<col />
<% if current_user.admin? %><col /><% end %>
<col class="col_highlight" />
@ -14,17 +14,17 @@
<col />
<col class="col_highlight" />
<tr>
<th>Name</th>
<th>Email</th>
<th>Certifications</th>
<th><a href="?sort=name">Name</a></th>
<% 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 %>
<th>Orientation?</th>
<th><a href="?sort=orientation">Orientation?</a></th>
<% end %>
<th>Waiver?</th>
<th>Member?</th>
<th>Card?</th>
<th>Instructor?</th>
<th>Admin?</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=instructor">Instructor?</a></th>
<th><a href="?sort=admin">Admin?</a></th>
<th></th>
<th></th>
</tr>
@ -33,7 +33,7 @@
<% @users.each do |user| %>
<tr>
<td><%= link_to user.name, user %></td>
<td><%= user.email %></td>
<% 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>

View File

@ -4,23 +4,37 @@
<%= @user.name %>
</p>
<p>
<b>Waiver?</b>
<%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %>
</p>
<p>
<b>Current Member?</b>
<%= raw(@user.member_status) %>
</p>
<p>
<b>Instructor?</b>
<%= @user.instructor? %>
</p>
<p>
<b>Admin?</b>
<%= @user.admin? %>
</p>
<% if current_user.admin? then %>
<p>
<b>Email:</b>
<%= @user.email %>
</p>
<p>
<b>Waiver?</b>
<%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %>
</p>
<% if current_user.admin? then %>
<p>
<b>Orientation?</b>
<%= @user.orientation.strftime("%B %d %Y") unless @user.orientation.blank? %>
</p>
<% end %>
<p>
<b>Emergency Name:</b>
<%= @user.emergency_name %>
@ -45,6 +59,7 @@
<b>Phone:</b>
<%= @user.phone %>
</p>
<% end %>
<p>
<b>Current Skills:</b>
<%= simple_format @user.current_skills %>
@ -53,30 +68,16 @@
<b>Desired Skills:</b>
<%= simple_format @user.desired_skills %>
</p>
<p>
<b>Current Member?</b>
<%= raw(@user.member_status) %>
</p>
<p>
<b>Instructor?</b>
<%= @user.instructor? %>
</p>
<p>
<b>Admin?</b>
<%= @user.admin? %>
</p>
<% if current_user.admin? then %>
<p>
<b>Cards:</b>
<b>Card:</b>
<% 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("&#x2713;") end %>
<% end %>
</p>
<% end %>
<b>Certifications:</b>
<ul>