-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
98 lines (84 loc) · 2.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var _ = require('lodash')
, async = require('async')
, moment = require('moment');
module.exports = {
name: 'apostrophe-blog',
alias: 'blog',
label: 'Article',
extend: 'apostrophe-pieces',
moogBundle: {
modules: ['apostrophe-blog-pages', 'apostrophe-blog-widgets'],
directory: 'lib/modules'
},
beforeConstruct: function(self, options) {
options.sort = { publishedAt: -1 };
options.addFields = [
{
name: 'publishedAt',
label: 'Publication Date',
type: 'date',
required: true
},
].concat(options.addFields || []);
options.arrangeFields = _.merge([
{ name: 'basic', label: 'Basics', fields: ['title', 'slug'] },
{ name: 'meta', label: 'Meta', fields: ['tags','published', 'publishedAt'] }
], options.arrangeFields || []);
options.addColumns = [
{
name: 'publishedAt',
label: 'Publication Date',
}
].concat(options.addColumns || []);
options.addSorts = [
{
name: 'publishedAt',
label: 'By Publication Date',
sort: { startDate: -1 }
}
].concat(options.addSorts || []);
options.addFilters = [
{
name: 'future',
choices: [
{
value: true,
label: 'Future'
},
{
value: false,
label: 'Past'
},
{
value: null,
label: 'Both'
}
],
def: null
}
].concat(options.addFilters || []);
},
construct: function(self, options) {
// limit the results of autocomplete for joins
// so they only include past posts
self.extendAutocompleteCursor = function(cursor) {
return cursor.future(false);
};
// When editing we don't care if the blog post is in the future
var superFindForEditing = self.findForEditing;
self.findForEditing = function(req, criteria, projection) {
return superFindForEditing(req, criteria, projection).future(null);
};
var superNewInstance = self.newInstance;
self.newInstance = function() {
var instance = superNewInstance();
// Correct handling of dynamic default. If you do this in the schema
// you wind up with the day the server launched
if (!instance.publishedAt) {
var now = moment();
instance.publishedAt = now.format('YYYY-MM-DD');
}
return instance;
};
}
};