From e4937a7f38903aa7612c1d9bdaed95e72d70df10 Mon Sep 17 00:00:00 2001 From: Sacha Greif Date: Sat, 12 Oct 2013 11:59:34 +0900 Subject: [PATCH] working on main posts list subscriptions --- client/helpers/router.js | 69 +++++++++++++++++++++++---- client/main.js | 8 ++-- client/views/posts/posts_best.html | 3 ++ client/views/posts/posts_best.js | 3 ++ client/views/posts/posts_list.html | 18 ------- client/views/posts/posts_list.js | 13 ----- client/views/posts/posts_new.html | 3 ++ client/views/posts/posts_new.js | 3 ++ client/views/posts/posts_pending.html | 3 ++ client/views/posts/posts_pending.js | 3 ++ client/views/posts/posts_top.html | 3 ++ client/views/posts/posts_top.js | 3 ++ 12 files changed, 89 insertions(+), 43 deletions(-) create mode 100644 client/views/posts/posts_best.html create mode 100644 client/views/posts/posts_best.js create mode 100644 client/views/posts/posts_new.html create mode 100644 client/views/posts/posts_new.js create mode 100644 client/views/posts/posts_pending.html create mode 100644 client/views/posts/posts_pending.js create mode 100644 client/views/posts/posts_top.html create mode 100644 client/views/posts/posts_top.js diff --git a/client/helpers/router.js b/client/helpers/router.js index 40d48befa..a233514c2 100644 --- a/client/helpers/router.js +++ b/client/helpers/router.js @@ -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 diff --git a/client/main.js b/client/main.js index 570067887..78ce11fb6 100644 --- a/client/main.js +++ b/client/main.js @@ -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')}); diff --git a/client/views/posts/posts_best.html b/client/views/posts/posts_best.html new file mode 100644 index 000000000..fd0f491f5 --- /dev/null +++ b/client/views/posts/posts_best.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/client/views/posts/posts_best.js b/client/views/posts/posts_best.js new file mode 100644 index 000000000..6f6d92ed0 --- /dev/null +++ b/client/views/posts/posts_best.js @@ -0,0 +1,3 @@ +Template.posts_best.bestPostsHandle = function() { + return subs.bestPostsHandle; +} \ No newline at end of file diff --git a/client/views/posts/posts_list.html b/client/views/posts/posts_list.html index 41467e2b7..89ba1dbbe 100644 --- a/client/views/posts/posts_list.html +++ b/client/views/posts/posts_list.html @@ -11,22 +11,4 @@ {{else}}
Loading...
{{/if}} - - - - - - - - - - - \ No newline at end of file diff --git a/client/views/posts/posts_list.js b/client/views/posts/posts_list.js index 1e5727bc9..571d9637c 100644 --- a/client/views/posts/posts_list.js +++ b/client/views/posts/posts_list.js @@ -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(); diff --git a/client/views/posts/posts_new.html b/client/views/posts/posts_new.html new file mode 100644 index 000000000..ee19d03a3 --- /dev/null +++ b/client/views/posts/posts_new.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/client/views/posts/posts_new.js b/client/views/posts/posts_new.js new file mode 100644 index 000000000..897e24fba --- /dev/null +++ b/client/views/posts/posts_new.js @@ -0,0 +1,3 @@ +Template.posts_new.newPostsHandle = function() { + return subs.newPostsHandle; +} \ No newline at end of file diff --git a/client/views/posts/posts_pending.html b/client/views/posts/posts_pending.html new file mode 100644 index 000000000..b28ac3d48 --- /dev/null +++ b/client/views/posts/posts_pending.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/client/views/posts/posts_pending.js b/client/views/posts/posts_pending.js new file mode 100644 index 000000000..a16960668 --- /dev/null +++ b/client/views/posts/posts_pending.js @@ -0,0 +1,3 @@ +Template.posts_pending.pendingPostsHandle = function() { + return subs.pendingPostsHandle; +} \ No newline at end of file diff --git a/client/views/posts/posts_top.html b/client/views/posts/posts_top.html new file mode 100644 index 000000000..16032ef26 --- /dev/null +++ b/client/views/posts/posts_top.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/client/views/posts/posts_top.js b/client/views/posts/posts_top.js new file mode 100644 index 000000000..e6d26fc8c --- /dev/null +++ b/client/views/posts/posts_top.js @@ -0,0 +1,3 @@ +Template.posts_top.topPostsHandle = function() { + return subs.topPostsHandle; +} \ No newline at end of file