Permalink
Browse files

Made it so clicking on chat will display what the board looked like a…

…t the time the chat was made.
  • Loading branch information...
1 parent 23fd324 commit ad83da578bfacc35f804d5e7e0d99dbcc86ccfa3 @deanius committed Jan 23, 2011
Showing with 24 additions and 7 deletions.
  1. +18 −1 app/models/chat.rb
  2. +1 −1 app/views/chats/_show.html.erb
  3. +1 −1 app/views/match/browser_view_model.js
  4. +4 −4 doc/stats.txt
View
@@ -4,8 +4,25 @@ class Chat < ActiveRecord::Base
before_save :sanitize_text
+ def board_num
+ return @board_num if @board_num
+ return @board_num=0 if match.moves.length == 0
+
+ match.moves.each_with_index do |mv, idx|
+ @board_num = idx # we stay one behind so we return the correct one
+ return @board_num if mv.created_at > self.created_at
+ end
+ return @board_num+1
+ end
+
def to_json
- {:id => id, :player => player.name, :time => created_at.strftime("%a %H:%M"), :text => text}.to_json
+ {
+ :id => id,
+ :player => player.name,
+ :time => created_at.strftime("%a %H:%M"),
+ :text => text,
+ :board_num => board_num
+ }.to_json
end
private
@@ -1,5 +1,5 @@
<% chats.each do |chat| %>
- <div class='chat_line'><b title="<%= chat.created_at.strftime("%a %H:%M") %>"><%= chat.player.name %>: </b><%= chat.text %></div>
+ <div class='chat_line' onclick="view.display_board(<%= chat.board_num %>)"><b title="<%= chat.created_at.strftime("%a %H:%M") %>"><%= chat.player.name %>: </b><%= chat.text %></div>
<% end %>
<script language="javascript">
@@ -182,7 +182,7 @@ var view = {
console.log('adding chat ' + ch.id)
view.all_chats.push(ch);
- var chatTemplate = '<div class="chat_line"><b title="${time}">${player}:</b> ${text} </div>';
+ var chatTemplate = '<div class="chat_line" onclick="view.display_board(${board_num})"><b title="${time}">${player}:</b> ${text} </div>';
render = $.tmpl( chatTemplate, ch );
$('#chat_window').append( render );
view.scroll_chat('bottom')
View
@@ -2,15 +2,15 @@
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
-| Controllers | 155 | 104 | 5 | 19 | 3 | 3 |
+| Controllers | 165 | 112 | 5 | 19 | 3 | 3 |
| Helpers | 50 | 36 | 0 | 7 | 0 | 3 |
-| Models | 954 | 665 | 18 | 90 | 5 | 5 |
+| Models | 983 | 680 | 18 | 91 | 5 | 5 |
| Libraries | 376 | 265 | 4 | 36 | 9 | 5 |
| Integration tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Functional tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Unit tests | 0 | 0 | 0 | 0 | 0 | 0 |
+----------------------+-------+-------+---------+---------+-----+-------+
-| Total | 1535 | 1070 | 27 | 152 | 5 | 5 |
+| Total | 1574 | 1093 | 27 | 153 | 5 | 5 |
+----------------------+-------+-------+---------+---------+-----+-------+
- Code LOC: 1070 Test LOC: 0 Code to Test Ratio: 1:0.0
+ Code LOC: 1093 Test LOC: 0 Code to Test Ratio: 1:0.0

0 comments on commit ad83da5

Please sign in to comment.