server half of #83, posts are draft by default, browse shows published by default
This commit is contained in:
parent
983c171fb0
commit
30bd89587f
@ -132,12 +132,12 @@
|
||||
}
|
||||
},
|
||||
'content': function (req, res) {
|
||||
api.posts.browse()
|
||||
.then(function (posts) {
|
||||
api.posts.browse({status: req.params.status || 'all'})
|
||||
.then(function (page) {
|
||||
res.render('content', {
|
||||
bodyClass: 'manage',
|
||||
adminNav: setSelected(adminNavbar, 'content'),
|
||||
posts: posts.toJSON()
|
||||
posts: page.posts
|
||||
});
|
||||
});
|
||||
},
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
frontendControllers = {
|
||||
'homepage': function (req, res) {
|
||||
api.posts.browse().then(function (posts) {
|
||||
ghost.doFilter('prePostsRender', posts.toJSON(), function (posts) {
|
||||
api.posts.browse().then(function (page) {
|
||||
ghost.doFilter('prePostsRender', page.posts, function (posts) {
|
||||
res.render('index', {posts: posts, ghostGlobals: res.locals.ghostGlobals, navItems: res.locals.navItems});
|
||||
});
|
||||
});
|
||||
|
@ -22,9 +22,9 @@
|
||||
// # Posts
|
||||
posts = {
|
||||
// takes filter / pagination parameters
|
||||
// returns a list of posts in a json response
|
||||
// returns a page of posts in a json response
|
||||
browse: function (options) {
|
||||
return dataProvider.Post.findAll(options);
|
||||
return dataProvider.Post.findPage(options);
|
||||
},
|
||||
// takes an identifier (id or slug?)
|
||||
// returns a single post in a json response
|
||||
|
@ -16,6 +16,10 @@
|
||||
|
||||
hasTimestamps: true,
|
||||
|
||||
defaults: {
|
||||
status: 'draft'
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
this.on('creating', this.creating, this);
|
||||
this.on('saving', this.saving, this);
|
||||
@ -69,17 +73,25 @@
|
||||
var postCollection;
|
||||
|
||||
// Allow findPage(n)
|
||||
if (!_.isObject(opts)) {
|
||||
if (_.isString(opts) || _.isNumber(opts)) {
|
||||
opts = {page: opts};
|
||||
}
|
||||
|
||||
opts = _.defaults(opts || {}, {
|
||||
opts = _.extend({
|
||||
page: 1,
|
||||
limit: 15,
|
||||
where: null
|
||||
});
|
||||
where: {},
|
||||
status: 'published'
|
||||
}, opts);
|
||||
|
||||
postCollection = Posts.forge();
|
||||
|
||||
// Unless `all` is passed as an option, filter on
|
||||
// the status provided.
|
||||
if (opts.status !== 'all') {
|
||||
opts.where.status = opts.status;
|
||||
}
|
||||
|
||||
// If there are where conditionals specified, add those
|
||||
// to the query.
|
||||
if (opts.where) {
|
||||
@ -93,7 +105,7 @@
|
||||
return postCollection
|
||||
.query('limit', opts.limit)
|
||||
.query('offset', opts.limit * (opts.page - 1))
|
||||
.fetch(_.omit(opts, 'page', 'limit', 'where'))
|
||||
.fetch(_.omit(opts, 'page', 'limit', 'where', 'status'))
|
||||
.then(function (collection) {
|
||||
var qb;
|
||||
|
||||
|
@ -72,7 +72,7 @@
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it('can add', function (done) {
|
||||
it('can add, defaulting as a draft', function (done) {
|
||||
var newPost = {
|
||||
title: 'Test Title 1',
|
||||
content: 'Test Content 1'
|
||||
@ -81,9 +81,10 @@
|
||||
PostModel.add(newPost).then(function (createdPost) {
|
||||
should.exist(createdPost);
|
||||
|
||||
createdPost.attributes.title.should.equal(newPost.title, "title is correct");
|
||||
createdPost.attributes.content.should.equal(newPost.content, "content is correct");
|
||||
createdPost.attributes.slug.should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct');
|
||||
createdPost.get('status').should.equal('draft');
|
||||
createdPost.get('title').should.equal(newPost.title, "title is correct");
|
||||
createdPost.get('content').should.equal(newPost.content, "content is correct");
|
||||
createdPost.get('slug').should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct');
|
||||
|
||||
done();
|
||||
}).then(null, done);
|
||||
@ -173,6 +174,12 @@
|
||||
|
||||
paginationResult.pages.should.equal(3);
|
||||
|
||||
return PostModel.findPage({limit: 10, page: 2, status: 'all'});
|
||||
|
||||
}).then(function (paginationResult) {
|
||||
|
||||
paginationResult.pages.should.equal(11);
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user