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 = [] @certification_users = []
#TODO: make a better SQL query for this #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 @certification_users.push user if can? :read, user
end end

View File

@ -13,7 +13,7 @@ class UserCertificationsController < ApplicationController
# GET /user_certifications # GET /user_certifications
# GET /user_certifications.json # GET /user_certifications.json
def index 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| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb

View File

@ -5,7 +5,27 @@ class UsersController < ApplicationController
# GET /users # GET /users
# GET /users.json # GET /users.json
def index def index
case params[:sort]
when "name"
@users = @users.sort_by(&: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| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb

View File

@ -3,13 +3,11 @@
<%= link_to 'New User Certification', new_user_certification_path %> <%= link_to 'New User Certification', new_user_certification_path %>
<dl> <dl>
<% @grouped_user_certs.sort.each do |user, user_certifications| %> <% @grouped_user_certs.sort.each do |cert, user_certifications| %>
<dt><%= user %></dt> <dt><%= cert.name %></dt>
<% user_certifications.each do |user_certification| %> <% user_certifications.sort{|a,b| a.user.name <=> b.user.name}.each do |user_certification| %>
<dd> <dd>
<%= link_to user_certification.certification.name, user_certification %> | <%= link_to user_certification.user.name, user_certification %>
<%= link_to 'Edit', edit_user_certification_path(user_certification) %> |
<%= link_to 'Destroy', user_certification, :confirm => 'Are you sure?', :method => :delete %>
</dd> </dd>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -20,3 +20,6 @@
<%= link_to 'Edit', edit_user_certification_path(@user_certification) %> | <%= link_to 'Edit', edit_user_certification_path(@user_certification) %> |
<%= link_to 'Back', user_certifications_path %> <%= 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 %> <% end %>
<table> <table>
<col /> <col />
<col /> <% if current_user.admin? then %><col /><% end %>
<col /> <col />
<% if current_user.admin? %><col /><% end %> <% if current_user.admin? %><col /><% end %>
<col class="col_highlight" /> <col class="col_highlight" />
@ -14,17 +14,17 @@
<col /> <col />
<col class="col_highlight" /> <col class="col_highlight" />
<tr> <tr>
<th>Name</th> <th><a href="?sort=name">Name</a></th>
<th>Email</th> <% if current_user.admin? then %><th><a href="?sort=email">Email</a></th><% end %>
<th>Certifications</th> <th><a href="?sort=certifications">Certifications</a></th>
<% if current_user.admin? then %> <% if current_user.admin? then %>
<th>Orientation?</th> <th><a href="?sort=orientation">Orientation?</a></th>
<% end %> <% end %>
<th>Waiver?</th> <th><a href="?sort=waiver">Waiver?</a></th>
<th>Member?</th> <th><a href="?sort=member">Member?</a></th>
<th>Card?</th> <th><a href="?sort=card">Card?</a></th>
<th>Instructor?</th> <th><a href="?sort=instructor">Instructor?</a></th>
<th>Admin?</th> <th><a href="?sort=admin">Admin?</a></th>
<th></th> <th></th>
<th></th> <th></th>
</tr> </tr>
@ -33,7 +33,7 @@
<% @users.each do |user| %> <% @users.each do |user| %>
<tr> <tr>
<td><%= link_to user.name, user %></td> <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| %> <td><% user.certifications.each do |c| %>
<%= link_to c.name, c %><%= "," unless c.id == user.certifications.last.id %> <%= link_to c.name, c %><%= "," unless c.id == user.certifications.last.id %>
<% end %></td> <% end %></td>

View File

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