From ec7298d548b4a8bef12b2d1fe037e9f112ad730e Mon Sep 17 00:00:00 2001
From: Robin Ward <robin.ward@gmail.com>
Date: Mon, 4 Nov 2013 15:48:51 -0500
Subject: [PATCH] FIX: Regression on topic list for best of links.

---
 .../discourse/helpers/grouped_each.js         | 10 ++++--
 .../list/basic_topic_list.js.handlebars       | 36 +++++++++----------
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/app/assets/javascripts/discourse/helpers/grouped_each.js b/app/assets/javascripts/discourse/helpers/grouped_each.js
index 218232acad7..86c3ce13d1d 100644
--- a/app/assets/javascripts/discourse/helpers/grouped_each.js
+++ b/app/assets/javascripts/discourse/helpers/grouped_each.js
@@ -75,11 +75,17 @@ DiscourseGroupedEach.prototype = {
     var content = this.content,
         contentLength = Em.get(content, 'length'),
         data = this.options.data,
-        template = this.template;
+        template = this.template,
+        keyword = this.options.hash.keyword;
 
     data.insideEach = true;
     for (var i = 0; i < contentLength; i++) {
-      template(content.objectAt(i), { data: data });
+      var row = content.objectAt(i);
+      if (keyword) {
+        data.keywords = data.keywords || {};
+        data.keywords[keyword] = row;
+      }
+      template(row, { data: data });
     }
   },
 
diff --git a/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars b/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars
index 8c11a522678..7bab4e628ae 100644
--- a/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars
+++ b/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars
@@ -13,50 +13,50 @@
       <th class='num activity' colspan='2'>{{i18n activity}}</th>
     </tr>
 
-    {{#each view.topics}}
+    {{#groupedEach topic in view.topics}}
       <tr {{bindAttr class="archived"}}>
         <td class='main-link'>
-          {{topicStatus topic=this}}
-          <a class='title' href="{{unbound lastUnreadUrl}}">{{{unbound fancy_title}}}</a>
+          {{topicStatus topic=topic}}
+          <a class='title' href="{{unbound topic.lastUnreadUrl}}">{{{unbound topic.fancy_title}}}</a>
           {{#if unread}}
-            <a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unbound unread}}</a>
+            <a href="{{unbound topic.lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unbound topic.unread}}</a>
           {{/if}}
-          {{#if new_posts}}
-            <a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{unbound new_posts}}</a>
+          {{#if topic.new_posts}}
+            <a href="{{unbound topic.lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{unbound topic.new_posts}}</a>
           {{/if}}
-          {{#if unseen}}
-            <a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
+          {{#if topic.unseen}}
+            <a href="{{unbound topic.lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
           {{/if}}
         </td>
         {{#unless controller.hideCategories}}
           <td class='category'>
-            {{categoryLink category}}
+            {{categoryLink topic.category}}
           </td>
         {{/unless}}
-        <td class='num posts'><a href="{{unbound lastUnreadUrl}}" class='badge-posts'>{{number posts_count numberKey="posts_long"}}</a></td>
+        <td class='num posts'><a href="{{unbound topic.lastUnreadUrl}}" class='badge-posts'>{{number topic.posts_count numberKey="posts_long"}}</a></td>
 
         <td class='num likes'>
-          {{#if like_count}}
-            <a href='{{unbound url}}{{#if has_best_of}}?filter=best_of{{/if}}'>{{unbound like_count}} <i class='icon-heart'></i></a>
+          {{#if topic.like_count}}
+            <a href='{{unbound topic.url}}{{#if topic.has_best_of}}?filter=best_of{{/if}}'>{{unbound topic.like_count}} <i class='icon-heart'></i></a>
           {{/if}}
         </td>
 
-        <td {{bindAttr class=":num :views viewsHeat"}}>{{number views numberKey="views_long"}}</td>
-        {{#if bumped}}
+        <td {{bindAttr class=":num :views topic.viewsHeat"}}>{{number topic.views numberKey="views_long"}}</td>
+        {{#if topic.bumped}}
           <td class='num activity'>
-            <a href="{{unbound url}}" {{{bindAttr class=":age ageCold"}}} title='{{i18n first_post}}: {{{unboundDate created_at}}}' >{{unboundAge created_at}}</a>
+            <a href="{{topic.unbound url}}" {{{bindAttr class=":age topic.ageCold"}}} title='{{i18n first_post}}: {{{unboundDate topic.created_at}}}' >{{unboundAge topic.created_at}}</a>
           </td>
           <td class='num activity last'>
-            <a href="{{unbound lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate bumped_at}}}'>{{unboundAge bumped_at}}</a>
+            <a href="{{unbound topic.lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate topic.bumped_at}}}'>{{unboundAge topic.bumped_at}}</a>
           </td>
         {{else}}
           <td class='num activity'>
-            <a href="{{unbound url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{unboundAge created_at}}</a>
+            <a href="{{unbound topic.url}}" class='age' title='{{i18n first_post}}: {{{unboundDate topic.created_at}}}'>{{unboundAge topic.created_at}}</a>
           </td>
           <td class="activity"></td>
         {{/if}}
       </tr>
-    {{/each}}
+    {{/groupedEach}}
 
   </table>
 {{else}}