-
Notifications
You must be signed in to change notification settings - Fork 0
/
workSchema.js
127 lines (119 loc) · 2.41 KB
/
workSchema.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
SectionContents = new Meteor.Collection("sectionContents", {
idGeneration: 'MONGO',
schema: {
work_id: {
type: Meteor.Collection.ObjectID
},
html: {
type: String
}
}
});
Annotations = new Meteor.Collection("annotations", {
idGeneration: 'MONGO',
schema: {
content_id: {
type: Meteor.Collection.ObjectID,
index: true
},
annotation: {
type: Object,
blackbox: true
}
}
});
Section = new SimpleSchema({
name: {
type: String,
label: "Section name"
},
subSections: {
type: [Object],
label: "Subsections",
custom: function() {
if (this.value.length > 0 && this.field('content').isSet)
return "sectionWithContent";
_.each(this.value, function(section) {
if (!Match.test(this.value, Section))
return "invalidSection";
});
}
},
content_id: {
type: Meteor.Collection.ObjectID,
optional: true
}
});
iterate_content_ids = function(sections, cb) {
for (var i = 0; i < sections.length; i++) {
var section = sections[i];
if (section.content_id) {
var result = cb(section.content_id);
if (result !== undefined) {
return result;
}
}
if (section.subSections) {
var result = iterate_content_ids(section.subSections, cb);
if (result !== undefined) {
return result;
}
}
}
};
Works = new Meteor.Collection("works", {
idGeneration: 'MONGO',
schema: {
title: {
type: String,
label: "Title",
max: 400
},
author: {
type: String,
label: "Author",
max: 200
},
summary: {
type: String,
label: "Summary",
max: 1000
},
year: {
type: Number,
label: "Year of publication"
},
pageViews: {
type: Number,
label: "Number of pageviews",
defaultValue: 0
},
introEssay: {
type: String,
label: "Introductory essay",
optional: true
},
createdAt: {
type: Date,
denyUpdate: true,
autoValue: function(){
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset();
}
}
},
annotationsCount: {
type: Number,
label: "Number of annotations",
defaultValue: 0
},
sections: {
type: [Section],
optional: true
}
}
});