added incoming posts notification button

This commit is contained in:
David Burles 2014-09-15 12:42:17 +10:00
parent d85d65f485
commit d54bd804e4
8 changed files with 58 additions and 8 deletions

View file

@ -67,4 +67,9 @@ UI.registerHelper("sanitize", function(content) {
console.log('cleaning up…')
console.log(content)
return cleanUp(content);
});
UI.registerHelper('pluralize', function(count, string) {
string = count === 1 ? string : string + 's';
return i18n.t(string);
});

View file

@ -11,6 +11,9 @@
{{/if}}
</div>
</div>
{{> postsListIncoming count=postsIncoming.count}}
{{#if hasPosts}}
<div class="posts grid list">
{{#each posts}}

View file

@ -60,3 +60,7 @@ Template[getTemplate('posts_digest')].rendered = function(){
$('body').css('min-height',distanceFromTop+160);
$('.more-button').css('top', distanceFromTop+"px");
}
Template[getTemplate('posts_digest')].created = function() {
Session.set('listPopulatedAt', new Date());
};

View file

@ -1,9 +1,10 @@
<template name="posts_list">
{{> postsListIncoming count=postsListIncoming.count}}
<div class="posts-wrapper grid grid-module">
<div class="posts list">
{{#each posts}}
{{> UI.dynamic template=post_item}}
{{/each}}
<div class="posts list">
{{#each posts}}
{{> UI.dynamic template=post_item}}
{{/each}}
</div>
</div>
{{> UI.dynamic template=postsLoadMore}}

View file

@ -14,5 +14,12 @@ Template[getTemplate('posts_list')].helpers({
},
postsLoadMore: function () {
return getTemplate('postsLoadMore');
},
postsIncoming: function () {
return getTemplate('postsIncoming');
}
});
});
Template[getTemplate('posts_list')].created = function() {
Session.set('listPopulatedAt', new Date());
};

View file

@ -0,0 +1,9 @@
<template name="postsListIncoming">
{{#if count}}
<a class="more-button show-new grid-module" href="">
<span>
{{i18n "View"}} {{count}} {{i18n "new"}} {{pluralize count "post"}}
</span>
</a>
{{/if}}
</template>

View file

@ -0,0 +1,5 @@
Template[getTemplate('postsListIncoming')].events({
'click .show-new': function(e, instance) {
Session.set('listPopulatedAt', new Date());
}
});

View file

@ -308,12 +308,19 @@ PostsListController = FastRender.RouteController.extend({
}
var parameters = getParameters(this._terms),
posts = Posts.find(parameters.find, parameters.options);
postsCount = posts.count();
postsCount = Posts.find(parameters.find, parameters.options).count();
parameters.find.createdAt = { $lte: Session.get('listPopulatedAt') };
var posts = Posts.find(parameters.find, parameters.options);
// Incoming posts
parameters.find.createdAt = { $gt: Session.get('listPopulatedAt') };
var postsIncoming = Posts.find(parameters.find, parameters.options);
Session.set('postsLimit', this._terms.limit);
return {
postsListIncoming: postsIncoming,
postsList: posts,
postsCount: postsCount,
ready: this.postsListSub.ready
@ -366,8 +373,17 @@ PostsDigestController = FastRender.RouteController.extend({
},
parameters = getParameters(terms);
Session.set('currentDate', currentDate);
parameters.find.createdAt = { $lte: Session.get('listPopulatedAt') };
var posts = Posts.find(parameters.find, parameters.options);
// Incoming posts
parameters.find.createdAt = { $gt: Session.get('listPopulatedAt') };
var postsIncoming = Posts.find(parameters.find, parameters.options);
return {
posts: Posts.find(parameters.find, parameters.options)
postsIncoming: postsIncoming,
posts: posts
};
}
});