2015-04-22 07:50:11 +09:00
|
|
|
/**
|
|
|
|
* Posts schema
|
|
|
|
* @type {SimpleSchema}
|
|
|
|
*/
|
2015-05-11 12:15:10 +09:00
|
|
|
Posts.schema = new SimpleSchema({
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
ID
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
_id: {
|
|
|
|
type: String,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Timetstamp of post creation
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Timestamp of post first appearing on the site (i.e. being approved)
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
postedAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true,
|
2015-04-27 17:15:16 +09:00
|
|
|
editableBy: ["admin"],
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'admin',
|
|
|
|
type: "bootstrap-datetimepicker"
|
|
|
|
}
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
URL
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2015-07-10 11:05:13 +09:00
|
|
|
max: 500,
|
2015-04-28 17:15:53 +09:00
|
|
|
editableBy: ["member", "admin"],
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
|
|
|
type: "bootstrap-url"
|
|
|
|
}
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Title
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
optional: false,
|
2015-07-10 11:05:13 +09:00
|
|
|
max: 500,
|
2015-04-28 17:15:53 +09:00
|
|
|
editableBy: ["member", "admin"]
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-06-18 13:04:38 +09:00
|
|
|
/**
|
|
|
|
Slug
|
|
|
|
*/
|
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Post body (markdown)
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
body: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2015-07-10 11:05:13 +09:00
|
|
|
max: 3000,
|
2015-04-28 17:15:53 +09:00
|
|
|
editableBy: ["member", "admin"],
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
|
|
|
rows: 5
|
|
|
|
}
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
HTML version of the post body
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
htmlBody: {
|
|
|
|
type: String,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Count of how many times the post's page was viewed
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
viewCount: {
|
|
|
|
type: Number,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Count of the post's comments
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
commentCount: {
|
|
|
|
type: Number,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
An array containing the `_id`s of commenters
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
commenters: {
|
|
|
|
type: [String],
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Timestamp of the last comment
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
lastCommentedAt: {
|
|
|
|
type: Date,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Count of how many times the post's link was clicked
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
clickCount: {
|
|
|
|
type: Number,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The post's base score (not factoring in the post's age)
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
baseScore: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
How many upvotes the post has received
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
upvotes: {
|
|
|
|
type: Number,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
An array containing the `_id`s of the post's upvoters
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
upvoters: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: [String],
|
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
How many downvotes the post has received
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
downvotes: {
|
|
|
|
type: Number,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
An array containing the `_id`s of the post's downvoters
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
downvoters: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: [String],
|
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The post's current score (factoring in age)
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
score: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The post's status. One of pending (`1`), approved (`2`), or deleted (`3`)
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
status: {
|
|
|
|
type: Number,
|
2015-09-06 11:46:42 +09:00
|
|
|
optional: true
|
|
|
|
// editableBy: ["admin"],
|
2015-09-06 11:37:48 +09:00
|
|
|
// autoValue: function () {
|
|
|
|
// // only provide a default value
|
|
|
|
// // 1) this is an insert operation
|
|
|
|
// // 2) status field is not set in the document being inserted
|
|
|
|
// var user = Meteor.users.findOne(this.userId);
|
|
|
|
// if (this.isInsert && !this.isSet)
|
|
|
|
// return Posts.getDefaultStatus(user);
|
|
|
|
// },
|
|
|
|
// autoform: {
|
|
|
|
// noselect: true,
|
|
|
|
// options: Posts.config.postStatuses,
|
|
|
|
// group: 'admin'
|
|
|
|
// }
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Whether the post is sticky (pinned to the top of posts lists)
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
sticky: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
defaultValue: false,
|
2015-04-27 17:15:16 +09:00
|
|
|
editableBy: ["admin"],
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'admin',
|
|
|
|
leftLabel: "Sticky"
|
|
|
|
}
|
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
Whether the post is inactive. Inactive posts see their score recalculated less often
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
inactive: {
|
|
|
|
type: Boolean,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The post author's name
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
author: {
|
|
|
|
type: String,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-05-11 11:46:18 +09:00
|
|
|
/**
|
|
|
|
The post author's `_id`.
|
|
|
|
*/
|
2015-04-22 07:50:11 +09:00
|
|
|
userId: {
|
2015-06-05 10:55:52 +09:00
|
|
|
type: String,
|
2015-04-22 07:50:11 +09:00
|
|
|
optional: true,
|
2015-07-14 11:40:24 +09:00
|
|
|
// regEx: SimpleSchema.RegEx.Id,
|
2015-04-27 17:15:16 +09:00
|
|
|
editableBy: ["admin"],
|
2015-04-22 07:50:11 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'admin',
|
|
|
|
options: function () {
|
|
|
|
return Meteor.users.find().map(function (user) {
|
|
|
|
return {
|
|
|
|
value: user._id,
|
|
|
|
label: Users.getDisplayName(user)
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-27 17:15:16 +09:00
|
|
|
// schema transforms
|
2015-09-02 01:38:31 +02:00
|
|
|
Meteor.startup(function(){
|
|
|
|
// needs to happen after every fields were added
|
|
|
|
Posts.internationalize();
|
|
|
|
});
|
2015-04-27 17:15:16 +09:00
|
|
|
|
2015-04-22 07:50:11 +09:00
|
|
|
/**
|
|
|
|
* Attach schema to Posts collection
|
|
|
|
*/
|
2015-05-11 12:15:10 +09:00
|
|
|
Posts.attachSchema(Posts.schema);
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
Posts.allow({
|
|
|
|
update: _.partial(Telescope.allowCheck, Posts),
|
|
|
|
remove: _.partial(Telescope.allowCheck, Posts)
|
|
|
|
});
|
2015-04-25 13:03:04 +09:00
|
|
|
|