summaryrefslogtreecommitdiff
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/middleware.js23
-rw-r--r--server/lib/views/staff/fields.js3
-rw-r--r--server/lib/views/staff/helpers.js7
-rw-r--r--server/lib/views/staff/index.js53
-rw-r--r--server/lib/views/staff/middleware.js55
5 files changed, 136 insertions, 5 deletions
diff --git a/server/lib/middleware.js b/server/lib/middleware.js
index 04cb330..0a0a9ce 100644
--- a/server/lib/middleware.js
+++ b/server/lib/middleware.js
@@ -8,6 +8,7 @@ var passport = require('passport'),
Collaborator = require('./schemas/Collaborator'),
Project = require('./schemas/Project'),
Layout = require('./schemas/Layout'),
+ Blueprint = require('./schemas/Blueprint'),
Plan = require('./schemas/Plan');
@@ -129,6 +130,28 @@ var middleware = {
}
},
+ ensureBlueprint: function (req, res, next) {
+ if (req.params.slug) {
+ Blueprint.findOne({ slug: req.params.slug }, function(err, blueprint){
+ if (err) {
+ console.error(err)
+ req.blueprint = null
+ }
+ else if (! blueprint) {
+ req.blueprint = null
+ }
+ else {
+ req.blueprint = blueprint
+ }
+ next()
+ })
+ }
+ else {
+ req.blueprint = null
+ next()
+ }
+ },
+
ensureIsCollaborator: function(req, res, next) {
req.isCollaborator = false
req.isOwner = false
diff --git a/server/lib/views/staff/fields.js b/server/lib/views/staff/fields.js
index 57eea7e..84c1efa 100644
--- a/server/lib/views/staff/fields.js
+++ b/server/lib/views/staff/fields.js
@@ -1,7 +1,8 @@
module.exports = {
user: "_id username displayName photo created_at updated_at last_seen created_ip last_ip",
project: "_id name slug user_id privacy layout_type created_at updated_at",
- layout: "_id name slug user_id layout_type created_at updated_at",
+ layout: "_id name slug user_id layout_type is_stock created_at updated_at",
+ blueprint: "_id name slug user_id created_at updated_at",
plans: "monthly_price yearly_price basic_layout_monthly_price basic_layout_yearly_price " +
"pro_layout_monthly_price pro_layout_yearly_price " +
"basic_layout_limit pro_layout_limit stock_project_limit basic_project_limit pro_project_limit",
diff --git a/server/lib/views/staff/helpers.js b/server/lib/views/staff/helpers.js
index 57383f4..ff4065a 100644
--- a/server/lib/views/staff/helpers.js
+++ b/server/lib/views/staff/helpers.js
@@ -27,6 +27,13 @@ module.exports = {
layout.user = {}
return layout
},
+
+ blueprint: function(blueprint){
+ blueprint = blueprint.toObject()
+ blueprint.date = moment( blueprint.updated_at || blueprint.created_at ).format("M/DD/YYYY hh:mm a")
+ blueprint.user = {}
+ return blueprint
+ },
media: function(media){
media = media.toObject()
diff --git a/server/lib/views/staff/index.js b/server/lib/views/staff/index.js
index 033fc88..49a0384 100644
--- a/server/lib/views/staff/index.js
+++ b/server/lib/views/staff/index.js
@@ -7,6 +7,7 @@ var User = require('../../schemas/User'),
Plan = require('../../schemas/Plan'),
Subscription = require('../../schemas/Subscription'),
Layout = require('../../schemas/Layout'),
+ Blueprint = require('../../schemas/Blueprint'),
config = require('../../../../config'),
middleware = require('../../middleware'),
util = require('../../util'),
@@ -159,7 +160,32 @@ var staff = module.exports = {
staff.layouts.make_stock
);
-
+
+ //
+ // blueprints
+
+ app.get('/staff/blueprints',
+ middleware.ensureAuthenticated,
+ middleware.ensureIsStaff,
+
+ staff.middleware.ensureBlueprintsCount,
+
+ staff.middleware.ensureBlueprints,
+ staff.middleware.ensureBlueprintsUsers,
+
+ staff.blueprints.index
+ );
+ app.get('/staff/blueprints/:slug',
+ middleware.ensureAuthenticated,
+ middleware.ensureIsStaff,
+
+ middleware.ensureBlueprint,
+ staff.middleware.ensureBlueprint,
+ staff.middleware.ensureBlueprintUser,
+
+ staff.blueprints.show
+ );
+
//
// media
@@ -321,7 +347,7 @@ var staff = module.exports = {
},
// /staff/projects/
- // /staff/projects/:name
+ // /staff/projects/:slug
projects: {
index: function(req, res){
res.locals.pagination.count = res.locals.projects.length
@@ -350,7 +376,7 @@ var staff = module.exports = {
},
// /staff/layouts/
- // /staff/layouts/:name
+ // /staff/layouts/:slug
layouts: {
index: function(req, res){
res.locals.pagination.count = res.locals.layouts.length
@@ -374,7 +400,26 @@ var staff = module.exports = {
})
},
},
-
+
+ // /staff/blueprints/
+ // /staff/blueprints/:slug
+ blueprints: {
+ index: function(req, res){
+ res.locals.pagination.count = res.locals.blueprints.length
+ res.locals.pagination.max = res.locals.blueprintCount
+ staff.paginate(req, res)
+ res.render('staff/blueprints/index')
+ },
+ show: function(req, res){
+ if (res.locals.blueprint) {
+ res.render('staff/blueprints/show', {
+ })
+ }
+ else {
+ res.render('staff/blueprints/show_404')
+ }
+ },
+ },
media: {
index: function(req, res){
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