working on daily view

This commit is contained in:
Sacha Greif 2014-08-27 09:24:37 +09:00
parent 735f0645db
commit 85679ded35
6 changed files with 113 additions and 0 deletions

View file

@ -0,0 +1,40 @@
Meteor.startup(function () {
Router.map(function() {
PostsDailyController = FastRender.RouteController.extend({
template: getTemplate('posts_daily'),
waitOn: function() {
// if number of days is set use that, else default to 3
var days = this.params.days ? this.params.days : 3,
terms = {
view: 'daily',
after: moment().subtract('days', days).startOf('day').toDate()
};
return [
coreSubscriptions.subscribe('postsList', terms),
coreSubscriptions.subscribe('postsListUsers', terms)
];
},
data: function() {
var days = this.params.days ? this.params.days : 3,
terms = {
view: 'daily',
after: moment().subtract('days', days).startOf('day').toDate()
},
parameters = getParameters(terms);
Session.set('currentDate', currentDate);
return {
posts: Posts.find(parameters.find, parameters.options)
};
}
});
this.route('posts_daily', {
path: '/daily/:days?',
controller: PostsDailyController
});
});
});

View file

@ -0,0 +1,12 @@
<template name="postsDaily">
<div class="grid">
{{#each day}}
<div class="posts-day posts list">
<h2 class="posts-day-heading">xyz</h2>
{{#each posts}}
{{> UI.dynamic template=post_item}}
{{/each}}
</div>
{{/each}}
</div>
</template>

View file

@ -0,0 +1,24 @@
Template[getTemplate('postsDaily')].helpers({
post_item: function () {
return getTemplate('post_item');
},
posts : function () {
if(this.postsList){ // XXX
this.postsList.rewind();
var posts = this.postsList.map(function (post, index, cursor) {
post.rank = index;
return post;
});
return posts;
}
},
hasMorePosts: function(){
// as long as we ask for N posts and all N posts showed up, then keep showing the "load more" button
return parseInt(Session.get('postsLimit')) == this.postsCount
},
loadMoreUrl: function () {
var count = parseInt(Session.get('postsLimit')) + parseInt(getSetting('postsPerPage', 10));
var categorySegment = Session.get('categorySlug') ? Session.get('categorySlug') + '/' : '';
return '/' + Session.get('view') + '/' + categorySegment + count;
}
});

View file

@ -0,0 +1,12 @@
viewParameters.daily = function (terms) {
return {
find: {
postedAt: {
$gte: terms.after
}
},
options: {
sort: {createdAt: -1, sticky: -1, baseScore: -1}
}
};
}

View file

@ -0,0 +1,25 @@
Package.describe({summary: "Telescope daily view"});
Package.on_use(function (api) {
api.use(['telescope-lib', 'telescope-base'], ['client', 'server']);
api.use([
'jquery',
'underscore',
'iron-router',
'templating'
], 'client');
api.add_files(['lib/daily.js'], ['client', 'server']);
api.add_files([
'lib/client/routes.js',
'lib/client/templates/posts_daily.html',
'lib/client/templates/posts_daily.js',
], ['client']);
api.add_files(['lib/server/publications.js'], ['server']);
api.export([]);
});