Browse Source

Step 5: The listing page shows when the website was added and how many up and down votes it has.

Frederic G. MARAND 9 years ago
parent
commit
195d217103
4 changed files with 32 additions and 2 deletions
  1. 6 1
      client/website_form.js
  2. 1 0
      client/website_item.html
  3. 22 0
      client/website_item.js
  4. 3 1
      server/collections.js

+ 6 - 1
client/website_form.js

@@ -14,9 +14,14 @@ Template.website_form.events({
     const url = event.target.url.value;
     const title = event.target.title.value;
     const description = event.target.description.value;
+    let poster = {
+      _id: Meteor.userId(),
+      name: Meteor.user().username
+    };
+    const postDate = new Date();
 
     //  put your website saving code in here!
-    const doc = { url, title, description };
+    const doc = { url, title, description, poster, postDate };
     Meteor._debug("Client trying to insert", doc);
     Websites.insert(doc);
 

+ 1 - 0
client/website_item.html

@@ -5,6 +5,7 @@
     <p>
       {{description}}
     </p>
+    <p>Added on {{ postDate }}. Votes: Plus = {{ plusVotes }} / Minus = {{ minusVotes }} /  Score = {{ score }}.</p>
     {{#if isLoggedIn }}
       <a href="#" class="btn btn-default js-upvote {{ upVoted }}">
         <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>

+ 22 - 0
client/website_item.js

@@ -72,5 +72,27 @@ Template.website_item.helpers({
 
   downVoted: function () {
     return _.contains(this.minus, Meteor.userId()) ? "btn-danger" : "";
+  },
+
+  postDate: function () {
+    return this.postDate ? this.postDate : "Application launch";
+  },
+
+  poster: function () {
+    return this.poster && this.poster.name ? this.poster.name : "Application setup";
+  },
+
+  minusVotes: function () {
+    return this.minusScore ? this.minusScore : 0;
+  },
+
+  plusVotes: function () {
+    return this.plusScore ? this.plusScore : 0;
+  },
+
+  score: function () {
+    const plus = this.plusScore ? this.plusScore : 0;
+    const minus = this.minusScore ? this.minusScore : 0;
+    return plus - minus;
   }
 });

+ 3 - 1
server/collections.js

@@ -4,7 +4,9 @@ Websites.allow({
     check(doc, {
       url: String,
       title: String,
-      description: String
+      description: String,
+      poster: Object,
+      postDate: Date
     });
 
     // Reject anonymous inserts.