0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/client/app/routes/posts/index.js
Kevin Ansfield 3d6856614f Use es6 across client and add ember-suave to enforce rules
no issue
- add ember-suave dependency
- upgrade grunt-jscs dependency
- add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc
- separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc
- standardize es6 usage across client
2015-11-30 10:41:01 +00:00

52 lines
1.4 KiB
JavaScript

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import MobileIndexRoute from 'ghost/routes/mobile-index-route';
const {computed, inject} = Ember;
const {reads} = computed;
export default MobileIndexRoute.extend(AuthenticatedRouteMixin, {
noPosts: false,
mediaQueries: inject.service(),
isMobile: reads('mediaQueries.isMobile'),
// Transition to a specific post if we're not on mobile
beforeModel() {
if (!this.get('isMobile')) {
return this.goToPost();
}
},
setupController(controller) {
controller.set('noPosts', this.get('noPosts'));
},
goToPost() {
// the store has been populated by PostsRoute
let posts = this.store.peekAll('post');
let post;
return this.get('session.user').then((user) => {
post = posts.find(function (post) {
// Authors can only see posts they've written
if (user.get('isAuthor')) {
return post.isAuthoredByUser(user);
}
return true;
});
if (post) {
return this.transitionTo('posts.post', post);
}
this.set('noPosts', true);
});
},
// Mobile posts route callback
desktopTransition() {
this.goToPost();
}
});