2015-05-13 08:27:59 +03:00
|
|
|
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
2014-09-16 08:55:37 +04:00
|
|
|
import MobileIndexRoute from 'ghost/routes/mobile-index-route';
|
|
|
|
import mobileQuery from 'ghost/utils/mobile';
|
2014-06-13 23:35:22 +04:00
|
|
|
|
2015-05-26 21:24:32 +03:00
|
|
|
var PostsIndexRoute = MobileIndexRoute.extend(AuthenticatedRouteMixin, {
|
2014-09-18 14:20:15 +04:00
|
|
|
noPosts: false,
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-09-16 08:55:37 +04:00
|
|
|
// Transition to a specific post if we're not on mobile
|
2014-06-17 23:17:08 +04:00
|
|
|
beforeModel: function () {
|
2014-09-16 08:55:37 +04:00
|
|
|
if (!mobileQuery.matches) {
|
|
|
|
return this.goToPost();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-09-18 14:20:15 +04:00
|
|
|
setupController: function (controller, model) {
|
|
|
|
/*jshint unused:false*/
|
|
|
|
controller.set('noPosts', this.get('noPosts'));
|
|
|
|
},
|
|
|
|
|
2014-09-16 08:55:37 +04:00
|
|
|
goToPost: function () {
|
2014-07-31 12:29:05 +04:00
|
|
|
var self = this,
|
2014-09-16 08:55:37 +04:00
|
|
|
// the store has been populated by PostsRoute
|
2014-08-01 10:47:29 +04:00
|
|
|
posts = this.store.all('post'),
|
2014-09-10 05:22:11 +04:00
|
|
|
post;
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-04-14 18:04:16 +03:00
|
|
|
return this.get('session.user').then(function (user) {
|
2014-09-10 05:22:11 +04:00
|
|
|
post = posts.find(function (post) {
|
2014-09-16 08:55:37 +04:00
|
|
|
// Authors can only see posts they've written
|
2014-07-31 15:25:40 +04:00
|
|
|
if (user.get('isAuthor')) {
|
|
|
|
return post.isAuthoredByUser(user);
|
2014-07-31 12:29:05 +04:00
|
|
|
}
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-09-16 08:55:37 +04:00
|
|
|
return true;
|
2014-07-31 12:29:05 +04:00
|
|
|
});
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-07-31 15:25:40 +04:00
|
|
|
if (post) {
|
|
|
|
return self.transitionTo('posts.post', post);
|
|
|
|
}
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-09-18 14:20:15 +04:00
|
|
|
self.set('noPosts', true);
|
2014-07-31 15:25:40 +04:00
|
|
|
});
|
2014-09-16 08:55:37 +04:00
|
|
|
},
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Mobile posts route callback
|
2014-09-16 08:55:37 +04:00
|
|
|
desktopTransition: function () {
|
|
|
|
this.goToPost();
|
2014-03-02 18:30:35 +04:00
|
|
|
}
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|
|
|
|
|
2014-07-31 15:25:40 +04:00
|
|
|
export default PostsIndexRoute;
|