Skip to content
Browse files

Game scores easier to read.

  • Loading branch information...
1 parent 955f19c commit 6b8a12a3c064abbbf86b675449dd382a53bc9710 Alex Burkhart committed
View
8 app/helpers/application_helper.rb
@@ -3,4 +3,12 @@ def link_to_with_current(name, url)
options = (current_page? url) ? { class: "current" } : {}
link_to name, url, options
end
+
+ def format_game_scores(scores)
+ spans = scores.map do |w, l, status|
+ content_tag 'span', "#{w}-#{l}", class: status
+ end.join
+
+ raw(spans)
+ end
end
View
6 app/models/match.rb
@@ -15,13 +15,13 @@ class Match < ActiveRecord::Base
def game_scores
self.games.map do |game|
if game.winner == self.winner
- "#{game.winner_score}-#{game.loser_score}"
+ [game.winner_score, game.loser_score, :win]
elsif game.winner == self.loser
- "#{game.loser_score}-#{game.winner_score}"
+ [game.loser_score, game.winner_score, :loss]
else
raise "Game winner did not play in this match. Data corruption likely."
end
- end.join(' ')
+ end
end
private
View
2 app/views/shared/_matches.html.haml
@@ -27,6 +27,6 @@
= "#{m.winner_score} - #{m.loser_score}"
%td.game-scores.score
- if m.games.first
- = m.game_scores
+ = format_game_scores m.game_scores
%td.action
= link_to "delete", match_path(m), method: :delete
View
14 public/javascripts/application.js
@@ -13,9 +13,17 @@ $(document).ready( function(){
}
});
- $('#matches').on('click', '.score', function(e){
+ var $matches = $('#matches')
+ , show_match_scores = true;
+
+ $matches.on('click', 'td.score', function(e){
var $match = $(e.target).parent('tr');
- $match.find('.match-score').toggle();
- $match.find('.game-scores').toggle();
+ $match.find('.score').toggle();
+ });
+
+ $matches.on('click', 'th.score', function(e) {
+ show_match_scores = !show_match_scores;
+ $matches.find('td.match-score').toggle(show_match_scores);
+ $matches.find('td.game-scores').toggle(!show_match_scores);
});
});
View
12 public/stylesheets/pong.css
@@ -107,6 +107,18 @@ li, td {
font-size: 12px;
}
+#matches td.game-scores span {
+ margin-right: 4px;
+}
+
+#matches td.game-scores span.win {
+ color: #050;
+}
+
+#matches td.game-scores span.loss {
+ color: #700;
+}
+
#matches td.action, #matches th.action {
font-size: 12px;
text-align: center;

0 comments on commit 6b8a12a

Please sign in to comment.
Something went wrong with that request. Please try again.