summaryrefslogtreecommitdiff
path: root/server/lib/views/staff/middleware.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/views/staff/middleware.js')
-rw-r--r--server/lib/views/staff/middleware.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/server/lib/views/staff/middleware.js b/server/lib/views/staff/middleware.js
index 1ea98e9..03fda2e 100644
--- a/server/lib/views/staff/middleware.js
+++ b/server/lib/views/staff/middleware.js
@@ -6,6 +6,7 @@ var User = require('../../schemas/User'),
Plan = require('../../schemas/Plan'),
Subscription = require('../../schemas/Subscription'),
Layout = require('../../schemas/Layout'),
+ Blueprint = require('../../schemas/Blueprint'),
util = require('../../util'),
fields = require('./fields'),
helpers = require('./helpers'),
@@ -128,6 +129,35 @@ var middleware = module.exports = {
})
},
+ ensureBlueprints: function(req, res, next){
+ var paginationInfo = res.locals.pagination = {}
+ var criteria = req.criteria || {}
+ var limit = paginationInfo.limit = Math.min( Number(req.query.limit) || 50, 200 )
+ var offset = paginationInfo.offset = Number(req.query.offset) || 0
+ var sort
+ paginationInfo.sort = req.query.sort
+ paginationInfo.sortOptions = ["date", "name"]
+ switch (req.query.sort) {
+ default:
+ case 'date':
+ sort = {'updated_at': -1}
+ break
+ case 'name':
+ paginationInfo.sort = "name"
+ sort = {'slug': 1}
+ break
+ }
+ Blueprint.find(criteria)
+ .select(fields.blueprint)
+ .sort(sort)
+ .skip(offset)
+ .limit(limit)
+ .exec(function (err, blueprints) {
+ res.locals.blueprints = blueprints.map(helpers.blueprint)
+ next()
+ })
+ },
+
ensureMedia: function(req, res, next){
var paginationInfo = res.locals.pagination = {}
var criteria = req.criteria || {}
@@ -240,6 +270,11 @@ var middleware = module.exports = {
middleware.ensureObjectsUsers(res.locals.layouts, next)
},
+ ensureBlueprintsUsers: function(req, res, next){
+ if (! res.locals.blueprints || ! res.locals.blueprints.length) { return next() }
+ middleware.ensureObjectsUsers(res.locals.blueprints, next)
+ },
+
ensureSubscriptionsUsers: function(req, res, next){
if (! res.locals.subscriptions || ! res.locals.subscriptions.length) { return next() }
middleware.ensureObjectsUsers(res.locals.subscriptions, next)
@@ -345,6 +380,13 @@ var middleware = module.exports = {
})
},
+ ensureBlueprintsCount: function(req, res, next){
+ Blueprint.count({}, function(err, count){
+ res.locals.blueprintCount = count || 0
+ next()
+ })
+ },
+
ensureMediaCount: function(req, res, next){
Media.count({}, function(err, count){
res.locals.mediaCount = count || 0
@@ -418,4 +460,17 @@ var middleware = module.exports = {
})
},
+ ensureBlueprint: function(req, res, next){
+ res.locals.blueprint = req.blueprint
+ next()
+ },
+ ensureBlueprintUser: function(req, res, next){
+ if (! res.locals.blueprint) { return next() }
+ User.findOne({ _id: res.locals.blueprint.user_id }, fields.user, function(err, user){
+ res.locals.blueprintUser = helpers.user(user) || defaults.user
+ next()
+ })
+ },
+
+
} \ No newline at end of file