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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: 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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: false
|
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,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.admin,
|
|
|
|
editableIf: Users.is.admin,
|
|
|
|
publish: true,
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "datepicker",
|
2016-02-17 11:28:00 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'admin',
|
|
|
|
type: "bootstrap-datetimepicker"
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
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,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.memberOrAdmin,
|
|
|
|
editableIf: Users.is.ownerOrAdmin,
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "text",
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-02-17 11:28:00 +09:00
|
|
|
autoform: {
|
|
|
|
type: "bootstrap-url",
|
|
|
|
order: 10
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
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,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.memberOrAdmin,
|
|
|
|
editableIf: Users.is.ownerOrAdmin,
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "text",
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-02-17 11:28:00 +09:00
|
|
|
autoform: {
|
|
|
|
order: 20
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-06-18 13:04:38 +09:00
|
|
|
/**
|
|
|
|
Slug
|
|
|
|
*/
|
|
|
|
slug: {
|
|
|
|
type: String,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2015-06-18 13:04:38 +09:00
|
|
|
},
|
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,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.memberOrAdmin,
|
|
|
|
editableIf: Users.is.ownerOrAdmin,
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "textarea",
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-02-17 11:28:00 +09:00
|
|
|
autoform: {
|
|
|
|
rows: 5,
|
|
|
|
order: 30
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: 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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: 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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: 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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: 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-22 11:41:12 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.admin,
|
|
|
|
editableIf: Users.is.admin,
|
2016-02-25 21:05:53 +09:00
|
|
|
control: "select",
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2015-09-22 11:41:12 +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);
|
|
|
|
},
|
2016-02-17 11:28:00 +09:00
|
|
|
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,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.admin,
|
|
|
|
editableIf: Users.is.admin,
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "checkbox",
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-02-17 11:28:00 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'admin',
|
|
|
|
leftLabel: "Sticky"
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: false
|
2015-04-22 07:50:11 +09:00
|
|
|
},
|
2015-12-28 11:52:01 -05:00
|
|
|
/**
|
|
|
|
Save info for later spam checking on a post. We will use this for the akismet package
|
|
|
|
*/
|
2015-12-30 15:33:40 +09:00
|
|
|
userIP: {
|
2015-12-28 11:52:01 -05:00
|
|
|
type: String,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: false
|
2015-12-28 11:52:01 -05:00
|
|
|
},
|
2015-12-30 15:33:40 +09:00
|
|
|
userAgent: {
|
2015-12-28 11:52:01 -05:00
|
|
|
type: String,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: false
|
2015-12-28 11:52:01 -05:00
|
|
|
},
|
|
|
|
referrer: {
|
|
|
|
type: String,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: false
|
2015-12-28 11:52:01 -05: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,
|
2016-02-17 11:28:00 +09:00
|
|
|
optional: true,
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: 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,
|
2016-02-28 13:12:36 +09:00
|
|
|
insertableIf: Users.is.admin,
|
|
|
|
editableIf: Users.is.admin,
|
2016-02-25 21:05:53 +09:00
|
|
|
control: "select",
|
2016-02-28 13:12:36 +09:00
|
|
|
publish: true,
|
2016-02-17 11:28:00 +09:00
|
|
|
autoform: {
|
|
|
|
group: 'admin',
|
|
|
|
options: function () {
|
|
|
|
return Meteor.users.find().map(function (user) {
|
|
|
|
return {
|
|
|
|
value: user._id,
|
|
|
|
label: Users.getDisplayName(user)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2016-02-17 19:39:43 +09:00
|
|
|
},
|
|
|
|
join: {
|
|
|
|
joinAs: "user",
|
2016-02-26 13:05:12 +09:00
|
|
|
collection: () => Meteor.users
|
2016-02-17 11:28:00 +09:00
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-27 17:15:16 +09:00
|
|
|
// schema transforms
|
2016-02-14 12:27:20 +09: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);
|