This repository has been archived by the owner on Oct 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fakeServerConfig.js
411 lines (382 loc) · 17.5 KB
/
fakeServerConfig.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
var _ = require('underscore');
module.exports = {
baseApiUrl: process.env.BASE_API_URL,
storageKey: 'fakeServerDataset',
resources: {
article: {
filters: {
title: function(title, query) {
return title.toLowerCase().indexOf(query.toLowerCase()) >= 0;
},
publishDate: function(publishDateString, query) {
var publishDate = new Date(publishDateString);
var queryDate = new Date(query);
queryDate.setHours(0, 0, 0, 0);
publishDate.setHours(0, 0, 0, 0);
return publishDate.getTime() === queryDate.getTime();
},
published: function(published, query) {
return String(published) === query;
},
author: function(author, query) {
return author.id === query;
},
tags: function(tags, query) {
var tagIds = query.split(',');
return _.every(tagIds, function(tagId) {
return _.findWhere(tags, {id: tagId});
});
}
},
validationRules: {
title: {
rule: function(title) {
return title.length > 0;
},
message: 'Please enter title.'
}
},
data: function(random) {
return _.chain(_.range(1, 200)).map(function(index) {
return {
type: 'article',
id: String(index),
attributes: {
title: 'Lorem ipsum dolor sit ament ' + index,
leadTitle: 'Ad veritatis necessitatibus voluptatem aut ' + index,
published: random.boolean(),
publishDate: new Date().toISOString(),
intro: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi. Nam in luctus est. Phasellus nec neque sed ante posuere maximus. Sed nibh nisl, iaculis eget maximus nec, fringilla quis sem. Aenean dictum laoreet sapien, vel consectetur est efficitur sit amet. Vivamus quis libero dolor. Nam purus turpis, aliquet quis arcu a, molestie placerat neque.',
contentRaw: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at turpis sed erat tincidunt iaculis facilisis ac leo. Cras semper, dui in suscipit hendrerit, dui felis molestie elit, bibendum efficitur sapien elit sed magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis purus sagittis velit lacinia dignissim. Maecenas at pellentesque ante, in dignissim ex.</p><ul><li>Sed eget ipsum condimentum sem interdum gravida</li><li>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos</li><li>Praesent sagittis metus et metus mollis rhoncus</li></ul><p>Maecenas imperdiet mollis leo, vitae facilisis ex accumsan a. Vivamus semper viverra nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis aliquet magna nec nibh vehicula molestie. Morbi vestibulum tempor molestie. Nam ante turpis, convallis a ornare nec, pellentesque id nunc. Sed neque felis, auctor et ultrices ac, euismod vel mi. Vivamus in gravida velit, nec convallis dui.</p><p>Proin interdum sagittis sem in elementum. Duis non libero vitae lectus viverra semper. Nunc at eros accumsan, bibendum nisl a, tincidunt nulla. Aliquam vitae nunc scelerisque libero dignissim luctus. Vestibulum iaculis hendrerit ullamcorper. Nullam porttitor risus sed luctus pretium.</p>',
metaTitle: 'Lorem ipsum dolor sit ament ' + index,
metaDiscription: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi. Nam in luctus est. Phasellus nec neque sed ante posuere maximus. Sed nibh nisl, iaculis eget maximus nec, fringilla quis sem. Aenean dictum laoreet sapien, vel consectetur est efficitur sit amet. Vivamus quis libero dolor. Nam purus turpis, aliquet quis arcu a, molestie placerat neque.',
latitude: '48.2206636',
longitude: '16.3100206',
proofreadStatus: '0',
graphicsStatus: '0'
},
relationships: {
author: {data: {id: random.id(1, 5), type: 'user'}},
media: {data: {id: random.id(1, 50), type: 'media'}},
tags: {
data: index % 10 === 0 ? null : [
{id: random.id(1, 5), type: 'tag'},
{id: random.id(6, 10), type: 'tag'},
{id: random.id(1, 10), type: 'tag'}
]
}
}
};
}).value();
}
},
media: {
filters: {
title: function(title, query) {
return title.toLowerCase().indexOf(query.toLowerCase()) >= 0;
},
caption: function(caption, query) {
return caption.toLowerCase().indexOf(query.toLowerCase()) >= 0;
}
},
validationRules: {
title: {
rule: function(title) {
return title.length > 0;
},
message: 'Please enter title.'
}
},
data: function(random) {
return _.chain(_.range(1, 50)).map(function(index) {
return {
type: 'media',
id: String(index),
attributes: {
title: 'Media item ' + index,
caption: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
mediaType: 'image',
thumbnailUrl: 'http://pipsum.com/400x300.jpg?v=' + String(index),
originalUrl: 'http://pipsum.com/1200x900.jpg?v=' + String(index)
}
};
}).value();
}
},
tag: {
filters: {
title: function(title, query) {
return title.toLowerCase().indexOf(query.toLowerCase()) >= 0;
}
},
validationRules: {
title: {
rule: function(title) {
return title.length > 0;
},
message: 'Please enter title.'
}
},
data: function(random) {
return _.chain(_.range(1, 10)).map(function(index) {
return {
type: 'tag',
id: String(index),
attributes: {
title: 'Tag ' + index
}
};
}).value();
}
},
user: {
filters: {
email: function(email, query) {
return email.toLowerCase().indexOf(query.toLowerCase()) >= 0;
}
},
validationRules: {
email: {
rule: function(email) {
return email.length > 0;
},
message: 'Please enter email.'
}
},
data: function(random) {
return _.chain(_.range(1, 5)).map(function(index) {
return {
type: 'user',
id: String(index),
attributes: {
email: 'test.user' + index + '@gmail.com'
},
relationships: {
contactData: {
data: index === 1 ? [
{id: '1', type: 'userContactEntry'},
{id: '2', type: 'userContactEntry'}
] : null
}
}
};
}).value();
}
},
userContactEntry: {
validationRules: {
label: {
rule: function(label) {
return label.length > 0;
},
message: 'Please enter label.'
},
entry: {
rule: function(entry) {
return entry.length > 0;
},
message: 'Please enter entry.'
}
},
data: function(random) {
return [{
type: 'userContactEntry',
id: '1',
attributes: {
label: 'Website',
entry: 'www.example.com',
position: 1
}
}, {
type: 'userContactEntry',
id: '2',
attributes: {
label: 'Telephone',
entry: '099 1000 000',
position: 2
}
}];
}
},
page: {
filters: {
title: function(title, query) {
return title.toLowerCase().indexOf(query.toLowerCase()) >= 0;
},
published: function(published, query) {
return String(published) === query;
},
publishDate: function(publishDateString, query) {
var publishDate = new Date(publishDateString);
var queryDate = new Date(query);
queryDate.setHours(0, 0, 0, 0);
publishDate.setHours(0, 0, 0, 0);
return publishDate.getTime() === queryDate.getTime();
},
author: function(author, query) {
return author.id === query;
},
tags: function(tags, query) {
var tagIds = query.split(',');
return _.every(tagIds, function(tagId) {
return _.findWhere(tags, {id: tagId});
});
}
},
validationRules: {
title: {
rule: function(title) {
return title.length > 0;
},
message: 'Please enter title.'
}
},
data: function(random) {
return _.chain(_.range(1, 150)).map(function(index) {
return {
type: 'page',
id: String(index),
attributes: {
title: 'Page ' + index,
published: random.boolean(),
publishDate: index % 10 === 0 ? null : new Date().toISOString()
},
relationships: {
author: {data: {id: random.id(1, 5), type: 'user'}},
tags: {
data: [
{id: random.id(1, 5), 'type': 'tag'},
{id: random.id(6, 10), 'type': 'tag'}
]
}
}
};
}).value();
}
},
category: {
filters: {
title: function(title, query) {
return title.toLowerCase().indexOf(query.toLowerCase()) >= 0;
},
parentCategory: function(parentCategory, query) {
return parentCategory && parentCategory.id === query;
}
},
validationRules: {
title: {
rule: function(title) {
return title.length > 0;
},
message: 'Please enter title.'
}
},
data: [{ // level 0
type: 'category',
id: '1',
attributes: {
title: 'Category 1',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=1',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=1'
},
relationships: {
parentCategory: {data: null},
childCategories: {data: null}
}
}, {
type: 'category',
id: '2',
attributes: {
title: 'Category 2',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=2',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=2'
},
relationships: {
parentCategory: {data: null},
childCategories: {data: [
{id: '4', type: 'category'},
{id: '5', type: 'category'}
]}
}
}, {
type: 'category',
id: '3',
attributes: {
title: 'Category 3',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=3',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=3'
},
relationships: {
parentCategory: {data: null},
childCategories: {data: [
{id: '6', type: 'category'}
]}
}
}, {
type: 'category',
id: '4',
attributes: {
title: 'Category 4',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=4',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=4'
},
relationships: {
parentCategory: {data: {id: '2', type: 'category'}},
childCategories: {data: null}
}
}, {
type: 'category',
id: '5',
attributes: {
title: 'Category 5',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=5',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=5'
},
relationships: {
parentCategory: {data: {id: '2', type: 'category'}},
childCategories: {data: [
{id: '7', type: 'category'}
]}
}
}, {
type: 'category',
id: '6',
attributes: {
title: 'Category 6',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=6',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=6'
},
relationships: {
parentCategory: {data: {id: '3', type: 'category'}},
childCategories: {data: null}
}
}, {
type: 'category',
id: '7',
attributes: {
title: 'Category 7',
description: 'Aenean gravida, orci in sagittis tincidunt, dolor quam pellentesque dolor, nec viverra neque nunc id mi.',
published: true,
imageThumbnailUrl: 'http://pipsum.com/400x300.jpg?v=7',
imageOriginalUrl: 'http://pipsum.com/1200x900.jpg?v=7'
},
relationships: {
parentCategory: {data: {id: '5', type: 'category'}},
childCategories: {data: null}
}
}]
}
}
};