Permalink
Browse files

sick player page

  • Loading branch information...
1 parent d9692f5 commit 9194fc95cac79b9eb71727874cfdf27c7487a564 @pedro pedro committed Apr 13, 2012
Showing with 48 additions and 4 deletions.
  1. +9 −0 lib/ranked/api.rb
  2. +11 −0 lib/ranked/result.rb
  3. +2 −1 views/index.haml
  4. +20 −0 views/player.haml
  5. +2 −1 views/players.haml
  6. +4 −2 views/results.haml
View
@@ -42,6 +42,15 @@ def link_class(path)
haml :players
end
+ get "/players/:id" do |id|
+ authenticate
+ @player = Player.find(:id => id)
+ @wins = Result.filter(:winner_id => id).count
+ @losses = Result.filter(:loser_id => id).count
+ @recent = Result.filter({:winner_id => id, :loser_id => id}.sql_or).limit(10)
+ haml :player
+ end
+
get "/results" do
authenticate
@results = Result.all
View
@@ -8,5 +8,16 @@ def winner_user
def loser_user
Player[loser_id].user
end
+
+ def oponent(player)
+ [winner_user, loser_user].reject { |p| p == player }.first
+ end
+
+ def result(player)
+ {
+ winner_id => "win",
+ loser_id => "loss",
+ }[player.id]
+ end
end
end
View
@@ -9,4 +9,5 @@
- @players.each_with_index do |player, i|
%tr
%td= "##{i+1}"
- %td= player.user
+ %td
+ %a{:href=>"/players/#{player.id}"}= player.user
View
@@ -0,0 +1,20 @@
+.container
+
+ %h2= @player.user
+
+ %span.label.label-success= "#{@wins} wins"
+ %span.label.label-important= "#{@losses} losses"
+
+.container
+ %h3 Recently
+
+ %table.table.table-condensed.table-striped
+ %tr
+ %th Date
+ %th Against
+ %th Result
+ - @recent.each do |result|
+ %tr
+ %td= result.at
+ %td= result.oponent(@player)
+ %td= result.result(@player)
View
@@ -7,4 +7,5 @@
%tbody
- @players.each do |player|
%tr
- %td= player.user
+ %td
+ %a{:href=>"/players/#{player.id}"}= player.user
View
@@ -18,5 +18,7 @@
- @results.each do |result|
%tr
%td= result.at
- %td= result.winner_user
- %td= result.loser_user
+ %td
+ %a{:href=>"/players/#{result.winner_id}"}= result.winner_user
+ %td
+ %a{:href=>"/players/#{result.loser_id}"}= result.loser_user

0 comments on commit 9194fc9

Please sign in to comment.