summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-27 18:00:57 -0400
committerJules Laplace <jules@okfoc.us>2015-08-27 18:00:57 -0400
commitebb9226fd5d37e8033e87e41b8ac0355d68f954c (patch)
tree8da5f8c450ab57379804a06000a24a875420f896
parentf2b0b712d4a73bfaeb1ed21674b0843f0d6fa28a (diff)
staff area for blueprints
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/regionlist.js64
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/shapelist.js3
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintEditor.js8
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintInfo.js23
-rwxr-xr-xpublic/assets/stylesheets/app.css9
-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
-rw-r--r--views/controls/blueprint/info.ejs7
-rw-r--r--views/staff/_blueprints.ejs21
-rw-r--r--views/staff/_nav.ejs1
-rw-r--r--views/staff/blueprints/index.ejs13
-rw-r--r--views/staff/blueprints/show.ejs59
-rw-r--r--views/staff/blueprints/show_404.ejs9
-rw-r--r--views/staff/layouts/show.ejs2
17 files changed, 331 insertions, 29 deletions
diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
index 86269a6..0dd4a1e 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
@@ -10,10 +10,25 @@ var RegionList = (function(){
var RegionList = {}
var regions = RegionList.regions
+ // Build a list of regions from the existing shapes.
+ // Operates on all the shapes at once.
RegionList.build = function(){
-
- // first, get the segments sorted right to left & top to bottom
var segments = RegionList.getSortedSegments()
+ return RegionList.buildRoomsFromSegments(segments)
+ }
+
+ // Build a list of regions from the individual shapes.
+ // Same, but operates on the shapes individually
+ RegionList.buildByShape = function(){
+ var shapes = RegionList.getSortedSegmentsByShape()
+ var region_lists = shapes.map(function(shape){
+ return RegionList.buildRoomsFromSegments(shape.segments)
+ })
+ var regions = []
+ return regions.concat.apply(regions, region_lists);
+ }
+
+ RegionList.buildRoomsFromSegments = function(segments){
var rooms = []
var seen_rooms = {}
@@ -172,31 +187,42 @@ var RegionList = (function(){
return rooms
}
-
// Gets a list of polylines from the ShapeList and sorts the segments.
RegionList.getSortedSegments = function(){
// get a list of all segments from these polylines
var segments = shapes.getAllSegments()
- // re-orient them so they're either facing up or right and make them into rects
- segments = segments.map(function(segment){
- // vertical
- if (segment[0].a == segment[1].a) {
- if (segment[0].b > segment[1].b) {
- segment.push(segment.shift())
- }
- }
- // horizontal
- else if (segment[0].b == segment[1].b) {
- if (segment[0].a > segment[1].a) {
- segment.push(segment.shift())
- }
- }
- return new Rect( segment[0].a, segment[0].b, segment[1].a, segment[1].b )
- })
+ segments = segments.map(RegionList.segmentsToRects)
return sort.rects_by_position(segments)
}
+
+ RegionList.getSortedSegmentsByShape = function(){
+ return shapes.getAllShapeSegments().map(function(shape){
+ var segments = shape.map(RegionList.segmentsToRects)
+ return {
+ shape: shape,
+ segments: sort.rects_by_position(segments)
+ }
+ })
+ }
+
+ // re-orient a segment so it's either facing up or right and make it into a rect
+ RegionList.segmentsToRects = function(segment){
+ // vertical
+ if (segment[0].a == segment[1].a) {
+ if (segment[0].b > segment[1].b) {
+ segment.push(segment.shift())
+ }
+ }
+ // horizontal
+ else if (segment[0].b == segment[1].b) {
+ if (segment[0].a > segment[1].a) {
+ segment.push(segment.shift())
+ }
+ }
+ return new Rect( segment[0].a, segment[0].b, segment[1].a, segment[1].b )
+ }
return RegionList
diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
index e5a70fb..2d33af2 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js
@@ -69,6 +69,9 @@ var ShapeList = Fiber.extend(function(base){
exports.forEach = function(fn){
this.shapes.forEach(fn)
}
+ exports.getAllShapeSegments = function(){
+ return this.shapes.map(function(shape){ return shape.getSegments() })
+ }
exports.getAllSegments = function(){
var segments = []
this.shapes.forEach(function(shape){
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js
index 7a1c064..7704689 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js
@@ -82,7 +82,7 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({
scale: media.scale,
})
this.startAnimating()
- this.regions = RegionList.build()
+ this.regions = RegionList.buildByShape()
},
animate: function(t, dt){
@@ -114,9 +114,9 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({
map.draw.camera(scene.camera)
// var colors = ["rgba(0,0,0,0.1)"]
-// var colors = ["rgba(255,255,255,1)"]
-//
-// map.draw.regions(this.regions, colors, "#000")
+// var colors = ["rgba(255,255,255,1)"]
+
+// map.draw.regions(this.regions, colors, "#000")
// this.regions.forEach(function(room,i){
// map.draw.ctx.fillStyle = colors[i % colors.length]
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
index 6dd6a7d..51b310e 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
@@ -10,6 +10,7 @@ var BlueprintInfo = View.extend({
"change [name=units]": 'changeUnits',
"keydown [name=viewHeight]": 'enterViewHeight',
"change [name=viewHeight]": 'changeViewHeight',
+ "click .openScaler": 'openScaler',
},
initialize: function(opt){
@@ -18,13 +19,30 @@ var BlueprintInfo = View.extend({
this.$units = this.$("[name=units]")
this.$viewHeight = this.$("[name=viewHeight]")
this.$unitName = this.$(".unitName")
+ this.$blueprintScaleDisplay = this.$("#blueprintScaleDisplay")
},
load: function(data){
this.$viewHeight.unitVal( window.viewHeight = data.viewHeight || app.defaults.viewHeight )
this.$height.unitVal( window.wallHeight = data.wallHeight || app.defaults.wallHeight )
this.$units.val( data.units )
+ this.$('span.units').html( data.units )
this.$unitName.html( data.units )
+
+ var resolution
+ switch (data.units) {
+ case 'ft':
+ resolution = app.defaults.footResolution
+ break
+ case 'm':
+ resolution = app.defaults.meterResolution
+ break
+ case 'px':
+ default:
+ resolution = 1
+ break
+ }
+ this.$blueprintScaleDisplay.html( ((1/data.scale) * resolution).toFixed(1) )
this.show()
},
@@ -33,6 +51,11 @@ var BlueprintInfo = View.extend({
this.$viewHeight.unitVal( window.viewHeight )
},
+ openScaler: function(){
+ this.parent.scaler.pick( this.parent.data, true )
+ this.parent.scaler.show()
+ },
+
show: function(){
this.toggle(true)
},
diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css
index e4f1b27..1154fde 100755
--- a/public/assets/stylesheets/app.css
+++ b/public/assets/stylesheets/app.css
@@ -2505,6 +2505,9 @@ input[type="range"]::-webkit-slider-thumb {
top: 5px;
font-weight:600;
}
+.setting.number.scale label {
+ top: 0;
+}
.setting.number label:after {
content:":";
}
@@ -3328,6 +3331,7 @@ a[data-role="forgot-password"] {
padding: 0px;
position: relative;
display: inline-block;
+ margin: 0 2px;
}
.blueprints .blueprint img {
height: 100px;
@@ -3364,6 +3368,11 @@ a[data-role="forgot-password"] {
[data-role="create-new-blueprint"] {
margin-bottom: 10px;
}
+.openScaler {
+ margin-left: 10px;
+ border-bottom: 1px solid;
+ cursor: pointer;
+}
/* KEYBOARD SHORTCUTS */
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
diff --git a/views/controls/blueprint/info.ejs b/views/controls/blueprint/info.ejs
index 4e2316f..a86481b 100644
--- a/views/controls/blueprint/info.ejs
+++ b/views/controls/blueprint/info.ejs
@@ -20,4 +20,11 @@
</select>
</div>
+ <div class="setting number scale">
+ <label>scale</label>
+ <span id="blueprintScaleDisplay"></span>
+ px/<span class="units"></span>
+ <span class="openScaler">[edit scale]</span>
+ </div>
+
</div>
diff --git a/views/staff/_blueprints.ejs b/views/staff/_blueprints.ejs
new file mode 100644
index 0000000..58fe2a3
--- /dev/null
+++ b/views/staff/_blueprints.ejs
@@ -0,0 +1,21 @@
+<table id="users">
+[[ blueprints.forEach(function(blueprint){ ]]
+ <tr>
+ <td>
+ <a href="/staff/blueprints/[[- blueprint.slug ]]">[[- blueprint.name ]]</a>
+ </td>
+ <td class="editLinks">
+ <a href="/blueprint/[[- blueprint.slug ]]">[view]</a>
+<!--
+ <a href="/api/rooms/[[- blueprint.slug ]]">[api]</a>
+ -->
+ </td>
+ <td>
+ <a href="/staff/users/[[- blueprint.user.username ]]">[[- blueprint.user.username ]]</a>
+ </td>
+ <td>
+ [[- blueprint.date ]]
+ </td>
+ </tr>
+[[ }) ]]
+</table>
diff --git a/views/staff/_nav.ejs b/views/staff/_nav.ejs
index 3bb3b08..702a374 100644
--- a/views/staff/_nav.ejs
+++ b/views/staff/_nav.ejs
@@ -3,6 +3,7 @@
<a href="/staff/users">users</a>
<a href="/staff/projects">projects</a>
<a href="/staff/layouts">layouts</a>
+ <a href="/staff/blueprints">blueprints</a>
<a href="/staff/media">media</a>
<a href="/staff/plans">plans</a>
<!-- <a href="/staff/subscriptions">subscriptions</a> -->
diff --git a/views/staff/blueprints/index.ejs b/views/staff/blueprints/index.ejs
new file mode 100644
index 0000000..2206a1c
--- /dev/null
+++ b/views/staff/blueprints/index.ejs
@@ -0,0 +1,13 @@
+[[ include ../_header ]]
+
+ <h1>Blueprints</h1>
+
+[[ include ../_nav ]]
+
+ <hr>
+
+[[ include ../_pagination ]]
+[[ include ../_blueprints ]]
+[[ include ../_pagination ]]
+
+[[ include ../_footer ]]
diff --git a/views/staff/blueprints/show.ejs b/views/staff/blueprints/show.ejs
new file mode 100644
index 0000000..5fd9db6
--- /dev/null
+++ b/views/staff/blueprints/show.ejs
@@ -0,0 +1,59 @@
+[[ include ../_header ]]
+
+ <h1>[[- blueprint.name ]]</h1>
+
+[[ include ../_nav ]]
+
+ <hr>
+
+ <table>
+ <tr>
+ <td>
+ <a href="/staff/blueprints/[[- blueprint.slug ]]">[[- blueprint.name ]]</a>
+ </td>
+ <td class="editLinks">
+ <a href="/blueprint/[[- blueprint.slug ]]">[view]</a>
+ <a href="/blueprint/[[- blueprint.slug ]]/edit">[edit]</a>
+<!--
+ <a href="/api/rooms/[[- blueprint.slug ]]">[api]</a>
+ -->
+ </td>
+ <td>
+ [[- blueprint.date ]]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ [[ if (blueprintUser.photo) { ]]
+ <a href="/staff/users/[[- blueprintUser.username ]]"><div style="background-image:url([[- blueprintUser.photo ]])" class="avatar"></div></a>
+ [[ } ]]
+ <a href="/staff/users/[[- blueprintUser.username ]]">[[- blueprintUser.username ]]</a>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="999">
+ <img src="[[- blueprint.url ]]" style="max-width: 400px">
+ </td>
+ </tr>
+ <tr>
+ <td>Width</td>
+ <td>[[- blueprint.width ]]</td>
+ </tr>
+ <tr>
+ <td>Height</td>
+ <td>[[- blueprint.height ]]</td>
+ </tr>
+ <tr>
+ <td>Scale</td>
+ <td>[[- blueprint.scale ]]</td>
+ </tr>
+ </table>
+
+ <br><br>
+ <div id="actions">
+ </div>
+
+ <br>
+ <br>
+
+[[ include ../_footer ]]
diff --git a/views/staff/blueprints/show_404.ejs b/views/staff/blueprints/show_404.ejs
new file mode 100644
index 0000000..0ffca86
--- /dev/null
+++ b/views/staff/blueprints/show_404.ejs
@@ -0,0 +1,9 @@
+[[ include ../_header ]]
+
+ <h1>Blueprint not found</h1>
+
+[[ include ../_nav ]]
+
+ <hr>
+
+[[ include ../_footer ]]
diff --git a/views/staff/layouts/show.ejs b/views/staff/layouts/show.ejs
index b66449f..2742c1f 100644
--- a/views/staff/layouts/show.ejs
+++ b/views/staff/layouts/show.ejs
@@ -42,7 +42,7 @@
</tr>
<tr>
<th>
- featured?
+ stock layout?
</th>
<td id="isStockLayout">
[[- layout.is_stock ? "yes" : "no" ]]