Skip to content
This repository
Browse code

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

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

0 notes on commit ad83da5

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