mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Updating controllers to use the api + some minor changes to the api calls
This commit is contained in:
parent
bb6880ea49
commit
58926d1ce4
3 changed files with 13 additions and 31 deletions
|
@ -61,13 +61,13 @@
|
||||||
},
|
},
|
||||||
'editor': function (req, res) {
|
'editor': function (req, res) {
|
||||||
if (req.params.id !== undefined) {
|
if (req.params.id !== undefined) {
|
||||||
api.posts.read(parseInt(req.params.id, 10))
|
api.posts.read({id: parseInt(req.params.id, 10)})
|
||||||
.then(function (post) {
|
.then(function (post) {
|
||||||
res.render('editor', {
|
res.render('editor', {
|
||||||
bodyClass: 'editor',
|
bodyClass: 'editor',
|
||||||
adminNav: setSelected(adminNavbar, 'blog'),
|
adminNav: setSelected(adminNavbar, 'blog'),
|
||||||
title: post.title,
|
title: post.get('title'),
|
||||||
content: post.content
|
content: post.get('content')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
res.render('blog', {
|
res.render('blog', {
|
||||||
bodyClass: 'manage',
|
bodyClass: 'manage',
|
||||||
adminNav: setSelected(adminNavbar, 'blog'),
|
adminNav: setSelected(adminNavbar, 'blog'),
|
||||||
posts: posts
|
posts: posts.toJSON()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,45 +7,27 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Ghost = require('../../ghost'),
|
var Ghost = require('../../ghost'),
|
||||||
_ = require('underscore'),
|
api = require('../../shared/api'),
|
||||||
|
|
||||||
ghost = new Ghost(),
|
ghost = new Ghost(),
|
||||||
frontendControllers;
|
frontendControllers;
|
||||||
|
|
||||||
frontendControllers = {
|
frontendControllers = {
|
||||||
'homepage': function (req, res) {
|
'homepage': function (req, res) {
|
||||||
var featureCount = 0,
|
api.posts.browse().then(function (posts) {
|
||||||
postCount = 0,
|
ghost.doFilter('prePostsRender', posts.toJSON(), function (posts) {
|
||||||
data;
|
res.render('index', {posts: posts, ghostGlobals: ghost.globals()});
|
||||||
|
|
||||||
ghost.dataProvider().posts.findAll(function (error, posts) {
|
|
||||||
data = _.groupBy(posts, function (post) {
|
|
||||||
var group = null;
|
|
||||||
if (post.featured === true && featureCount < ghost.config().homepage.features) {
|
|
||||||
featureCount += 1;
|
|
||||||
group = 'features';
|
|
||||||
} else if (postCount < ghost.config().homepage.posts) {
|
|
||||||
postCount += 1;
|
|
||||||
group = 'posts';
|
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
|
||||||
});
|
|
||||||
|
|
||||||
ghost.doFilter('prepostsRender', data.posts, function (posts) {
|
|
||||||
res.render('index', {features: data.features, posts: posts, ghostGlobals: ghost.globals()});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'single': function (req, res) {
|
'single': function (req, res) {
|
||||||
ghost.dataProvider().posts.findOne({'slug': req.params.slug}, function (error, post) {
|
api.posts.read({'slug': req.params.slug}).then(function (post) {
|
||||||
ghost.doFilter('prePostsRender', post, function (post) {
|
ghost.doFilter('prePostsRender', post.toJSON(), function (post) {
|
||||||
res.render('single', {post: post, ghostGlobals: ghost.globals()});
|
res.render('single', {post: post, ghostGlobals: ghost.globals()});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = frontendControllers;
|
module.exports = frontendControllers;
|
||||||
}());
|
}());
|
|
@ -23,12 +23,12 @@
|
||||||
// takes filter / pagination parameters
|
// takes filter / pagination parameters
|
||||||
// returns a list of posts in a json response
|
// returns a list of posts in a json response
|
||||||
browse: function (options) {
|
browse: function (options) {
|
||||||
return when.call(ghost.dataProvider().posts.findAll);
|
return when.call(ghost.dataProvider().posts.findAll, 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
|
||||||
read: function (id) {
|
read: function (args) {
|
||||||
return when.call(ghost.dataProvider().posts.findOne, {id: id});
|
return when.call(ghost.dataProvider().posts.findOne, args);
|
||||||
},
|
},
|
||||||
// takes a json object with all the properties which should be updated
|
// takes a json object with all the properties which should be updated
|
||||||
// returns the resulting post in a json response
|
// returns the resulting post in a json response
|
||||||
|
|
Loading…
Add table
Reference in a new issue