Преглед изворни кода

Commit 10-1: Added comments collection, pub/sub and fixtures.

Frederic G. MARAND пре 9 година
родитељ
комит
d27a5733b5
5 измењених фајлова са 68 додато и 33 уклоњено
  1. 1 0
      .jshintrc
  2. 10 0
      lib/collections/comments.js
  3. 4 1
      lib/router.js
  4. 51 21
      server/fixtures.js
  5. 2 11
      server/publications.js

+ 1 - 0
.jshintrc

@@ -132,6 +132,7 @@
 
       // Microscope globals
       // - Collections
+      "Comments": true,
       "Errors": true,
       "Mongo": true,
       "Posts": true,

+ 10 - 0
lib/collections/comments.js

@@ -0,0 +1,10 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 05/09/15
+ * Time: 21:47
+ */
+
+Comments = new Mongo.Collection('comments');

+ 4 - 1
lib/router.js

@@ -12,7 +12,10 @@ Router.configure({
   loadingTemplate: "loading",
   notFoundTemplate: "notFound",
   waitOn: function () {
-    return Meteor.subscribe('posts');
+    return [
+      Meteor.subscribe('posts'),
+      Meteor.subscribe('comments'),
+    ];
   }
 });
 

+ 51 - 21
server/fixtures.js

@@ -8,27 +8,57 @@
  */
 
 if (Posts.find().count() === 0) {
-  var data = [
-    {
-      title: "Introducing Telescope",
-      url: "http://sachagreif.com/introducing-telescope",
-      author: "Sacha Greif"
-    },
-    {
-      title: "Meteor",
-      url: "http://meteor.com",
-      author: "Tom Coleman"
-      },
-    {
-      title: "The Meteor book",
-      url: "http://themeteorbook.com",
-      author: "Meteor Inc."
-      }
-  ];
-
-  data.forEach(function (post) {
-    Meteor._debug("Inserting", post);
-    Posts.insert(post);
+  var now = new Date().getTime();
+
+  // Create two users.
+  var tomId = Meteor.users.insert({
+    profile: {name: 'Tom Coleman'}
+  });
+  var tom = Meteor.users.findOne(tomId);
+
+  var sachaId = Meteor.users.insert({
+    profile: {name: 'Sacha Greif'}
+  });
+  var sacha = Meteor.users.findOne(sachaId);
+
+  var telescopeId = Posts.insert({
+    title: "Introducing Telescope",
+    userId: sacha._id,
+    author: sacha.profile.name,
+    url: "http://sachagreif.com/introducing-telescope",
+    submitted: new Date(now - 7 * 3600 * 1000)
+  });
+
+  Comments.insert({
+    postId: telescopeId,
+    userId: tom._id,
+    author: tom.profile.name,
+    submitted: new Date(now - 5 * 3600 * 1000),
+    body: 'Interesting project Sacha, can I get involved?'
+  });
+
+  Comments.insert({
+    postId: telescopeId,
+    userId: sacha._id,
+    author: sacha.profile.name,
+    submitted: new Date(now - 3 * 3600 * 1000),
+    body: 'You sure can Tom!'
+  });
+
+  Posts.insert({
+    title: "Meteor",
+    userId: tom._id,
+    author: tom.profile.name,
+    url: "http://meteor.com",
+    submitted: new Date(now - 10 * 3600 * 1000)
+  });
+
+  Posts.insert({
+    title: "The Meteor book",
+    userId: tom._id,
+    author: tom.profile.name,
+    url: "http://themeteorbook.com",
+    submitted: new Date(now - 12 * 3600 * 1000)
   });
 }
 else {

+ 2 - 11
server/publications.js

@@ -11,15 +11,6 @@ Meteor.publish('posts', function() {
   return Posts.find();
 });
 
-Meteor.publish('userData', function () {
-  // If user is logged-in.
-  if (this.userId) {
-    return Meteor.users.find({
-      _id: this.userId
-    }, {
-      fields: {
-        'emails': 1
-      }
-    });
-  }
+Meteor.publish('comments', function() {
+  return Comments.find();
 });