2016-12-13 11:32:23 +09:00
|
|
|
import { newMutation } from 'meteor/nova:core';
|
2016-06-07 15:03:00 +09:00
|
|
|
import moment from 'moment';
|
2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-06-23 12:17:39 +09:00
|
|
|
import Comments from "meteor/nova:comments";
|
2016-06-23 15:00:58 +09:00
|
|
|
import Users from 'meteor/nova:users';
|
2016-06-23 15:16:32 +09:00
|
|
|
import Events from "meteor/nova:events";
|
2016-06-07 15:03:00 +09:00
|
|
|
|
2015-04-22 07:50:11 +09:00
|
|
|
var toTitleCase = function (str) {
|
|
|
|
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var createPost = function (slug, postedAt, username, thumbnail) {
|
2016-11-07 12:11:02 +09:00
|
|
|
|
|
|
|
const user = Users.findOne({username: username});
|
|
|
|
|
2015-04-22 07:50:11 +09:00
|
|
|
var post = {
|
|
|
|
postedAt: postedAt,
|
|
|
|
body: Assets.getText("content/" + slug + ".md"),
|
|
|
|
title: toTitleCase(slug.replace(/_/g, ' ')),
|
|
|
|
dummySlug: slug,
|
|
|
|
isDummy: true,
|
2016-11-07 12:11:02 +09:00
|
|
|
userId: user._id
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
if (typeof thumbnail !== "undefined")
|
2016-11-10 16:53:06 +01:00
|
|
|
post.thumbnailUrl = "/packages/nova_getting-started/content/images/" + thumbnail;
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2016-11-07 12:11:02 +09:00
|
|
|
newMutation({
|
|
|
|
collection: Posts,
|
|
|
|
document: post,
|
|
|
|
currentUser: user,
|
|
|
|
validate: false
|
|
|
|
});
|
|
|
|
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var createComment = function (slug, username, body, parentBody) {
|
|
|
|
|
2016-11-07 12:11:02 +09:00
|
|
|
const user = Users.findOne({username: username});
|
|
|
|
|
2015-04-22 07:50:11 +09:00
|
|
|
var comment = {
|
|
|
|
postId: Posts.findOne({dummySlug: slug})._id,
|
2016-11-07 12:11:02 +09:00
|
|
|
userId: user._id,
|
2015-04-22 07:50:11 +09:00
|
|
|
body: body,
|
|
|
|
isDummy: true,
|
|
|
|
disableNotifications: true
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
|
|
|
var parentComment = Comments.findOne({body: parentBody});
|
|
|
|
if (parentComment)
|
2015-04-22 07:50:11 +09:00
|
|
|
comment.parentCommentId = parentComment._id;
|
|
|
|
|
2016-11-07 12:11:02 +09:00
|
|
|
newMutation({
|
|
|
|
collection: Comments,
|
|
|
|
document: comment,
|
|
|
|
currentUser: user,
|
|
|
|
validate: false
|
|
|
|
});
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var createDummyUsers = function () {
|
|
|
|
Accounts.createUser({
|
|
|
|
username: 'Bruce',
|
|
|
|
email: 'dummyuser1@telescopeapp.org',
|
|
|
|
profile: {
|
2016-12-02 09:19:41 +01:00
|
|
|
isDummy: true
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Accounts.createUser({
|
|
|
|
username: 'Arnold',
|
|
|
|
email: 'dummyuser2@telescopeapp.org',
|
|
|
|
profile: {
|
2016-12-02 09:19:41 +01:00
|
|
|
isDummy: true
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Accounts.createUser({
|
|
|
|
username: 'Julia',
|
|
|
|
email: 'dummyuser3@telescopeapp.org',
|
|
|
|
profile: {
|
2016-12-02 09:19:41 +01:00
|
|
|
isDummy: true
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
});
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var createDummyPosts = function () {
|
|
|
|
|
|
|
|
createPost("read_this_first", moment().toDate(), "Bruce", "telescope.png");
|
|
|
|
|
2016-04-14 11:09:03 +09:00
|
|
|
createPost("deploying", moment().subtract(10, 'minutes').toDate(), "Arnold");
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2016-04-14 11:09:03 +09:00
|
|
|
createPost("customizing", moment().subtract(3, 'hours').toDate(), "Julia");
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
createPost("getting_help", moment().subtract(1, 'days').toDate(), "Bruce", "stackoverflow.png");
|
|
|
|
|
|
|
|
createPost("removing_getting_started_posts", moment().subtract(2, 'days').toDate(), "Julia");
|
|
|
|
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
var createDummyComments = function () {
|
|
|
|
|
|
|
|
createComment("read_this_first", "Bruce", "What an awesome app!");
|
|
|
|
|
2016-04-14 11:09:03 +09:00
|
|
|
createComment("deploying", "Arnold", "Deploy to da choppah!");
|
|
|
|
createComment("deploying", "Julia", "Do you really need to say this all the time?", "Deploy to da choppah!");
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2016-04-14 11:09:03 +09:00
|
|
|
createComment("customizing", "Julia", "This is really cool!");
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-06-05 11:38:02 +09:00
|
|
|
createComment("removing_getting_started_posts", "Bruce", "Yippee ki-yay!");
|
|
|
|
createComment("removing_getting_started_posts", "Arnold", "I'll be back.", "Yippee ki-yay!");
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2016-11-26 02:46:55 +08:00
|
|
|
var deleteDummyContent = function () {
|
2016-10-05 08:37:48 +02:00
|
|
|
Users.remove({'profile.isDummy': true});
|
2015-04-22 07:50:11 +09:00
|
|
|
Posts.remove({isDummy: true});
|
|
|
|
Comments.remove({isDummy: true});
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
Meteor.methods({
|
|
|
|
addGettingStartedContent: function () {
|
2016-07-21 14:51:58 +09:00
|
|
|
if (Users.isAdmin(Meteor.user())) {
|
2015-04-22 07:50:11 +09:00
|
|
|
createDummyUsers();
|
|
|
|
createDummyPosts();
|
|
|
|
createDummyComments();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeGettingStartedContent: function () {
|
2016-07-21 14:51:58 +09:00
|
|
|
if (Users.isAdmin(Meteor.user()))
|
2015-04-22 07:50:11 +09:00
|
|
|
deleteDummyContent();
|
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
});
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
Meteor.startup(function () {
|
|
|
|
// insert dummy content only if createDummyContent hasn't happened and there aren't any posts in the db
|
2016-02-29 22:13:19 -05:00
|
|
|
if (!Users.find().count() && !Events.findOne({name: 'createDummyContent'}) && !Posts.find().count()) {
|
2015-04-22 07:50:11 +09:00
|
|
|
createDummyUsers();
|
|
|
|
createDummyPosts();
|
|
|
|
createDummyComments();
|
2015-05-06 13:40:01 -04:00
|
|
|
Events.log({name: 'createDummyContent', unique: true, important: true});
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
});
|