-
Notifications
You must be signed in to change notification settings - Fork 3
/
routes.js
55 lines (50 loc) · 1.29 KB
/
routes.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
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
results: function() {
if(this.params.keywords){
return this.params.keywords;
} else {
return false;
}
}
});
Router.map(function () {
this.route('postsList', {
path: '/',
template: 'posts',
waitOn: function() { return Meteor.subscribe('posts'); },
posts: function() {
return Posts.find({}, {sort: {time: -1}, limit:25})
},
data: function() {
return {
postsCount: Posts.find().count()
}
}
});
this.route('search', {
path: '/search/:keywords',
template: 'results',
waitOn: function() {
// insert keyword split/checking code here?
Meteor.call('search', this.params.keywords, function() {
console.log("Search Run");
});
return Meteor.subscribe('search_results', this.params.keywords);
},
data: function () { // could reduce this to a map function but this is clear
var post_ids = [],
sr = Search_results.findOne({"keywords":this.params.keywords});
if(sr && sr.posts && sr.posts.length > 0 ){
for(var i in sr.posts){
post_ids.push(sr.posts[i]._id);
}
}
return {
keywords: this.params.keywords,
post_ids: post_ids
}
}
});
});