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