Vulcan/packages/nova-posts/lib/collection.js

237 lines
4.4 KiB
JavaScript
Raw Normal View History

/**
* 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
*/
_id: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true
},
2015-05-11 11:46:18 +09:00
/**
Timetstamp of post creation
*/
createdAt: {
type: Date,
2016-02-17 11:28:00 +09:00
optional: true,
publish: false
},
2015-05-11 11:46:18 +09:00
/**
Timestamp of post first appearing on the site (i.e. being approved)
*/
postedAt: {
type: Date,
optional: true,
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-05-11 11:46:18 +09:00
/**
URL
*/
url: {
type: String,
optional: true,
max: 500,
insertableIf: Users.is.memberOrAdmin,
editableIf: Users.is.ownerOrAdmin,
2016-02-25 17:44:43 +09:00
control: "text",
publish: true,
2016-02-17 11:28:00 +09:00
autoform: {
type: "bootstrap-url",
order: 10
}
},
2015-05-11 11:46:18 +09:00
/**
Title
*/
title: {
type: String,
optional: false,
max: 500,
insertableIf: Users.is.memberOrAdmin,
editableIf: Users.is.ownerOrAdmin,
2016-02-25 17:44:43 +09:00
control: "text",
publish: true,
2016-02-17 11:28:00 +09:00
autoform: {
order: 20
}
},
2015-06-18 13:04:38 +09:00
/**
Slug
*/
slug: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true,
2015-06-18 13:04:38 +09:00
},
2015-05-11 11:46:18 +09:00
/**
Post body (markdown)
*/
body: {
type: String,
optional: true,
max: 3000,
insertableIf: Users.is.memberOrAdmin,
editableIf: Users.is.ownerOrAdmin,
2016-02-25 17:44:43 +09:00
control: "textarea",
publish: true,
2016-02-17 11:28:00 +09:00
autoform: {
rows: 5,
order: 30
}
},
2015-05-11 11:46:18 +09:00
/**
HTML version of the post body
*/
htmlBody: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true,
},
2015-05-11 11:46:18 +09:00
/**
Count of how many times the post's page was viewed
*/
viewCount: {
type: Number,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true,
},
2015-05-11 11:46:18 +09:00
/**
Timestamp of the last comment
*/
lastCommentedAt: {
type: Date,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true,
},
2015-05-11 11:46:18 +09:00
/**
Count of how many times the post's link was clicked
*/
clickCount: {
type: Number,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true,
},
2015-05-11 11:46:18 +09:00
/**
The post's status. One of pending (`1`), approved (`2`), or deleted (`3`)
*/
status: {
type: Number,
2015-09-22 11:41:12 +09:00
optional: true,
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
2016-02-25 21:05:53 +09:00
control: "select",
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-05-11 11:46:18 +09:00
/**
Whether the post is sticky (pinned to the top of posts lists)
*/
sticky: {
type: Boolean,
optional: true,
defaultValue: false,
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
2016-02-25 17:44:43 +09:00
control: "checkbox",
publish: true,
2016-02-17 11:28:00 +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
*/
inactive: {
type: Boolean,
2016-02-17 11:28:00 +09:00
optional: true,
publish: false
},
/**
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: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: false
},
2015-12-30 15:33:40 +09:00
userAgent: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: false
},
referrer: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: false
},
2015-05-11 11:46:18 +09:00
/**
The post author's name
*/
author: {
type: String,
2016-02-17 11:28:00 +09:00
optional: true,
publish: true,
},
2015-05-11 11:46:18 +09:00
/**
The post author's `_id`.
*/
userId: {
type: String,
optional: true,
// regEx: SimpleSchema.RegEx.Id,
insertableIf: Users.is.admin,
editableIf: Users.is.admin,
2016-02-25 21:05:53 +09:00
control: "select",
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)
};
});
}
},
join: {
joinAs: "user",
2016-02-26 13:05:12 +09:00
collection: () => Meteor.users
2016-02-17 11:28:00 +09:00
}
}
});
// schema transforms
// Meteor.startup(function(){
// // needs to happen after every fields were added
// Posts.internationalize();
// });
/**
* Attach schema to Posts collection
*/
2015-05-11 12:15:10 +09:00
Posts.attachSchema(Posts.schema);