From b4c7b2126b384a61bb69b046d0620ac53dd063ec Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 18 Aug 2015 17:55:10 -0400 Subject: split off info/settings --- .../javascripts/ui/blueprint/BlueprintInfo.js | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 public/assets/javascripts/ui/blueprint/BlueprintInfo.js (limited to 'public/assets/javascripts/ui/blueprint/BlueprintInfo.js') diff --git a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js new file mode 100644 index 0000000..ad462ae --- /dev/null +++ b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js @@ -0,0 +1,76 @@ + +var BlueprintInfo = View.extend({ + el: "#blueprintInfo", + + events: { + "mousedown": "stopPropagation", + "keydown": 'stopPropagation', + "keydown [name=height]": 'enterHeight', + "change [name=units]": 'changeUnits', + "keydown [name=viewHeight]": 'enterViewHeight', + "change [name=viewHeight]": 'changeViewHeight', + "click [data-role=destroy-room]": 'destroy', + }, + + initialize: function(opt){ + this.parent = opt.parent + this.$units = this.$("[name=units]") + this.$viewHeight = this.$("[name=viewHeight]") + this.$unitName = this.$(".unitName") + }, + + load: function(data){ + this.$viewHeight.unitVal( window.viewHeight = data.viewHeight || app.defaults.viewHeight ) + this.$units.val( data.units ) + this.$unitName.html( data.units ) + }, + + toggle: function(state){ + this.$el.toggleClass("active", state) + this.$viewHeight.unitVal( window.viewHeight ) + }, + + show: function(){ + this.toggle(true) + }, + + hide: function(){ + this.room = null + this.toggle(false) + }, + + room: null, + + pick: function(room){ + }, + + deselect: function(){ + this.room = null + this.toggle(true) + }, + + enterHeight: function(e){ + if (e.keyCode == 13) this.changeHeight(e) + }, + changeHeight: function(e){ + e.stopPropagation() + var height = this.room.height = this.$height.unitVal() + if (window.heightIsGlobal) { + Rooms.forEach(function(room){ + room.height = height + }) + } + Rooms.rebuild() + }, + changeUnits: function(){ + app.units = this.$units.val() + this.$('.units').resetUnitVal() + }, + enterViewHeight: function(e){ + if (e.keyCode == 13) this.changeViewHeight(e) + }, + changeViewHeight: function(){ + window.viewHeight = this.$viewHeight.unitVal() + } + +}) -- cgit v1.2.3-70-g09d2 From 72afc148b11ac57c991d699c205675b4b0f1cf70 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 18 Aug 2015 19:35:02 -0400 Subject: set wall height --- public/assets/javascripts/defaults.js | 1 + .../javascripts/mx/primitives/mx.polyline.js | 11 +++++++++-- .../javascripts/rectangles/engine/map/_map.js | 2 +- .../javascripts/ui/blueprint/BlueprintEditor.js | 2 +- .../javascripts/ui/blueprint/BlueprintInfo.js | 23 ++++++++-------------- .../javascripts/ui/blueprint/BlueprintScaler.js | 4 ++-- .../javascripts/ui/blueprint/BlueprintView.js | 7 ++----- public/assets/test/ortho2.html | 6 +++--- public/assets/test/ortho3.html | 2 +- public/assets/test/ortho4.html | 2 +- views/controls/blueprint/info.ejs | 2 -- 11 files changed, 29 insertions(+), 33 deletions(-) (limited to 'public/assets/javascripts/ui/blueprint/BlueprintInfo.js') diff --git a/public/assets/javascripts/defaults.js b/public/assets/javascripts/defaults.js index 413bb13..1e1ac5b 100644 --- a/public/assets/javascripts/defaults.js +++ b/public/assets/javascripts/defaults.js @@ -1,6 +1,7 @@ app = window.app || {} app.defaults = { viewHeight: window.viewHeight = 186, + wallHeight: 397, units: app.units = "ft", footResolution: 36, meterResolution: 100, diff --git a/public/assets/javascripts/mx/primitives/mx.polyline.js b/public/assets/javascripts/mx/primitives/mx.polyline.js index 555b3c6..63c0ef8 100644 --- a/public/assets/javascripts/mx/primitives/mx.polyline.js +++ b/public/assets/javascripts/mx/primitives/mx.polyline.js @@ -28,16 +28,23 @@ MX.Polyline = MX.Object3D.extend({ var angle = atan2( head.b - tail.b, head.a - tail.a ) mx.move({ x: mid_x / 2, - y: wall_height/2 + 1, + y: wallHeight/2 + 1, z: mid_z / 2, width: ceil(len), - height: wall_height, + height: wallHeight, rotationY: angle }) var hue = abs(round( angle / PI * 90 + 300)) mx.el.style.backgroundColor = 'hsl(' + [hue, "100%", "50%"] + ')' }, + set_height: function(height){ + for (var i = 0; i < this.faces.length; i++) { + this.faces[i].height = height + this.faces[i].y = height / 2 + 1 + } + }, + destroy: function(){ this.faces.forEach(function(mx){ scene.remove(mx) diff --git a/public/assets/javascripts/rectangles/engine/map/_map.js b/public/assets/javascripts/rectangles/engine/map/_map.js index e3d7621..2aee962 100644 --- a/public/assets/javascripts/rectangles/engine/map/_map.js +++ b/public/assets/javascripts/rectangles/engine/map/_map.js @@ -51,7 +51,7 @@ var Map = function(opt){ case "ortho": base.draw = new Map.Draw (base, { ortho: true }) base.ui = new Map.UI.Ortho (base) - base.sides = base.sides_for_camera + base.sides = base.sides_for_center $(window).resize(base.resize) break diff --git a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js index 72c129a..73f21c0 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js @@ -1,5 +1,5 @@ -var wall_height = 180 +var wallHeight = 180 var shapes = new ShapeList var last_point = new vec2 (0,0) diff --git a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js index ad462ae..6dd6a7d 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintInfo.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintInfo.js @@ -5,15 +5,16 @@ var BlueprintInfo = View.extend({ events: { "mousedown": "stopPropagation", "keydown": 'stopPropagation', + "change [name=height]": 'changeHeight', "keydown [name=height]": 'enterHeight', "change [name=units]": 'changeUnits', "keydown [name=viewHeight]": 'enterViewHeight', "change [name=viewHeight]": 'changeViewHeight', - "click [data-role=destroy-room]": 'destroy', }, initialize: function(opt){ this.parent = opt.parent + this.$height = this.$("[name=height]") this.$units = this.$("[name=units]") this.$viewHeight = this.$("[name=viewHeight]") this.$unitName = this.$(".unitName") @@ -21,8 +22,10 @@ var BlueprintInfo = View.extend({ 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.$unitName.html( data.units ) + this.show() }, toggle: function(state){ @@ -35,17 +38,10 @@ var BlueprintInfo = View.extend({ }, hide: function(){ - this.room = null this.toggle(false) }, - - room: null, - - pick: function(room){ - }, deselect: function(){ - this.room = null this.toggle(true) }, @@ -54,13 +50,10 @@ var BlueprintInfo = View.extend({ }, changeHeight: function(e){ e.stopPropagation() - var height = this.room.height = this.$height.unitVal() - if (window.heightIsGlobal) { - Rooms.forEach(function(room){ - room.height = height - }) - } - Rooms.rebuild() + window.wallHeight = this.$height.unitVal() + shapes.forEach(function(line){ + line.mx.set_height( window.wallHeight ) + }) }, changeUnits: function(){ app.units = this.$units.val() diff --git a/public/assets/javascripts/ui/blueprint/BlueprintScaler.js b/public/assets/javascripts/ui/blueprint/BlueprintScaler.js index 0f2fdcd..5bd2229 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintScaler.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintScaler.js @@ -48,7 +48,7 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ this.floorplan.load({ media: media, scale: 1, keepImage: true }) if (!! media.units && ! shouldEdit) { - this.parent.useFloorplan(media) + this.parent.ready(media) this.hide() this.stopAnimating() return @@ -149,7 +149,7 @@ var BlueprintScaler = ModalFormView.extend(AnimatedView.prototype).extend({ success: function(){ this.media.scale = this.$dimensions.unitVal() / this.lineLength() this.stopAnimating() - this.parent.useFloorplan(this.media) + this.parent.ready(this.media) this.hide() }, diff --git a/public/assets/javascripts/ui/blueprint/BlueprintView.js b/public/assets/javascripts/ui/blueprint/BlueprintView.js index a59f44f..f919cc7 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintView.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintView.js @@ -54,16 +54,13 @@ var BlueprintView = View.extend({ ready: function(data){ // this.settings.load(data) -// this.info.load(data) + this.info.load(data) + this.editor.loadFloorplan(data) }, hideExtras: function(){ }, - useFloorplan: function(media){ - this.editor.loadFloorplan(media) - }, - pickWall: function(wall, pos){ }, diff --git a/public/assets/test/ortho2.html b/public/assets/test/ortho2.html index 013c75b..448f029 100644 --- a/public/assets/test/ortho2.html +++ b/public/assets/test/ortho2.html @@ -167,7 +167,7 @@ $(window).resize(function(){ map.canvas.width = map.dimensions.a = window.innerWidth/2 }) -var wall_height = 180 +var wallHeight = 180 var placing = false var points, mx_points = [] var shapes = [] @@ -219,10 +219,10 @@ function add_mx_polyline_face(head, tail){ var angle = atan2( head.b - tail.b, head.a - tail.a ) mx.move({ x: mid_x / 2, - y: wall_height/2 + 1, + y: wallHeight/2 + 1, z: mid_z / 2, width: ceil(len), - height: wall_height, + height: wallHeight, rotationY: angle }) var hue = abs(round( angle / PI * 90 + 300)) diff --git a/public/assets/test/ortho3.html b/public/assets/test/ortho3.html index f41a0ba..71e43f1 100644 --- a/public/assets/test/ortho3.html +++ b/public/assets/test/ortho3.html @@ -112,7 +112,7 @@ $(window).resize(function(){ map.canvas.width = map.dimensions.a = window.innerWidth/2 }) -var wall_height = 180 +var wallHeight = 180 var shapes = new ShapeList var ctx = map.draw.ctx var last_point = new vec2 (0,0) diff --git a/public/assets/test/ortho4.html b/public/assets/test/ortho4.html index d704e0e..8db7ead 100644 --- a/public/assets/test/ortho4.html +++ b/public/assets/test/ortho4.html @@ -165,7 +165,7 @@ $(window).resize(function(){ map.canvas.height = map.dimensions.b = window.innerHeight/2 }) -var wall_height = 180 +var wallHeight = 180 var shapes = new ShapeList var ctx = map.draw.ctx var last_point = new vec2 (0,0) diff --git a/views/controls/blueprint/info.ejs b/views/controls/blueprint/info.ejs index f994629..9f7d708 100644 --- a/views/controls/blueprint/info.ejs +++ b/views/controls/blueprint/info.ejs @@ -4,8 +4,6 @@
- -
-- cgit v1.2.3-70-g09d2 From ebb9226fd5d37e8033e87e41b8ac0355d68f954c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 27 Aug 2015 18:00:57 -0400 Subject: staff area for blueprints --- .../rectangles/engine/shapes/regionlist.js | 64 +++++++++++++++------- .../rectangles/engine/shapes/shapelist.js | 3 + .../javascripts/ui/blueprint/BlueprintEditor.js | 8 +-- .../javascripts/ui/blueprint/BlueprintInfo.js | 23 ++++++++ public/assets/stylesheets/app.css | 9 +++ server/lib/middleware.js | 23 ++++++++ server/lib/views/staff/fields.js | 3 +- server/lib/views/staff/helpers.js | 7 +++ server/lib/views/staff/index.js | 53 ++++++++++++++++-- server/lib/views/staff/middleware.js | 55 +++++++++++++++++++ views/controls/blueprint/info.ejs | 7 +++ views/staff/_blueprints.ejs | 21 +++++++ views/staff/_nav.ejs | 1 + views/staff/blueprints/index.ejs | 13 +++++ views/staff/blueprints/show.ejs | 59 ++++++++++++++++++++ views/staff/blueprints/show_404.ejs | 9 +++ views/staff/layouts/show.ejs | 2 +- 17 files changed, 331 insertions(+), 29 deletions(-) create mode 100644 views/staff/_blueprints.ejs create mode 100644 views/staff/blueprints/index.ejs create mode 100644 views/staff/blueprints/show.ejs create mode 100644 views/staff/blueprints/show_404.ejs (limited to 'public/assets/javascripts/ui/blueprint/BlueprintInfo.js') 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 @@
+
+ + + px/ + [edit scale] +
+ 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 @@ + +[[ blueprints.forEach(function(blueprint){ ]] + + + + + + +[[ }) ]] +
+ [[- blueprint.name ]] + + [[- blueprint.user.username ]] + + [[- blueprint.date ]] +
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 @@ users projects layouts + blueprints media plans 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 ]] + +

Blueprints

+ +[[ include ../_nav ]] + +
+ +[[ 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 ]] + +

[[- blueprint.name ]]

+ +[[ include ../_nav ]] + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ [[- blueprint.name ]] + + [[- blueprint.date ]] +
+ [[ if (blueprintUser.photo) { ]] +
+ [[ } ]] + [[- blueprintUser.username ]] +
+ +
Width[[- blueprint.width ]]
Height[[- blueprint.height ]]
Scale[[- blueprint.scale ]]
+ +

+
+
+ +
+
+ +[[ 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 ]] + +

Blueprint not found

+ +[[ include ../_nav ]] + +
+ +[[ 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 @@ - featured? + stock layout? [[- layout.is_stock ? "yes" : "no" ]] -- cgit v1.2.3-70-g09d2