working on main posts list subscriptions

This commit is contained in:
Sacha Greif 2013-10-12 11:59:34 +09:00
parent 632ddd5b00
commit e4937a7f38
12 changed files with 89 additions and 43 deletions

View file

@ -25,7 +25,9 @@ canEditComment
hasCompletedProfile
---------------------------------------------------------------
# Subscription Functions #
---------------------------------------------------------------
---------------------------------------------------------------
# Routes #
@ -92,6 +94,10 @@ Router.configure({
//--------------------------------------------- Filters --------------------------------------------//
//--------------------------------------------------------------------------------------------------//
subs = {
}
var filters = {
// isLoggedIn: function(page) {
@ -192,8 +198,40 @@ var filters = {
}
//--------------------------------------------------------------------------------------------------//
//------------------------------------- Subscription Functions -------------------------------------//
//--------------------------------------------------------------------------------------------------//
// Posts Lists
STATUS_PENDING=1;
STATUS_APPROVED=2;
STATUS_REJECTED=3;
var selectTop = function() {
return selectPosts({name: 'top', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
}
var selectNew = function() {
return selectPosts({name: 'new', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
}
var selectBest = function() {
return selectPosts({name: 'best', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
}
var selectPending = function() {
return selectPosts({name: 'pending', status: STATUS_PENDING, slug: Session.get('categorySlug')});
}
// put it all together with pagination
var postListSubscription = function(find, options, per_page) {
var handle = Meteor.subscribeWithPagination('paginatedPosts', find, options, per_page);
handle.fetch = function() {
var ourFind = _.isFunction(find) ? find() : find;
return limitDocuments(Posts.find(ourFind, options), handle.loaded());
}
return handle;
}
//--------------------------------------------------------------------------------------------------//
//--------------------------------------------- Routes ---------------------------------------------//
@ -205,28 +243,43 @@ Router.map(function() {
template: 'posts_top'
});
this.route('posts_top', {path: '/top'});
this.route('posts_new', {path: '/new'});
this.route('posts_best', {path: '/best'});
this.route('posts_pending', {path: '/pending'});
// Top
// TODO
// waitOn: subs.topPostHandle = postListSubscription(selectTop, sortPosts('score'), 10);
this.route('home', {
path: '/',
template:'posts_top',
waitOn: subs.topPostsHandle = postListSubscription(selectTop, sortPosts('score'), 10)
});
this.route('posts_top', {
path: '/top',
waitOn: subs.topPostsHandle = postListSubscription(selectTop, sortPosts('score'), 10)
});
// New
// TODO
this.route('posts_new', {
path: '/new',
waitOn: subs.newPostsHandle = postListSubscription(selectNew, sortPosts('submitted'), 10)
});
// Best
// TODO
this.route('posts_best', {
path: '/best',
waitOn: subs.bestPostsHandle = postListSubscription(selectBest, sortPosts('baseScore'), 10)
});
// Pending
// TODO
this.route('posts_pending', {
path: '/pending',
waitOn: subs.pendingPostsHandle = postListSubscription(selectPending, sortPosts('createdAt'), 10)
});
// Categories

View file

@ -46,10 +46,10 @@ postListSubscription = function(find, options, per_page) {
}
// 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);
// selectTop = function() {
// return selectPosts({name: 'top', status: STATUS_APPROVED, slug: Session.get('categorySlug')});
// }
// topPostsHandle = postListSubscription(selectTop, sortPosts('score'), 10);
selectNew = function() {
return selectPosts({name: 'new', status: STATUS_APPROVED, slug: Session.get('categorySlug')});

View file

@ -0,0 +1,3 @@
<template name="posts_best">
{{> posts_list bestPostsHandle}}
</template>

View file

@ -0,0 +1,3 @@
Template.posts_best.bestPostsHandle = function() {
return subs.bestPostsHandle;
}

View file

@ -11,22 +11,4 @@
{{else}}
<div>Loading... </div>
{{/if}}
</template>
<!-- and the various pages that use the above template -->
<!-- XXX: makes me want to be able to set a context from the router... -->
<template name="posts_top">
{{> posts_list topPostsHandle}}
</template>
<template name="posts_new">
{{> posts_list newPostsHandle}}
</template>
<template name="posts_best">
{{> posts_list bestPostsHandle}}
</template>
<template name="posts_pending">
{{> posts_list pendingPostsHandle}}
</template>

View file

@ -1,16 +1,3 @@
Template.posts_top.topPostsHandle = function() {
return topPostsHandle;
}
Template.posts_new.newPostsHandle = function() {
return newPostsHandle;
}
Template.posts_best.bestPostsHandle = function() {
return bestPostsHandle;
}
Template.posts_pending.pendingPostsHandle = function() {
return pendingPostsHandle;
}
Template.posts_list.helpers({
posts: function() {
return this.fetch();

View file

@ -0,0 +1,3 @@
<template name="posts_new">
{{> posts_list newPostsHandle}}
</template>

View file

@ -0,0 +1,3 @@
Template.posts_new.newPostsHandle = function() {
return subs.newPostsHandle;
}

View file

@ -0,0 +1,3 @@
<template name="posts_pending">
{{> posts_list pendingPostsHandle}}
</template>

View file

@ -0,0 +1,3 @@
Template.posts_pending.pendingPostsHandle = function() {
return subs.pendingPostsHandle;
}

View file

@ -0,0 +1,3 @@
<template name="posts_top">
{{> posts_list topPostsHandle}}
</template>

View file

@ -0,0 +1,3 @@
Template.posts_top.topPostsHandle = function() {
return subs.topPostsHandle;
}