From e75bf50727b3ebdd142953c09117de38d3a5b174 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 10 Oct 2014 14:55:19 -0400 Subject: stuff date in url slugs --- server/lib/api/projects.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'server/lib/api') diff --git a/server/lib/api/projects.js b/server/lib/api/projects.js index 61a6e10..5bd3d0f 100644 --- a/server/lib/api/projects.js +++ b/server/lib/api/projects.js @@ -67,14 +67,6 @@ var projects = { return docs.create(req, res) } - var data = util.cleanQuery(req.body) - - // data.user_id = req.user._id - data.name = util.sanitize(data.name) - data.slug = util.slugify(data.name) - data.description = util.sanitize(data.description) - data.updated_at = new Date () - if (req.files.thumbnail) { upload.put("projects", req.files.thumbnail, { unacceptable: function(err){ @@ -93,6 +85,17 @@ var projects = { function done() { Project.findOne({ _id: _id }, function(err, doc){ if (err || ! doc) { return res.json({ error: err }) } + + var data = util.cleanQuery(req.body) + + // data.user_id = req.user._id + data.name = util.sanitize(data.name) + if (data.name != doc.name) { + data.slug = util.slugify(data.name) + } + data.description = util.sanitize(data.description) + data.updated_at = new Date () + _.extend(doc, data) doc.rooms = JSON.parse(data.rooms) -- cgit v1.2.3-70-g09d2 From e35d5df30c8106bc1f4bfcbd1ba0094d8e6bc642 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 10 Oct 2014 15:59:50 -0400 Subject: change profile avatar --- public/assets/javascripts/ui/site/ProfileView.js | 19 +++++++++++++++++++ public/assets/stylesheets/app.css | 1 + server/lib/api/projects.js | 4 ++-- server/lib/util.js | 2 +- server/lib/views/index.js | 1 + views/profile.ejs | 8 ++++++-- views/projects/list-projects.ejs | 4 ++-- 7 files changed, 32 insertions(+), 7 deletions(-) (limited to 'server/lib/api') diff --git a/public/assets/javascripts/ui/site/ProfileView.js b/public/assets/javascripts/ui/site/ProfileView.js index 76d733c..8471abc 100644 --- a/public/assets/javascripts/ui/site/ProfileView.js +++ b/public/assets/javascripts/ui/site/ProfileView.js @@ -21,6 +21,25 @@ var ProfileView = View.extend({ }, uploadAvatar: function(){ + var fd = new FormData(), hasCSRF = false + var files = this.$("#profile_avatar")[0].files + if (! files.length) return + + fd.append("avatar", files[0]); + fd.append("_csrf", $("[name=_csrf]").val()) + + var request = $.ajax({ + url: "/api/profile", + type: "put", + data: fd, + dataType: "json", + processData: false, + contentType: false, + }) + + request.done($.proxy(function (response) { + window.location.href = "/profile" + }, this)); } }) diff --git a/public/assets/stylesheets/app.css b/public/assets/stylesheets/app.css index 57cb8fc..29f7888 100755 --- a/public/assets/stylesheets/app.css +++ b/public/assets/stylesheets/app.css @@ -679,6 +679,7 @@ iframe.embed { } .profilepage .about h2 .btn { + float: none; border: 1px solid; font-weight: 500; padding: 10px; diff --git a/server/lib/api/projects.js b/server/lib/api/projects.js index 5bd3d0f..c04f4f6 100644 --- a/server/lib/api/projects.js +++ b/server/lib/api/projects.js @@ -34,7 +34,7 @@ var projects = { data.user_id = req.user._id data.name = util.sanitize(data.name) - data.slug = util.slugify(data.name) + data.slug = util.slugify(data.name) + "-" + (+new Date) data.description = util.sanitize(data.description) data.rooms = JSON.parse(data.rooms) data.walls = JSON.parse(data.walls) @@ -91,7 +91,7 @@ var projects = { // data.user_id = req.user._id data.name = util.sanitize(data.name) if (data.name != doc.name) { - data.slug = util.slugify(data.name) + data.slug = util.slugify(data.name) + "-" + (+new Date) } data.description = util.sanitize(data.description) data.updated_at = new Date () diff --git a/server/lib/util.js b/server/lib/util.js index 2841cc5..791d3e2 100644 --- a/server/lib/util.js +++ b/server/lib/util.js @@ -13,7 +13,7 @@ var util = {} util.trim = function (s){ return (s || "").replace(whitespaceHead,"").replace(whitespaceTail,"") } util.slugify = function (s){ - return (s + "-" + (+new Date) || "").toLowerCase().replace(whitespace,"-").replace(nonAlphanumerics, '-').replace(consecutiveDashes,"-") + return (s || "").toLowerCase().replace(whitespace,"-").replace(nonAlphanumerics, '-').replace(consecutiveDashes,"-") } util.sanitize = function (s){ return (s || "").replace(entities, "") diff --git a/server/lib/views/index.js b/server/lib/views/index.js index 637b061..5b1a72e 100644 --- a/server/lib/views/index.js +++ b/server/lib/views/index.js @@ -165,6 +165,7 @@ var views = module.exports = { function done(err, user, projects){ if (! user) { return res.redirect('/') } res.render('profile', { + isOwnProfile: String(user._id) == (req.user && String(req.user._id)), profile: user, projects: projects || [], }) diff --git a/views/profile.ejs b/views/profile.ejs index 5ff2eb0..2909fb8 100644 --- a/views/profile.ejs +++ b/views/profile.ejs @@ -16,8 +16,10 @@
-
click to add profile pic
- + [[ if (isOwnProfile) { ]] +
click to add profile pic
+ + [[ } ]]
[[ } ]] @@ -57,12 +59,14 @@ VValls lets you create awesome 3D rooms. + [[ if (isOwnProfile) { ]]

You don't have any projects yet.

Create a New Project

+ [[ } ]] [[ } ]] diff --git a/views/projects/list-projects.ejs b/views/projects/list-projects.ejs index c47dee0..9dbd7d2 100644 --- a/views/projects/list-projects.ejs +++ b/views/projects/list-projects.ejs @@ -5,9 +5,9 @@ [[ projects.forEach(function(project, i) { ]] [[ if (String(user._id) == String(project.user_id)) { ]] - + [[ } else { ]] - + [[ } ]] -- cgit v1.2.3-70-g09d2