From 75bd8d99201961f8d4039c6356701247d4f5d9da Mon Sep 17 00:00:00 2001 From: Sacha Greif Date: Mon, 8 Dec 2014 11:15:20 +0900 Subject: [PATCH] extracting digest into its own package --- .meteor/packages | 2 +- .meteor/versions | 1 + client/views/posts/posts_digest.js | 69 ------ i18n/de.i18n.json | 9 - i18n/en.i18n.json | 9 - i18n/es.i18n.json | 8 - i18n/fr.i18n.json | 9 - i18n/it.i18n.json | 9 - i18n/ru.i18n.json | 9 - i18n/tr.i18n.json | 9 - i18n/zh-CN.i18n.json | 8 - lib/helpers.js | 7 - lib/router/posts.js | 56 ----- packages/telescope-base/lib/base.js | 21 +- packages/telescope-blank/package-tap.i18n | 3 +- packages/telescope-blank/package.js | 19 +- packages/telescope-daily/lib/routes.js | 2 - .../lib/server/publications.js | 0 packages/telescope-daily/package.js | 5 +- packages/telescope-daily/versions.json | 4 + packages/telescope-digest/.gitignore | 1 + packages/telescope-digest/i18n/de.i18n.json | 9 + packages/telescope-digest/i18n/en.i18n.json | 9 + packages/telescope-digest/i18n/es.i18n.json | 8 + packages/telescope-digest/i18n/fr.i18n.json | 9 + packages/telescope-digest/i18n/it.i18n.json | 9 + packages/telescope-digest/i18n/tr.i18n.json | 9 + .../telescope-digest/i18n/zh-CN.i18n.json | 8 + .../lib/client/templates}/posts_digest.html | 0 .../lib/client/templates/posts_digest.js | 73 ++++++ packages/telescope-digest/lib/digest.js | 26 ++ packages/telescope-digest/lib/routes.js | 57 +++++ packages/telescope-digest/package-tap.i18n | 5 + packages/telescope-digest/package.js | 84 +++++++ packages/telescope-digest/versions.json | 223 ++++++++++++++++++ 35 files changed, 549 insertions(+), 240 deletions(-) delete mode 100644 client/views/posts/posts_digest.js delete mode 100644 packages/telescope-daily/lib/server/publications.js create mode 100644 packages/telescope-digest/.gitignore create mode 100644 packages/telescope-digest/i18n/de.i18n.json create mode 100644 packages/telescope-digest/i18n/en.i18n.json create mode 100644 packages/telescope-digest/i18n/es.i18n.json create mode 100644 packages/telescope-digest/i18n/fr.i18n.json create mode 100644 packages/telescope-digest/i18n/it.i18n.json create mode 100644 packages/telescope-digest/i18n/tr.i18n.json create mode 100644 packages/telescope-digest/i18n/zh-CN.i18n.json rename {client/views/posts => packages/telescope-digest/lib/client/templates}/posts_digest.html (100%) create mode 100644 packages/telescope-digest/lib/client/templates/posts_digest.js create mode 100644 packages/telescope-digest/lib/digest.js create mode 100644 packages/telescope-digest/lib/routes.js create mode 100644 packages/telescope-digest/package-tap.i18n create mode 100644 packages/telescope-digest/package.js create mode 100644 packages/telescope-digest/versions.json diff --git a/.meteor/packages b/.meteor/packages index da9091c8b..0b3cd196c 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -69,8 +69,8 @@ telescope-newsletter telescope-daily telescope-update-prompt telescope-kadira - telescope-notifications +telescope-digest # Accounts Templates useraccounts:unstyled diff --git a/.meteor/versions b/.meteor/versions index 71824f43d..99fd7749d 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -114,6 +114,7 @@ telescope-api@0.0.0 telescope-base@0.0.0 telescope-daily@0.0.0 telescope-datetimepicker@1.0.3 +telescope-digest@0.1.0 telescope-email@0.2.9 telescope-embedly@0.2.9 telescope-i18n@0.0.0 diff --git a/client/views/posts/posts_digest.js b/client/views/posts/posts_digest.js deleted file mode 100644 index ab305c195..000000000 --- a/client/views/posts/posts_digest.js +++ /dev/null @@ -1,69 +0,0 @@ -Template[getTemplate('posts_digest')].created = function(){ - $(document).unbind('keyup'); //remove any potential existing bindings to avoid duplicates - var currentDate=moment(Session.get('currentDate')).startOf('day'); - var today=moment(new Date()).startOf('day'); - $(document).bind('keyup', 'left', function(){ - Router.go($('.prev-link').attr('href')); - }); - $(document).bind('keyup', 'right', function(){ - if(isAdmin(Meteor.user()) || today.diff(currentDate, 'days') > 0) - Router.go($('.next-link').attr('href')); - }); -}; - -Template[getTemplate('posts_digest')].helpers({ - post_item: function () { - return getTemplate('post_item'); - }, - postsListIncoming: function () { - return getTemplate('postsListIncoming'); - }, - hasPosts: function(){ - if(this.posts) // XXX - return !!this.posts.count(); - }, - currentDate: function(){ - var currentDate=moment(Session.get('currentDate')); - var today=moment(new Date()); - var diff=today.diff(currentDate, 'days'); - if(diff === 0) - return i18n.t("today"); - if(diff === 1) - return i18n.t("yesterday"); - return currentDate.format("dddd, MMMM Do YYYY"); - }, - previousDateURL: function(){ - var currentDate=moment(Session.get('currentDate')); - var newDate=currentDate.subtract(1, 'days'); - return getDigestURL(newDate); - }, - showPreviousDate: function(){ - // TODO - return true; - }, - nextDateURL: function(){ - var currentDate=moment(Session.get('currentDate')); - var newDate=currentDate.add('days', 1); - return getDigestURL(newDate); - }, - showNextDate: function(){ - var currentDate=moment(Session.get('currentDate')).startOf('day'); - var today=moment(new Date()).startOf('day'); - return isAdmin(Meteor.user()) || (today.diff(currentDate, 'days') > 0) - } -}); - -Template[getTemplate('posts_digest')].rendered = function(){ - var distanceFromTop = 0; - $('.post').each(function(){ - distanceFromTop += $(this).height(); - }); - distanceFromTop+=55; - Session.set('distanceFromTop', distanceFromTop); - $('body').css('min-height',distanceFromTop+160); - $('.more-button').css('top', distanceFromTop+"px"); -} - -Template[getTemplate('posts_digest')].created = function() { - Session.set('listPopulatedAt', new Date()); -}; \ No newline at end of file diff --git a/i18n/de.i18n.json b/i18n/de.i18n.json index 9cf33d49b..8b4747308 100644 --- a/i18n/de.i18n.json +++ b/i18n/de.i18n.json @@ -47,15 +47,6 @@ // Post deleted "your_post_has_been_deleted": "Dein Link wurde gelöscht.", - // Post digest - "the_top_5_posts_of_each_day": "Die Top-5-Links eines jeden Tages.", - "previous_day": "Einen Tag zurück", - "next_day": "Einen Tag vor", - "sorry_no_posts_for_today": "Heute gibt es keine Links.", - "sorry_no_posts_for": "Keine Links für", - "today": "Heute", - "yesterday": "Gestern", - // Post submit & edit "created": "Erstellt", "title": "Titel", diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 671dd24ae..250416bb5 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -120,15 +120,6 @@ // Post deleted "your_post_has_been_deleted": "Your post has been deleted.", - // Post digest - "the_top_5_posts_of_each_day": "The top 5 posts of each day.", - "previous_day": "Previous Day", - "next_day": "Next Day", - "sorry_no_posts_for_today": "Sorry, no posts for today", - "sorry_no_posts_for": "Sorry, no posts for", - "today": "Today", - "yesterday": "Yesterday", - // Post submit & edit "created": "Created", "title": "Title", diff --git a/i18n/es.i18n.json b/i18n/es.i18n.json index 1ef3516f9..db9ccf6af 100644 --- a/i18n/es.i18n.json +++ b/i18n/es.i18n.json @@ -48,14 +48,6 @@ // Post deleted "your_post_has_been_deleted": "Tu post ha sido borrado.", - // Post digest - "the_top_5_posts_of_each_day": "Los 5 mejores posts de cada día", - "previous_day": "Dia anterior", - "next_day": "Dia siguiente", - "sorry_no_posts_for_today": "Lo sentimos, no hay post para hoy", - "today": "Hoy", - "yesterday": "Ayer", - // Post submit & edit "created": "Creado", "title": "Título", diff --git a/i18n/fr.i18n.json b/i18n/fr.i18n.json index 9e7302a7b..8ea2d3dfa 100644 --- a/i18n/fr.i18n.json +++ b/i18n/fr.i18n.json @@ -114,15 +114,6 @@ // Post deleted "your_post_has_been_deleted": "Votre post a été supprimé.", - // Post digest - "the_top_5_posts_of_each_day": "5 meilleurs post par jours", - "previous_day": "Jour précédent", - "next_day": "Jour suivant", - "sorry_no_posts_for_today": "Désolé, aucun post aujourd'hui", - "sorry_no_posts_for": "Désolé, aucun post pour", - "today": "Aujourd'hui", - "yesterday": "Hier", - // Post submit & edit "created": "Crée", "title": "Titre", diff --git a/i18n/it.i18n.json b/i18n/it.i18n.json index 711a6c9b1..a9b3407c6 100644 --- a/i18n/it.i18n.json +++ b/i18n/it.i18n.json @@ -47,15 +47,6 @@ // Post deleted "your_post_has_been_deleted": "Il tuo post è stato rimosso.", - // Post digest - "the_top_5_posts_of_each_day": "I 5 migliori post di ogni giorno.", - "previous_day": "Giorno Precedente", - "next_day": "Giorno Successivo", - "sorry_no_posts_for_today": "Ci spiace, non ci sono post per oggi", - "sorry_no_posts_for": "Ci spiace, non ci sono post per", - "today": "Oggi", - "yesterday": "Ieri", - // Post submit & edit "created": "Creato", "title": "Titolo", diff --git a/i18n/ru.i18n.json b/i18n/ru.i18n.json index d08597667..4c0d54062 100644 --- a/i18n/ru.i18n.json +++ b/i18n/ru.i18n.json @@ -49,15 +49,6 @@ // Post deleted "your_post_has_been_deleted": "Your post has been deleted.", - // Post digest - "the_top_5_posts_of_each_day": "The top 5 posts of each day.", - "previous_day": "Previous Day", - "next_day": "Next Day", - "sorry_no_posts_for_today": "Sorry, no posts for today", - "sorry_no_posts_for": "Sorry, no posts for", - "today": "Today", - "yesterday": "Yesterday", - // Post submit & edit "created": "Создан", "title": "Заголовок", diff --git a/i18n/tr.i18n.json b/i18n/tr.i18n.json index a00a312ff..7862923d6 100644 --- a/i18n/tr.i18n.json +++ b/i18n/tr.i18n.json @@ -47,15 +47,6 @@ // Post deleted "your_post_has_been_deleted": "Paylaşımınız silindi", - // Post digest - "the_top_5_posts_of_each_day": "Her günün en üst 5 paylaşımı", - "previous_day": "Önceki gün", - "next_day": "Sonraki gün", - "Sorry, no posts for today": "Özür dileriz, bugün bir paylaşım yok", - "sorry_no_posts_for_today": "Özür dileriz, paylaşım yok", - "today": "Bugün", - "yesterday": "Dün", - // Post submit & edit "created": "Oluşturuldu", "title": "Başlık", diff --git a/i18n/zh-CN.i18n.json b/i18n/zh-CN.i18n.json index 143db4a59..a7b293402 100644 --- a/i18n/zh-CN.i18n.json +++ b/i18n/zh-CN.i18n.json @@ -48,14 +48,6 @@ // Post deleted "your_post_has_been_deleted": "你的帖子已经被删除", - // Post digest - "the_top_5_posts_of_each_day": "每天前5名的帖子", - "previous_day": "前一天", - "next_day": "后一天", - "sorry_no_posts_for_today": "抱歉今天没有新的帖子", - "today": "今天", - "yesterday": "昨天", - // Post submit & edit "created": "创建", "title": "标题", diff --git a/lib/helpers.js b/lib/helpers.js index 7a78f9ccc..69eef93cd 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -23,13 +23,6 @@ getAuthorName = function(item){ scrollPageTo = function(selector){ $('body').scrollTop($(selector).offset().top); }; -getDigestURL = function(moment){ - return Router.routes['posts_digest'].path({ - year: moment.year(), - month: moment.month() + 1, - day: moment.date() - }); -}; getDateRange= function(pageNumber){ var now = moment(new Date()); var dayToDisplay=now.subtract(pageNumber-1, 'days'); diff --git a/lib/router/posts.js b/lib/router/posts.js index a4ed82cb7..efd7d916d 100644 --- a/lib/router/posts.js +++ b/lib/router/posts.js @@ -76,48 +76,6 @@ PostsPendingController = PostsListController.extend({ view: 'pending' }); -// Controller for post digest - -PostsDigestController = RouteController.extend({ - template: getTemplate('posts_digest'), - waitOn: function() { - // if day is set, use that. If not default to today - var currentDate = this.params.day ? new Date(this.params.year, this.params.month-1, this.params.day) : new Date(), - terms = { - view: 'digest', - after: moment(currentDate).startOf('day').toDate(), - before: moment(currentDate).endOf('day').toDate() - }; - return [ - coreSubscriptions.subscribe('postsList', terms), - coreSubscriptions.subscribe('postsListUsers', terms) - ]; - }, - data: function() { - var currentDate = this.params.day ? new Date(this.params.year, this.params.month-1, this.params.day) : Session.get('today'), - terms = { - view: 'digest', - after: moment(currentDate).startOf('day').toDate(), - before: moment(currentDate).endOf('day').toDate() - }, - parameters = getPostsParameters(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 { - incoming: postsIncoming, - posts: posts - }; - }, - fastRender: true -}); - // Controller for post pages PostPageController = RouteController.extend({ @@ -190,20 +148,6 @@ Meteor.startup(function () { controller: PostsPendingController }); - // TODO: enable /category/new, /category/best, etc. views - - // Digest - - Router.route('/digest/:year/:month/:day', { - name: 'posts_digest', - controller: PostsDigestController - }); - - Router.route('/digest', { - name: 'posts_digest_default', - controller: PostsDigestController - }); - // Post Page Router.route('/posts/:_id', { diff --git a/packages/telescope-base/lib/base.js b/packages/telescope-base/lib/base.js index 03c416d93..d2ee2881f 100644 --- a/packages/telescope-base/lib/base.js +++ b/packages/telescope-base/lib/base.js @@ -55,11 +55,7 @@ viewNav = [ { route: 'posts_best', label: 'best' - }, - { - route: 'posts_digest_default', - label: 'digest' - } + } ]; // ------------------------------------- Views -------------------------------- // @@ -99,21 +95,6 @@ viewParameters.pending = function (terms) { }; } -viewParameters.digest = function (terms) { - return { - find: { - postedAt: { - $gte: terms.after, - $lt: terms.before - } - }, - options: { - sort: {sticky: -1, baseScore: -1, limit: 0} - } - }; -} - - heroModules = []; footerModules = []; diff --git a/packages/telescope-blank/package-tap.i18n b/packages/telescope-blank/package-tap.i18n index ba31163c9..a52321d15 100644 --- a/packages/telescope-blank/package-tap.i18n +++ b/packages/telescope-blank/package-tap.i18n @@ -1,4 +1,5 @@ { "translation_function_name": "__", - "helper_name": "_" + "helper_name": "_", + "namespace": "project" } \ No newline at end of file diff --git a/packages/telescope-blank/package.js b/packages/telescope-blank/package.js index 8a362d87c..6d56dd349 100644 --- a/packages/telescope-blank/package.js +++ b/packages/telescope-blank/package.js @@ -15,22 +15,19 @@ Package.onUse(function (api) { // automatic (let the package specify where it's needed) api.use([ - 'telescope-base', - 'telescope-lib', - 'telescope-i18n', - 'tap:i18n' + 'tap:i18n', // internationalization package + 'iron:router', // routing package + 'telescope-base', // basic Telescope hooks and objects + 'telescope-lib', // useful functions + 'telescope-i18n' // internationalization wrapper ]); - // both - - api.use([ - // - ], ['client','server']); - // client api.use([ - // + 'jquery', // useful for DOM interactions + 'underscore', // JavaScript swiss army knife library + 'templating' // required for client-side templates ], ['client']); // server diff --git a/packages/telescope-daily/lib/routes.js b/packages/telescope-daily/lib/routes.js index a07db663b..37d98a019 100644 --- a/packages/telescope-daily/lib/routes.js +++ b/packages/telescope-daily/lib/routes.js @@ -7,8 +7,6 @@ var coreSubscriptions = new SubsManager({ expireIn: 30 }); -// note: FastRender not defined here? - PostsDailyController = RouteController.extend({ template: function() { return getTemplate('postsDaily'); diff --git a/packages/telescope-daily/lib/server/publications.js b/packages/telescope-daily/lib/server/publications.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/telescope-daily/package.js b/packages/telescope-daily/package.js index 36a795d5d..3014bf546 100644 --- a/packages/telescope-daily/package.js +++ b/packages/telescope-daily/package.js @@ -8,7 +8,8 @@ Package.onUse(function (api) { 'iron:router', 'meteorhacks:fast-render', 'meteorhacks:subs-manager', - 'tap:i18n' + 'tap:i18n', + 'telescope-digest' ], ['client', 'server']); api.use([ @@ -29,8 +30,6 @@ Package.onUse(function (api) { 'lib/client/stylesheets/daily.css', ], ['client']); - api.add_files(['lib/server/publications.js'], ['server']); - api.add_files([ "i18n/de.i18n.json", "i18n/en.i18n.json", diff --git a/packages/telescope-daily/versions.json b/packages/telescope-daily/versions.json index c29f94db5..5146443c7 100644 --- a/packages/telescope-daily/versions.json +++ b/packages/telescope-daily/versions.json @@ -212,6 +212,10 @@ "telescope-base", "0.0.0" ], + [ + "telescope-digest", + "0.1.0" + ], [ "telescope-i18n", "0.0.0" diff --git a/packages/telescope-digest/.gitignore b/packages/telescope-digest/.gitignore new file mode 100644 index 000000000..677a6fc26 --- /dev/null +++ b/packages/telescope-digest/.gitignore @@ -0,0 +1 @@ +.build* diff --git a/packages/telescope-digest/i18n/de.i18n.json b/packages/telescope-digest/i18n/de.i18n.json new file mode 100644 index 000000000..281eb5acd --- /dev/null +++ b/packages/telescope-digest/i18n/de.i18n.json @@ -0,0 +1,9 @@ +{ + "the_top_5_posts_of_each_day": "Die Top-5-Links eines jeden Tages.", + "previous_day": "Einen Tag zurück", + "next_day": "Einen Tag vor", + "sorry_no_posts_for_today": "Heute gibt es keine Links.", + "sorry_no_posts_for": "Keine Links für", + "today": "Heute", + "yesterday": "Gestern" +} \ No newline at end of file diff --git a/packages/telescope-digest/i18n/en.i18n.json b/packages/telescope-digest/i18n/en.i18n.json new file mode 100644 index 000000000..f8f2f4b89 --- /dev/null +++ b/packages/telescope-digest/i18n/en.i18n.json @@ -0,0 +1,9 @@ +{ + "the_top_5_posts_of_each_day": "The top 5 posts of each day.", + "previous_day": "Previous Day", + "next_day": "Next Day", + "sorry_no_posts_for_today": "Sorry, no posts for today", + "sorry_no_posts_for": "Sorry, no posts for", + "today": "Today", + "yesterday": "Yesterday" +} \ No newline at end of file diff --git a/packages/telescope-digest/i18n/es.i18n.json b/packages/telescope-digest/i18n/es.i18n.json new file mode 100644 index 000000000..02bd8b781 --- /dev/null +++ b/packages/telescope-digest/i18n/es.i18n.json @@ -0,0 +1,8 @@ +{ + "the_top_5_posts_of_each_day": "Los 5 mejores posts de cada día", + "previous_day": "Dia anterior", + "next_day": "Dia siguiente", + "sorry_no_posts_for_today": "Lo sentimos, no hay post para hoy", + "today": "Hoy", + "yesterday": "Ayer" +} \ No newline at end of file diff --git a/packages/telescope-digest/i18n/fr.i18n.json b/packages/telescope-digest/i18n/fr.i18n.json new file mode 100644 index 000000000..969c73a05 --- /dev/null +++ b/packages/telescope-digest/i18n/fr.i18n.json @@ -0,0 +1,9 @@ +{ + "the_top_5_posts_of_each_day": "5 meilleurs post par jours", + "previous_day": "Jour précédent", + "next_day": "Jour suivant", + "sorry_no_posts_for_today": "Désolé, aucun post aujourd'hui", + "sorry_no_posts_for": "Désolé, aucun post pour", + "today": "Aujourd'hui", + "yesterday": "Hier" +} \ No newline at end of file diff --git a/packages/telescope-digest/i18n/it.i18n.json b/packages/telescope-digest/i18n/it.i18n.json new file mode 100644 index 000000000..80b15bcbb --- /dev/null +++ b/packages/telescope-digest/i18n/it.i18n.json @@ -0,0 +1,9 @@ +{ + "the_top_5_posts_of_each_day": "I 5 migliori post di ogni giorno.", + "previous_day": "Giorno Precedente", + "next_day": "Giorno Successivo", + "sorry_no_posts_for_today": "Ci spiace, non ci sono post per oggi", + "sorry_no_posts_for": "Ci spiace, non ci sono post per", + "today": "Oggi", + "yesterday": "Ieri" +} \ No newline at end of file diff --git a/packages/telescope-digest/i18n/tr.i18n.json b/packages/telescope-digest/i18n/tr.i18n.json new file mode 100644 index 000000000..a43273b77 --- /dev/null +++ b/packages/telescope-digest/i18n/tr.i18n.json @@ -0,0 +1,9 @@ +{ + "the_top_5_posts_of_each_day": "Her günün en üst 5 paylaşımı", + "previous_day": "Önceki gün", + "next_day": "Sonraki gün", + "Sorry, no posts for today": "Özür dileriz, bugün bir paylaşım yok", + "sorry_no_posts_for_today": "Özür dileriz, paylaşım yok", + "today": "Bugün", + "yesterday": "Dün" +} \ No newline at end of file diff --git a/packages/telescope-digest/i18n/zh-CN.i18n.json b/packages/telescope-digest/i18n/zh-CN.i18n.json new file mode 100644 index 000000000..c15ffa04b --- /dev/null +++ b/packages/telescope-digest/i18n/zh-CN.i18n.json @@ -0,0 +1,8 @@ +{ + "the_top_5_posts_of_each_day": "每天前5名的帖子", + "previous_day": "前一天", + "next_day": "后一天", + "sorry_no_posts_for_today": "抱歉今天没有新的帖子", + "today": "今天", + "yesterday": "昨天" +} \ No newline at end of file diff --git a/client/views/posts/posts_digest.html b/packages/telescope-digest/lib/client/templates/posts_digest.html similarity index 100% rename from client/views/posts/posts_digest.html rename to packages/telescope-digest/lib/client/templates/posts_digest.html diff --git a/packages/telescope-digest/lib/client/templates/posts_digest.js b/packages/telescope-digest/lib/client/templates/posts_digest.js new file mode 100644 index 000000000..a346a45b1 --- /dev/null +++ b/packages/telescope-digest/lib/client/templates/posts_digest.js @@ -0,0 +1,73 @@ +Meteor.startup(function () { + + Template[getTemplate('posts_digest')].created = function(){ + $(document).unbind('keyup'); //remove any potential existing bindings to avoid duplicates + var currentDate=moment(Session.get('currentDate')).startOf('day'); + var today=moment(new Date()).startOf('day'); + $(document).bind('keyup', 'left', function(){ + Router.go($('.prev-link').attr('href')); + }); + $(document).bind('keyup', 'right', function(){ + if(isAdmin(Meteor.user()) || today.diff(currentDate, 'days') > 0) + Router.go($('.next-link').attr('href')); + }); + }; + + Template[getTemplate('posts_digest')].helpers({ + post_item: function () { + return getTemplate('post_item'); + }, + postsListIncoming: function () { + return getTemplate('postsListIncoming'); + }, + hasPosts: function(){ + if(this.posts) // XXX + return !!this.posts.count(); + }, + currentDate: function(){ + var currentDate=moment(Session.get('currentDate')); + var today=moment(new Date()); + var diff=today.diff(currentDate, 'days'); + if(diff === 0) + return i18n.t("today"); + if(diff === 1) + return i18n.t("yesterday"); + return currentDate.format("dddd, MMMM Do YYYY"); + }, + previousDateURL: function(){ + var currentDate=moment(Session.get('currentDate')); + var newDate=currentDate.subtract(1, 'days'); + return getDigestURL(newDate); + }, + showPreviousDate: function(){ + // TODO + return true; + }, + nextDateURL: function(){ + var currentDate=moment(Session.get('currentDate')); + var newDate=currentDate.add('days', 1); + return getDigestURL(newDate); + }, + showNextDate: function(){ + var currentDate=moment(Session.get('currentDate')).startOf('day'); + var today=moment(new Date()).startOf('day'); + return isAdmin(Meteor.user()) || (today.diff(currentDate, 'days') > 0) + } + }); + + Template[getTemplate('posts_digest')].rendered = function(){ + var distanceFromTop = 0; + $('.post').each(function(){ + distanceFromTop += $(this).height(); + }); + distanceFromTop+=55; + Session.set('distanceFromTop', distanceFromTop); + $('body').css('min-height',distanceFromTop+160); + $('.more-button').css('top', distanceFromTop+"px"); + } + + Template[getTemplate('posts_digest')].created = function() { + Session.set('listPopulatedAt', new Date()); + }; + +}); \ No newline at end of file diff --git a/packages/telescope-digest/lib/digest.js b/packages/telescope-digest/lib/digest.js new file mode 100644 index 000000000..248321258 --- /dev/null +++ b/packages/telescope-digest/lib/digest.js @@ -0,0 +1,26 @@ +viewNav.push({ + route: 'posts_digest_default', + label: 'digest' +}); + +viewParameters.digest = function (terms) { + return { + find: { + postedAt: { + $gte: terms.after, + $lt: terms.before + } + }, + options: { + sort: {sticky: -1, baseScore: -1, limit: 0} + } + }; +} + +getDigestURL = function(moment){ + return Router.routes['posts_digest'].path({ + year: moment.year(), + month: moment.month() + 1, + day: moment.date() + }); +}; \ No newline at end of file diff --git a/packages/telescope-digest/lib/routes.js b/packages/telescope-digest/lib/routes.js new file mode 100644 index 000000000..e281e5eb2 --- /dev/null +++ b/packages/telescope-digest/lib/routes.js @@ -0,0 +1,57 @@ +// Controller for post digest + +PostsDigestController = RouteController.extend({ + template: getTemplate('posts_digest'), + waitOn: function() { + // if day is set, use that. If not default to today + var currentDate = this.params.day ? new Date(this.params.year, this.params.month-1, this.params.day) : new Date(), + terms = { + view: 'digest', + after: moment(currentDate).startOf('day').toDate(), + before: moment(currentDate).endOf('day').toDate() + }; + return [ + coreSubscriptions.subscribe('postsList', terms), + coreSubscriptions.subscribe('postsListUsers', terms) + ]; + }, + data: function() { + var currentDate = this.params.day ? new Date(this.params.year, this.params.month-1, this.params.day) : Session.get('today'), + terms = { + view: 'digest', + after: moment(currentDate).startOf('day').toDate(), + before: moment(currentDate).endOf('day').toDate() + }, + parameters = getPostsParameters(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 { + incoming: postsIncoming, + posts: posts + }; + }, + fastRender: true +}); + +Meteor.startup(function () { + + // Digest + + Router.route('/digest/:year/:month/:day', { + name: 'posts_digest', + controller: PostsDigestController + }); + + Router.route('/digest', { + name: 'posts_digest_default', + controller: PostsDigestController + }); + +}); \ No newline at end of file diff --git a/packages/telescope-digest/package-tap.i18n b/packages/telescope-digest/package-tap.i18n new file mode 100644 index 000000000..a52321d15 --- /dev/null +++ b/packages/telescope-digest/package-tap.i18n @@ -0,0 +1,5 @@ +{ + "translation_function_name": "__", + "helper_name": "_", + "namespace": "project" +} \ No newline at end of file diff --git a/packages/telescope-digest/package.js b/packages/telescope-digest/package.js new file mode 100644 index 000000000..1aa3eca16 --- /dev/null +++ b/packages/telescope-digest/package.js @@ -0,0 +1,84 @@ +Package.describe({ + summary: 'Telescope digest package', + version: '0.1.0', + name: 'telescope-digest' +}); + +Npm.depends({ + // NPM package dependencies +}); + +Package.onUse(function (api) { + + // --------------------------- 1. Meteor packages dependencies --------------------------- + + // automatic (let the package specify where it's needed) + + api.use([ + 'telescope-base', + 'telescope-lib', + 'telescope-i18n', + 'tap:i18n', + 'iron:router' + ]); + + // client + + api.use([ + 'jquery', + 'underscore', + 'templating' + ], ['client']); + + // server + + api.use([ + // + ], ['server']); + + // ---------------------------------- 2. Files to include ---------------------------------- + + // i18n config (must come first) + + api.add_files([ + 'package-tap.i18n' + ], ['client', 'server']); + + // both + + api.add_files([ + 'lib/routes.js', + 'lib/digest.js' + ], ['client', 'server']); + + // client + + api.add_files([ + 'lib/client/templates/posts_digest.html', + 'lib/client/templates/posts_digest.js' + ], ['client']); + + // server + + api.add_files([ + ], ['server']); + + // i18n languages (must come last) + + api.add_files([ + 'i18n/de.i18n.json', + 'i18n/en.i18n.json', + 'i18n/es.i18n.json', + 'i18n/fr.i18n.json', + 'i18n/it.i18n.json', + 'i18n/tr.i18n.json', + 'i18n/zh-CN.i18n.json' + ], ['client', 'server']); + + // -------------------------------- 3. Variables to export -------------------------------- + + api.export([ + 'getDigestURL' + ]); + +}); \ No newline at end of file diff --git a/packages/telescope-digest/versions.json b/packages/telescope-digest/versions.json new file mode 100644 index 000000000..3e7ba6fdb --- /dev/null +++ b/packages/telescope-digest/versions.json @@ -0,0 +1,223 @@ +{ + "dependencies": [ + [ + "aldeed:simple-schema", + "1.1.0" + ], + [ + "application-configuration", + "1.0.3" + ], + [ + "base64", + "1.0.1" + ], + [ + "binary-heap", + "1.0.1" + ], + [ + "blaze", + "2.0.3" + ], + [ + "blaze-tools", + "1.0.1" + ], + [ + "boilerplate-generator", + "1.0.1" + ], + [ + "callback-hook", + "1.0.1" + ], + [ + "check", + "1.0.2" + ], + [ + "coffeescript", + "1.0.4" + ], + [ + "ddp", + "1.0.11" + ], + [ + "deps", + "1.0.5" + ], + [ + "ejson", + "1.0.4" + ], + [ + "follower-livedata", + "1.0.2" + ], + [ + "geojson-utils", + "1.0.1" + ], + [ + "html-tools", + "1.0.2" + ], + [ + "htmljs", + "1.0.2" + ], + [ + "id-map", + "1.0.1" + ], + [ + "iron:controller", + "1.0.0" + ], + [ + "iron:core", + "1.0.3" + ], + [ + "iron:dynamic-template", + "1.0.3" + ], + [ + "iron:layout", + "1.0.3" + ], + [ + "iron:location", + "1.0.3" + ], + [ + "iron:middleware-stack", + "1.0.0" + ], + [ + "iron:router", + "1.0.1" + ], + [ + "iron:url", + "1.0.3" + ], + [ + "jquery", + "1.0.1" + ], + [ + "json", + "1.0.1" + ], + [ + "logging", + "1.0.5" + ], + [ + "meteor", + "1.1.3" + ], + [ + "minifiers", + "1.1.2" + ], + [ + "minimongo", + "1.0.5" + ], + [ + "mongo", + "1.0.8" + ], + [ + "observe-sequence", + "1.0.3" + ], + [ + "ordered-dict", + "1.0.1" + ], + [ + "random", + "1.0.1" + ], + [ + "reactive-dict", + "1.0.4" + ], + [ + "reactive-var", + "1.0.3" + ], + [ + "retry", + "1.0.1" + ], + [ + "routepolicy", + "1.0.2" + ], + [ + "session", + "1.0.4" + ], + [ + "spacebars", + "1.0.3" + ], + [ + "spacebars-compiler", + "1.0.3" + ], + [ + "tap:http-methods", + "0.0.23" + ], + [ + "tap:i18n", + "1.2.1" + ], + [ + "telescope-base", + "0.0.0" + ], + [ + "telescope-i18n", + "0.0.0" + ], + [ + "telescope-lib", + "0.2.9" + ], + [ + "templating", + "1.0.9" + ], + [ + "tracker", + "1.0.3" + ], + [ + "ui", + "1.0.4" + ], + [ + "underscore", + "1.0.1" + ], + [ + "webapp", + "1.1.4" + ], + [ + "webapp-hashing", + "1.0.1" + ] + ], + "pluginDependencies": [], + "toolVersion": "meteor-tool@1.0.35", + "format": "1.0" +} \ No newline at end of file