Vulcan/client/main.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

// Session variables
2012-12-11 10:47:11 +09:00
Session.set('initialLoad', true);
2013-04-06 15:17:09 +09:00
Session.set('currentDate', new Date());
Session.set('categorySlug', null);
2012-12-11 10:47:11 +09:00
2013-10-09 22:16:47 +09:00
// Subscriptions
// note: here we only subscribe to subscriptions that we need to be available all the time.
// For subscriptions depending on specific pages, see the router.
// TODO: add session variable that tracks once all subscriptions here have loaded
// Settings
Meteor.subscribe('settings', function(){
2013-10-09 22:16:47 +09:00
// runs once after settings have loaded
2012-12-11 10:47:11 +09:00
analyticsInit();
2012-11-21 14:31:58 +09:00
Session.set('settingsLoaded',true);
});
// Categories
Meteor.subscribe('categories');
2013-10-09 22:16:47 +09:00
// Current User
// we need to subscribe to the currentUser subscription because by default,
//Meteor doesn't send all the user properties that we need
2012-11-17 13:24:19 +09:00
Meteor.subscribe('currentUser');
// Notifications - only load if user is logged in
if(Meteor.userId() != null){
Meteor.subscribe('notifications');
}
// Posts Lists
2012-10-24 11:04:42 +09:00
STATUS_PENDING=1;
STATUS_APPROVED=2;
STATUS_REJECTED=3;
// put it all together with pagination
2013-04-06 15:17:09 +09:00
postListSubscription = function(find, options, per_page) {
2013-03-23 16:58:28 +11:00
var handle = Meteor.subscribeWithPagination('paginatedPosts', find, options, per_page);
handle.fetch = function() {
2013-04-14 13:00:23 +10:00
var ourFind = _.isFunction(find) ? find() : find;
return limitDocuments(Posts.find(ourFind, options), handle.loaded());
}
return handle;
2012-10-09 12:02:37 +09:00
}
2013-04-07 17:40:32 +09:00
// note: the "name" property is for internal debugging purposes only
// selectTop = function() {
// return selectPosts({name: 'top', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
// }
// topPostsHandle = postListSubscription(selectTop, sortPosts('score'), 10);
selectNew = function() {
2013-04-06 18:39:01 +11:00
return selectPosts({name: 'new', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
}
newPostsHandle = postListSubscription(selectNew, sortPosts('submitted'), 10);
selectBest = function() {
2013-04-06 18:39:01 +11:00
return selectPosts({name: 'best', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
}
bestPostsHandle = postListSubscription(selectBest, sortPosts('baseScore'), 10);
selectPending = function() {
2013-04-06 18:39:01 +11:00
return selectPosts({name: 'pending', status: STATUS_PENDING, slug: Session.get('categorySlug')});
}
2013-04-06 18:39:01 +11:00
pendingPostsHandle = postListSubscription(selectPending, sortPosts('createdAt'), 10);