2014-11-17 14:45:23 +09:00
|
|
|
|
// Controller for all posts lists
|
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
|
PostsListController = RouteController.extend({
|
2015-01-18 23:55:39 -08:00
|
|
|
|
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'posts_list',
|
2014-12-11 12:38:53 +09:00
|
|
|
|
|
2015-03-22 09:42:58 +09:00
|
|
|
|
onBeforeAction: function () {
|
2015-03-25 12:30:55 +09:00
|
|
|
|
var showViewsNav = (typeof this.showViewsNav === 'undefined') ? true : this.showViewsNav;
|
|
|
|
|
|
|
|
|
|
if (showViewsNav) {
|
2015-04-13 16:29:33 +09:00
|
|
|
|
this.render('postListTop', {to: 'postListTop'});
|
2015-03-25 12:30:55 +09:00
|
|
|
|
}
|
2015-03-22 09:42:58 +09:00
|
|
|
|
this.next();
|
|
|
|
|
},
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
subscriptions: function () {
|
|
|
|
|
// take the first segment of the path to get the view, unless it's '/' in which case the view default to 'top'
|
|
|
|
|
// note: most of the time this.params.slug will be empty
|
|
|
|
|
this._terms = {
|
|
|
|
|
view: this.view,
|
2015-03-28 18:30:26 +09:00
|
|
|
|
limit: this.params.limit || Settings.get('postsPerPage', 10),
|
2014-11-17 14:45:23 +09:00
|
|
|
|
category: this.params.slug
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(Meteor.isClient) {
|
|
|
|
|
this._terms.query = Session.get("searchQuery");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.postsListSub = coreSubscriptions.subscribe('postsList', this._terms);
|
|
|
|
|
this.postsListUsersSub = coreSubscriptions.subscribe('postsListUsers', this._terms);
|
|
|
|
|
},
|
2014-12-11 12:38:53 +09:00
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
data: function () {
|
|
|
|
|
|
|
|
|
|
if(Meteor.isClient) {
|
|
|
|
|
this._terms.query = Session.get("searchQuery");
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 13:57:37 +09:00
|
|
|
|
var parameters = Posts.getSubParams(this._terms),
|
2015-01-08 15:38:07 +09:00
|
|
|
|
postsCount = Posts.find(parameters.find, parameters.options).count();
|
2014-11-17 14:45:23 +09:00
|
|
|
|
|
|
|
|
|
parameters.find.createdAt = { $lte: Session.get('listPopulatedAt') };
|
|
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
2015-01-18 23:55:39 -08:00
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
// Incoming posts
|
|
|
|
|
parameters.find.createdAt = { $gt: Session.get('listPopulatedAt') };
|
|
|
|
|
var postsIncoming = Posts.find(parameters.find, parameters.options);
|
|
|
|
|
|
|
|
|
|
Session.set('postsLimit', this._terms.limit);
|
|
|
|
|
|
|
|
|
|
return {
|
2015-03-25 12:30:55 +09:00
|
|
|
|
title: this.getTitle(),
|
2014-11-17 14:45:23 +09:00
|
|
|
|
incoming: postsIncoming,
|
2015-01-08 15:38:07 +09:00
|
|
|
|
postsCursor: posts,
|
|
|
|
|
postsCount: postsCount,
|
2015-01-10 11:38:19 +09:00
|
|
|
|
postsReady: this.postsListSub.ready(),
|
2015-01-08 17:07:17 +09:00
|
|
|
|
hasMorePosts: this._terms.limit == postsCount,
|
|
|
|
|
loadMoreHandler: function () {
|
2015-01-19 00:48:17 -08:00
|
|
|
|
|
2015-03-28 18:30:26 +09:00
|
|
|
|
var count = parseInt(Session.get('postsLimit')) + parseInt(Settings.get('postsPerPage', 10));
|
2015-01-08 17:07:17 +09:00
|
|
|
|
var categorySegment = Session.get('categorySlug') ? Session.get('categorySlug') + '/' : '';
|
|
|
|
|
|
2015-01-19 00:48:17 -08:00
|
|
|
|
// TODO: use Router.path here?
|
2015-01-08 17:07:17 +09:00
|
|
|
|
Router.go('/' + Session.get('view') + '/' + categorySegment + count);
|
|
|
|
|
}
|
2014-11-17 14:45:23 +09:00
|
|
|
|
};
|
|
|
|
|
},
|
2014-12-11 12:38:53 +09:00
|
|
|
|
|
|
|
|
|
getTitle: function () {
|
2015-04-01 11:00:31 +09:00
|
|
|
|
return i18n.t(this.view);
|
2014-12-11 12:38:53 +09:00
|
|
|
|
},
|
|
|
|
|
|
2014-12-15 09:46:51 +09:00
|
|
|
|
getDescription: function () {
|
2014-12-17 09:49:56 +09:00
|
|
|
|
if (Router.current().route.getName() == 'posts_default') { // return site description on root path
|
2015-03-28 18:30:26 +09:00
|
|
|
|
return Settings.get('description');
|
2014-12-17 09:49:56 +09:00
|
|
|
|
} else {
|
2015-04-20 13:57:37 +09:00
|
|
|
|
return i18n.t(_.findWhere(Telescope.config.viewsMenu, {label: this.view}).description);
|
2014-12-17 09:49:56 +09:00
|
|
|
|
}
|
2014-12-15 09:46:51 +09:00
|
|
|
|
},
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
onAfterAction: function() {
|
|
|
|
|
Session.set('view', this.view);
|
2014-11-27 17:25:01 +05:30
|
|
|
|
},
|
2014-12-11 12:38:53 +09:00
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
|
fastRender: true
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-02-12 18:57:37 +09:00
|
|
|
|
var getDefaultViewController = function () {
|
2015-03-28 18:30:26 +09:00
|
|
|
|
var defaultView = Settings.get('defaultView', 'top');
|
2015-02-12 18:57:37 +09:00
|
|
|
|
defaultView = defaultView.charAt(0).toUpperCase() + defaultView.slice(1);
|
|
|
|
|
return eval("Posts"+defaultView+"Controller");
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-11 19:15:29 +09:00
|
|
|
|
// wrap in startup block to make sure Settings collection is defined
|
|
|
|
|
Meteor.startup(function () {
|
|
|
|
|
|
2015-02-12 18:57:37 +09:00
|
|
|
|
PostsDefaultController = getDefaultViewController().extend({
|
2015-02-11 19:15:29 +09:00
|
|
|
|
getTitle: function () {
|
2015-03-28 18:30:26 +09:00
|
|
|
|
var title = Settings.get('title', 'Telescope');
|
|
|
|
|
var tagline = Settings.get('tagline');
|
2015-02-11 19:15:29 +09:00
|
|
|
|
var fullTitle = !!tagline ? title + ' – ' + tagline : title ;
|
|
|
|
|
return fullTitle;
|
2015-02-12 18:57:37 +09:00
|
|
|
|
}
|
2015-02-11 19:15:29 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
PostsTopController = PostsListController.extend({
|
2015-02-11 19:15:29 +09:00
|
|
|
|
view: 'top',
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PostsNewController = PostsListController.extend({
|
|
|
|
|
view: 'new'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PostsBestController = PostsListController.extend({
|
|
|
|
|
view: 'best'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
PostsPendingController = PostsListController.extend({
|
|
|
|
|
view: 'pending'
|
|
|
|
|
});
|
|
|
|
|
|
2014-12-08 16:39:10 +09:00
|
|
|
|
PostsScheduledController = PostsListController.extend({
|
|
|
|
|
view: 'scheduled'
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
// Controller for post pages
|
|
|
|
|
|
2014-11-27 17:25:01 +05:30
|
|
|
|
PostPageController = RouteController.extend({
|
2015-01-18 23:55:39 -08:00
|
|
|
|
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'post_page',
|
2014-11-17 14:45:23 +09:00
|
|
|
|
|
|
|
|
|
waitOn: function() {
|
|
|
|
|
this.postSubscription = coreSubscriptions.subscribe('singlePost', this.params._id);
|
|
|
|
|
this.postUsersSubscription = coreSubscriptions.subscribe('postUsers', this.params._id);
|
|
|
|
|
this.commentSubscription = coreSubscriptions.subscribe('postComments', this.params._id);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
post: function() {
|
|
|
|
|
return Posts.findOne(this.params._id);
|
|
|
|
|
},
|
|
|
|
|
|
2014-12-11 12:38:53 +09:00
|
|
|
|
getTitle: function () {
|
2014-12-18 15:09:50 +09:00
|
|
|
|
if (!!this.post())
|
2015-04-01 11:00:31 +09:00
|
|
|
|
return this.post().title;
|
2014-12-11 12:38:53 +09:00
|
|
|
|
},
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
onBeforeAction: function() {
|
|
|
|
|
if (! this.post()) {
|
|
|
|
|
if (this.postSubscription.ready()) {
|
2015-04-13 16:29:33 +09:00
|
|
|
|
this.render('not_found');
|
2014-11-17 14:45:23 +09:00
|
|
|
|
} else {
|
2015-04-13 16:29:33 +09:00
|
|
|
|
this.render('loading');
|
2014-11-17 14:45:23 +09:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.next();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onRun: function() {
|
|
|
|
|
var sessionId = Meteor.default_connection && Meteor.default_connection._lastSessionId ? Meteor.default_connection._lastSessionId : null;
|
|
|
|
|
Meteor.call('increasePostViews', this.params._id, sessionId);
|
2015-01-10 12:46:44 +09:00
|
|
|
|
this.next();
|
2014-11-17 14:45:23 +09:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
data: function() {
|
|
|
|
|
return this.post();
|
2014-11-27 17:25:01 +05:30
|
|
|
|
},
|
|
|
|
|
fastRender: true
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Meteor.startup(function () {
|
|
|
|
|
|
|
|
|
|
Router.route('/', {
|
|
|
|
|
name: 'posts_default',
|
2015-02-11 19:15:29 +09:00
|
|
|
|
controller: PostsDefaultController
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Router.route('/top/:limit?', {
|
|
|
|
|
name: 'posts_top',
|
|
|
|
|
controller: PostsTopController
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// New
|
|
|
|
|
|
|
|
|
|
Router.route('/new/:limit?', {
|
|
|
|
|
name: 'posts_new',
|
|
|
|
|
controller: PostsNewController
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Best
|
|
|
|
|
|
|
|
|
|
Router.route('/best/:limit?', {
|
|
|
|
|
name: 'posts_best',
|
|
|
|
|
controller: PostsBestController
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Pending
|
|
|
|
|
|
|
|
|
|
Router.route('/pending/:limit?', {
|
|
|
|
|
name: 'posts_pending',
|
|
|
|
|
controller: PostsPendingController
|
|
|
|
|
});
|
|
|
|
|
|
2014-12-08 16:39:10 +09:00
|
|
|
|
// Scheduled
|
|
|
|
|
|
|
|
|
|
Router.route('/scheduled/:limit?', {
|
|
|
|
|
name: 'posts_scheduled',
|
|
|
|
|
controller: PostsScheduledController
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-17 14:45:23 +09:00
|
|
|
|
// Post Page
|
|
|
|
|
|
|
|
|
|
Router.route('/posts/:_id', {
|
|
|
|
|
name: 'post_page',
|
|
|
|
|
controller: PostPageController
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Router.route('/posts/:_id/comment/:commentId', {
|
|
|
|
|
name: 'post_page_comment',
|
|
|
|
|
controller: PostPageController,
|
|
|
|
|
onAfterAction: function () {
|
|
|
|
|
// TODO: scroll to comment position
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Post Edit
|
|
|
|
|
|
|
|
|
|
Router.route('/posts/:_id/edit', {
|
|
|
|
|
name: 'post_edit',
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'post_edit',
|
2014-11-17 14:45:23 +09:00
|
|
|
|
waitOn: function () {
|
|
|
|
|
return [
|
|
|
|
|
coreSubscriptions.subscribe('singlePost', this.params._id),
|
|
|
|
|
coreSubscriptions.subscribe('allUsersAdmin')
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
data: function() {
|
|
|
|
|
return {
|
|
|
|
|
postId: this.params._id,
|
|
|
|
|
post: Posts.findOne(this.params._id)
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
fastRender: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Post Submit
|
|
|
|
|
|
|
|
|
|
Router.route('/submit', {
|
|
|
|
|
name: 'post_submit',
|
2015-04-13 16:29:33 +09:00
|
|
|
|
template: 'post_submit',
|
2014-11-18 11:13:16 +09:00
|
|
|
|
waitOn: function () {
|
|
|
|
|
return coreSubscriptions.subscribe('allUsersAdmin');
|
|
|
|
|
}
|
2014-11-17 14:45:23 +09:00
|
|
|
|
});
|
|
|
|
|
|
2015-03-28 18:30:26 +09:00
|
|
|
|
});
|