Ghost/ghost/admin/app/controllers/posts.js
Kevin Ansfield a109c1c3db Use Ember.Comparable mixin to sort posts
closes https://github.com/TryGhost/Ghost/issues/7002
- move sorting logic out of the controller and into the Post model

This is a quick attempt at implementing the refactoring referenced in https://github.com/TryGhost/Ghost/issues/7002. The client-side sorting is working but we still have the problem of scheduled posts not appearing in the list until you scroll to the very first published post because the server is returning posts in the wrong order.
2016-06-17 11:33:11 +01:00

30 lines
677 B
JavaScript

import Ember from 'ember';
const {
Controller,
compare,
computed,
inject: {service}
} = Ember;
const {equal} = computed;
export default Controller.extend({
feature: service(),
showDeletePostModal: false,
// See PostsRoute's shortcuts
postListFocused: equal('keyboardFocus', 'postList'),
postContentFocused: equal('keyboardFocus', 'postContent'),
sortedPosts: computed('model.@each.{status,publishedAtUTC,isNew,updatedAtUTC}', function () {
return this.get('model').toArray().sort(compare);
}),
actions: {
toggleDeletePostModal() {
this.toggleProperty('showDeletePostModal');
}
}
});