summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-07 14:58:34 -0400
committerJules Laplace <jules@okfoc.us>2015-08-07 14:58:34 -0400
commita8005cd5db8d24342a6b7d53ccedc9808050eef7 (patch)
tree2ebf7d91f4e136e0f8d37095c12e58d1e81e7a87
parent387d00aa5c329cfc59f7e940542bf971fa6eecdd (diff)
layouts staff stuff
-rw-r--r--server/lib/schemas/Layout.js2
-rw-r--r--server/lib/views/staff.js75
2 files changed, 74 insertions, 3 deletions
diff --git a/server/lib/schemas/Layout.js b/server/lib/schemas/Layout.js
index e3f2616..cff1d78 100644
--- a/server/lib/schemas/Layout.js
+++ b/server/lib/schemas/Layout.js
@@ -26,6 +26,8 @@ var LayoutSchema = new mongoose.Schema({
rooms: [mongoose.Schema.Types.Mixed],
startPosition: mongoose.Schema.Types.Mixed,
viewHeight: { type: Number },
+ is_stock: { type: Boolean, default: false },
+ is_pro: { type: Boolean, default: false },
user_id: { type: mongoose.Schema.ObjectId, index: true },
created_at: { type: Date },
updated_at: { type: Date },
diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js
index 6c97bbd..0fdbbb7 100644
--- a/server/lib/views/staff.js
+++ b/server/lib/views/staff.js
@@ -17,7 +17,8 @@ var staff = module.exports = {
fields: {
user: "_id username displayName photo created_at updated_at last_seen created_ip last_ip",
- project: "_id name slug user_id privacy created_at updated_at",
+ 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",
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",
@@ -116,6 +117,35 @@ var staff = module.exports = {
})
},
+ ensureLayouts: 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
+ }
+ Layout.find(criteria)
+ .select(staff.fields.layout)
+ .sort(sort)
+ .skip(offset)
+ .limit(limit)
+ .exec(function (err, layouts) {
+ res.locals.layouts = layouts.map(staff.helpers.layout)
+ next()
+ })
+ },
+
ensureMedia: function(req, res, next){
var paginationInfo = res.locals.pagination = {}
var criteria = req.criteria || {}
@@ -223,6 +253,11 @@ var staff = module.exports = {
staff.middleware.ensureObjectsUsers(res.locals.projects, next)
},
+ ensureLayoutsUsers: function(req, res, next){
+ if (! res.locals.layouts || ! res.locals.layouts.length) { return next() }
+ staff.middleware.ensureObjectsUsers(res.locals.layouts, next)
+ },
+
ensureSubscriptionsUsers: function(req, res, next){
if (! res.locals.subscriptions || ! res.locals.subscriptions.length) { return next() }
staff.middleware.ensureObjectsUsers(res.locals.subscriptions, next)
@@ -321,6 +356,13 @@ var staff = module.exports = {
})
},
+ ensureLayoutsCount: function(req, res, next){
+ Layout.count({}, function(err, count){
+ res.locals.layoutCount = count || 0
+ next()
+ })
+ },
+
ensureMediaCount: function(req, res, next){
Media.count({}, function(err, count){
res.locals.mediaCount = count || 0
@@ -552,7 +594,7 @@ var staff = module.exports = {
staff.layouts.show
);
- app.put('/staff/layouts/:slug/feature',
+ app.put('/staff/layouts/:slug/stock',
middleware.ensureAuthenticated,
middleware.ensureIsStaff,
@@ -561,7 +603,7 @@ var staff = module.exports = {
staff.layouts.make_stock
);
-
+
//
// media
@@ -744,7 +786,34 @@ var staff = module.exports = {
})
},
},
+
+ // /staff/layouts/
+ // /staff/layouts/:name
+ layouts: {
+ index: function(req, res){
+ res.locals.pagination.count = res.locals.layouts.length
+ res.locals.pagination.max = res.locals.layoutCount
+ staff.paginate(req, res)
+ res.render('staff/layouts/index')
+ },
+ show: function(req, res){
+ if (res.locals.layout) {
+ res.render('staff/layouts/show', {
+ })
+ }
+ else {
+ res.render('staff/layouts/show_404')
+ }
+ },
+ feature: function(req, res){
+ res.locals.layout.is_stock = req.body.state == "true"
+ res.locals.layout.save(function(err, layout){
+ res.json({ state: layout.featured })
+ })
+ },
+ },
+
media: {
index: function(req, res){
res.locals.pagination.count = res.locals.media.length