mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
5f7bd12eec
no issue - returns the promise/result from `loadNextPage` so that it's return value can be utilised in closure actions - sets the `isLoading` property in `loadFirstPage` to match `loadNextPage` behaviour - reset the `isLoading` property even if the request fails - adds a `didReceivePaginationMeta` hook so that consumers of the mixin can use the metadata values without having to rely on observers - eg. pulling the `total` into a separate property that can be manipulated when items are added/removed but still reset to the sever's total value the next time a page is loaded - renames the `pagination-route` mixin to simply `pagination` as it's not tied to routes and works equally well in other objects that need to paginate an API resource
101 lines
2.9 KiB
JavaScript
101 lines
2.9 KiB
JavaScript
import Ember from 'ember';
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
|
import PaginationMixin from 'ghost/mixins/pagination';
|
|
|
|
export default AuthenticatedRoute.extend(ShortcutsRoute, PaginationMixin, {
|
|
titleToken: 'Content',
|
|
|
|
paginationModel: 'post',
|
|
paginationSettings: {
|
|
status: 'all',
|
|
staticPages: 'all'
|
|
},
|
|
|
|
model() {
|
|
let paginationSettings = this.get('paginationSettings');
|
|
|
|
return this.get('session.user').then((user) => {
|
|
if (user.get('isAuthor')) {
|
|
paginationSettings.filter = paginationSettings.filter ?
|
|
`${paginationSettings.filter}+author:${user.get('slug')}` : `author:${user.get('slug')}`;
|
|
}
|
|
|
|
return this.loadFirstPage().then(() => {
|
|
// 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.
|
|
return this.store.filter('post', (post) => {
|
|
if (user.get('isAuthor')) {
|
|
return post.isAuthoredByUser(user);
|
|
}
|
|
|
|
return true;
|
|
});
|
|
});
|
|
});
|
|
},
|
|
|
|
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;
|
|
|
|
// if we are on the first or last item
|
|
// just do nothing (desired behavior is to not
|
|
// loop around)
|
|
if (newPosition >= length) {
|
|
return;
|
|
} else if (newPosition < 0) {
|
|
return;
|
|
}
|
|
|
|
this.transitionTo('posts.post', posts.objectAt(newPosition));
|
|
},
|
|
|
|
scrollContent(amount) {
|
|
let content = Ember.$('.js-content-preview');
|
|
let scrolled = content.scrollTop();
|
|
|
|
content.scrollTop(scrolled + 50 * amount);
|
|
},
|
|
|
|
shortcuts: {
|
|
'up, k': 'moveUp',
|
|
'down, j': 'moveDown',
|
|
left: 'focusList',
|
|
right: 'focusContent',
|
|
c: 'newPost'
|
|
},
|
|
|
|
actions: {
|
|
focusList() {
|
|
this.controller.set('keyboardFocus', 'postList');
|
|
},
|
|
|
|
focusContent() {
|
|
this.controller.set('keyboardFocus', 'postContent');
|
|
},
|
|
|
|
newPost() {
|
|
this.transitionTo('editor.new');
|
|
},
|
|
|
|
moveUp() {
|
|
if (this.controller.get('postContentFocused')) {
|
|
this.scrollContent(-1);
|
|
} else {
|
|
this.stepThroughPosts(-1);
|
|
}
|
|
},
|
|
|
|
moveDown() {
|
|
if (this.controller.get('postContentFocused')) {
|
|
this.scrollContent(1);
|
|
} else {
|
|
this.stepThroughPosts(1);
|
|
}
|
|
}
|
|
}
|
|
});
|