2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-10-28 17:29:42 +03:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-06-19 23:44:44 +04:00
|
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
2014-07-20 20:42:03 +04:00
|
|
|
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
|
2014-03-02 18:30:35 +04:00
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
export default AuthenticatedRoute.extend(ShortcutsRoute, PaginationRouteMixin, {
|
2014-11-25 23:56:08 +03:00
|
|
|
titleToken: 'Content',
|
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
paginationModel: 'post',
|
|
|
|
paginationSettings: {
|
|
|
|
status: 'all',
|
2015-11-20 12:41:43 +03:00
|
|
|
staticPages: 'all'
|
2015-09-03 14:06:50 +03:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
model() {
|
|
|
|
let paginationSettings = this.get('paginationSettings');
|
2014-07-30 20:44:49 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.get('session.user').then((user) => {
|
2014-07-30 20:44:49 +04:00
|
|
|
if (user.get('isAuthor')) {
|
2015-11-20 12:41:43 +03:00
|
|
|
paginationSettings.filter = paginationSettings.filter ?
|
|
|
|
`${paginationSettings.filter}+author:${user.get('slug')}` : `author:${user.get('slug')}`;
|
2014-07-30 20:44:49 +04:00
|
|
|
}
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.loadFirstPage().then(() => {
|
2015-09-03 14:06:50 +03:00
|
|
|
// using `.filter` allows the template to auto-update when new models are pulled in from the server.
|
|
|
|
// we just need to 'return true' to allow all models by default.
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.store.filter('post', (post) => {
|
2015-09-03 14:06:50 +03:00
|
|
|
if (user.get('isAuthor')) {
|
|
|
|
return post.isAuthoredByUser(user);
|
|
|
|
}
|
2014-07-31 06:44:51 +04:00
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
return true;
|
|
|
|
});
|
2014-07-30 20:44:49 +04:00
|
|
|
});
|
2014-05-24 07:25:20 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
stepThroughPosts(step) {
|
|
|
|
let currentPost = this.get('controller.currentPost');
|
|
|
|
let posts = this.get('controller.sortedPosts');
|
|
|
|
let length = posts.get('length');
|
|
|
|
let newPosition = posts.indexOf(currentPost) + step;
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2014-08-07 17:12:51 +04:00
|
|
|
// if we are on the first or last item
|
|
|
|
// just do nothing (desired behavior is to not
|
|
|
|
// loop around)
|
2014-07-31 06:33:05 +04:00
|
|
|
if (newPosition >= length) {
|
2014-08-07 17:12:51 +04:00
|
|
|
return;
|
|
|
|
} else if (newPosition < 0) {
|
|
|
|
return;
|
2014-07-31 06:33:05 +04:00
|
|
|
}
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-07-31 06:33:05 +04:00
|
|
|
this.transitionTo('posts.post', posts.objectAt(newPosition));
|
|
|
|
},
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
scrollContent(amount) {
|
|
|
|
let content = Ember.$('.js-content-preview');
|
|
|
|
let scrolled = content.scrollTop();
|
2014-10-16 05:56:32 +04:00
|
|
|
|
|
|
|
content.scrollTop(scrolled + 50 * amount);
|
|
|
|
},
|
|
|
|
|
2014-06-19 23:44:44 +04:00
|
|
|
shortcuts: {
|
2014-09-21 20:31:40 +04:00
|
|
|
'up, k': 'moveUp',
|
|
|
|
'down, j': 'moveDown',
|
2014-10-16 05:56:32 +04:00
|
|
|
left: 'focusList',
|
|
|
|
right: 'focusContent',
|
2014-10-25 01:09:50 +04:00
|
|
|
c: 'newPost'
|
2014-06-19 23:44:44 +04:00
|
|
|
},
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-03-02 18:30:35 +04:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
focusList() {
|
2014-10-16 05:56:32 +04:00
|
|
|
this.controller.set('keyboardFocus', 'postList');
|
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
focusContent() {
|
2014-10-16 05:56:32 +04:00
|
|
|
this.controller.set('keyboardFocus', 'postContent');
|
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
newPost() {
|
2014-09-21 20:31:40 +04:00
|
|
|
this.transitionTo('editor.new');
|
|
|
|
},
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
moveUp() {
|
2014-10-16 05:56:32 +04:00
|
|
|
if (this.controller.get('postContentFocused')) {
|
|
|
|
this.scrollContent(-1);
|
|
|
|
} else {
|
|
|
|
this.stepThroughPosts(-1);
|
|
|
|
}
|
2014-06-19 23:44:44 +04:00
|
|
|
},
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
moveDown() {
|
2014-10-16 05:56:32 +04:00
|
|
|
if (this.controller.get('postContentFocused')) {
|
|
|
|
this.scrollContent(1);
|
|
|
|
} else {
|
|
|
|
this.stepThroughPosts(1);
|
|
|
|
}
|
2014-03-02 18:30:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|