1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/routes/posts/index.js
Kevin Ansfield 604fda4348 Update package.json details, rename module to ghost-admin
no issue
- updates `package.json` details to better reflect the separation from the `Ghost` package
- update ember config and all import statements to reflect the new `ghost-admin` module name in `package.json`
2016-06-03 16:12:54 +01:00

58 lines
1.5 KiB
JavaScript

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import MobileIndexRoute from 'ghost-admin/routes/mobile-index-route';
const {
computed,
inject: {service}
} = Ember;
const {reads} = computed;
export default MobileIndexRoute.extend(AuthenticatedRouteMixin, {
noPosts: false,
mediaQueries: service(),
isMobile: reads('mediaQueries.isMobile'),
// Transition to a specific post if we're not on mobile
beforeModel() {
this._super(...arguments);
if (!this.get('isMobile')) {
return this.goToPost();
}
},
setupController(controller) {
controller.set('noPosts', this.get('noPosts'));
this._super(...arguments);
},
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();
}
});