Browse Source

Commit 10-2: Display comments on postPage.

Frederic G. MARAND 9 years ago
parent
commit
866d1a8d11

+ 14 - 0
client/templates/comments/comment_item.js

@@ -0,0 +1,14 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 05/09/15
+ * Time: 22:10
+ */
+
+Template.commentItem.helpers({
+  submittedText: function () {
+    return this.submitted.toString();
+  }
+});

+ 9 - 0
client/templates/comments/commment_item.html

@@ -0,0 +1,9 @@
+<template name="commentItem">
+  <li>
+    <h4>
+      <span class="author">{{author}}</span>
+      <span class="date">{{submittedText}}</span>
+    </h4>
+    <p>{{body}}</p>
+  </li>
+</template>

+ 4 - 4
client/templates/posts/post_item.html

@@ -2,10 +2,10 @@
   <div class="post">
     <div class="post-content">
       <h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3>
-      <p>Submitted by {{author}}</p>
-      {{#if ownPost}}
-        <a href="{{pathFor 'postEdit' }}">Edit</a>
-      {{/if}}
+      <p>Submitted by {{author}},
+        <a href="{{pathFor 'postPage' }}">{{commentsCount}} comments</a>
+        {{#if ownPost}}<a href="{{pathFor 'postEdit' }}">Edit</a>{{/if}}
+      </p>
     </div>
     {{! La route postPage nécessite un _id, donc IR va le chercher dans le
       data context, qui se trouve à ce stade être le document concerné, qui

+ 4 - 0
client/templates/posts/post_item.js

@@ -17,5 +17,9 @@ Template.postItem.helpers({
     var a = document.createElement('a');
     a.href = this.url;
     return a.hostname;
+  },
+
+  commentsCount: function () {
+    return Comments.find({postId: this._id}).count();
   }
 });

+ 5 - 0
client/templates/posts/post_page.html

@@ -1,5 +1,10 @@
 <template name="postPage">
   <div class="post-page page">
     {{> postItem}}
+    <ul class="comments">
+      {{#each comments}}
+        {{> commentItem}}
+      {{/each}}
+    </ul>
   </div>
 </template>

+ 16 - 0
client/templates/posts/post_page.js

@@ -0,0 +1,16 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 05/09/15
+ * Time: 22:06
+ */
+
+Template.postPage.helpers({
+  comments: function () {
+    return Comments.find({
+      postId: this._id
+    });
+  }
+});