diff --git a/controllers/resources.js b/controllers/resources.js index cf716d4d34b..b47a2731581 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -1,6 +1,8 @@ var User = require('../models/User'), Challenge = require('./../models/Challenge'), Bonfire = require('./../models/Bonfire'), + Story = require('./../models/Story'), + Comment = require('./../models/Comment'), resources = require('./resources.json'), questions = resources.questions, steps = resources.steps, @@ -11,7 +13,8 @@ var User = require('../models/User'), https = require('https'), debug = require('debug')('freecc:cntr:resources'), cheerio = require('cheerio'), - request = require('request'); + request = require('request'), + R = require('ramda'); /** * GET / @@ -283,8 +286,47 @@ module.exports = { } }); })(); + }, + updateUserStoryPictures: function(userId, picture) { + + var counter = 0, + foundStories, + foundComments; + + Story.find({'author.userId': userId}, function(err, stories) { + if (err) { + throw err; + } + foundStories = stories; + counter++; + saveStoriesAndComments(); + }); + Comment.find({'author.userId': userId}, function(err, comments) { + if (err) { + throw err; + } + foundComments = comments; + counter++; + saveStoriesAndComments(); + }); + + function saveStoriesAndComments() { + if (counter !== 2) { + return; + } + R.forEach(function(comment) { + comment.author.picture = picture; + comment.markModified('author'); + comment.save(); + }, foundComments); + + R.forEach(function(story) { + story.author.picture = picture; + debug('This is a story', story); + debug(story.author.picture); + story.markModified('author'); + story.save(); + }, foundStories); + } } }; - - - diff --git a/controllers/story.js b/controllers/story.js index 5bbca93aadf..b3eab988349 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -7,7 +7,8 @@ var R = require('ramda'), resources = require('./resources'), mongodb = require('mongodb'), MongoClient = mongodb.MongoClient, - secrets = require('../config/secrets'); + secrets = require('../config/secrets'), + User = require('./../models/User'); exports.hotJSON = function(req, res, next) { var story = Story.find({}).sort({'rank': -1, 'timePosted': -1}); diff --git a/controllers/user.js b/controllers/user.js index c7947d53a9c..c0da54bf470 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -7,7 +7,8 @@ var _ = require('lodash'), secrets = require('../config/secrets'), moment = require('moment'), Challenge = require('./../models/Challenge'), - debug = require('debug')('freecc:cntr:challenges'); + debug = require('debug')('freecc:cntr:challenges') + resources = require('./resources'); //TODO(Berks): Refactor to use module.exports = {} pattern. @@ -314,7 +315,7 @@ exports.postUpdateProfile = function(req, res, next) { return next(err); } var user = req.user; - if (existingUsername && existingUsername.profile.username != user.profile.username) { + if (existingUsername && existingUsername.profile.username !== user.profile.username) { req.flash('errors', { msg: 'An account with that username already exists.' }); @@ -343,9 +344,12 @@ exports.postUpdateProfile = function(req, res, next) { user.save(function (err) { - if (err) return next(err); - req.flash('success', {msg: 'Profile information updated.'}); - res.redirect('/account'); + if (err) { + return next(err); + } + req.flash('success', {msg: 'Profile information updated.'}); + res.redirect('/account'); + resources.updateUserStoryPictures(user._id.toString(), user.profile.picture); }); }); }); diff --git a/models/Comment.js b/models/Comment.js index 8af4aaefcfc..89d1804654e 100644 --- a/models/Comment.js +++ b/models/Comment.js @@ -29,4 +29,11 @@ var commentSchema = new mongoose.Schema({ } }); -module.exports = mongoose.model('Comment', commentSchema); \ No newline at end of file +module.exports = mongoose.model('Comment', commentSchema); + +/* + author: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User' + }, + */ \ No newline at end of file diff --git a/models/Story.js b/models/Story.js index 902ff2c893f..76d95471a5c 100644 --- a/models/Story.js +++ b/models/Story.js @@ -41,5 +41,18 @@ var storySchema = new mongoose.Schema({ } }); +storySchema.pre('save', function(next) { + console.log('pre save test'); + next(); +}); + module.exports = mongoose.model('Story', storySchema); +/* + author: { + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User' + } + }, + */ diff --git a/public/css/main.less b/public/css/main.less index b3e4ad7bb46..c12a8977895 100644 --- a/public/css/main.less +++ b/public/css/main.less @@ -192,6 +192,10 @@ ul { margin-top: -35px; } +.negative-30 { + margin-top: -30px; +} + .negative-5 { margin-top: -5px; } @@ -811,6 +815,14 @@ iframe.iphone { height: 50px; } +.comment-wrapper { + position: relative; +} + +.comment + .comment-wrapper { + left: 3%; +} + //uncomment this to see the dimensions of all elements outlined in red //* { // border-color: red; diff --git a/views/stories/comments.jade b/views/stories/comments.jade index f916e041a5a..b85cd7e7e0d 100644 --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -25,35 +25,29 @@ var div = document.createElement('div'); $(div) .html( - "
" + - "" +
- "commented " + moment(commentDetails.commentedOn).fromNow() + " by " +
- "@" + commentDetails.author.username + "" +
+ "" +
+ "" +
+ "" +
+ commentDetails.body +
" " +
- "" +
- " " +
- "" +
- "" +
+ " " +
+ "" +
" " +
" " +
- " " +
- " "
- )
- .addClass(offSetClass + ' row ' + rowClass + ' comment_' + commentDetails._id)
+ "
" + - "Reply" + + "" +
+ "commented " + moment(commentDetails.commentedOn).fromNow() + " by " +
+ "@" + commentDetails.author.username + " · " +
+ "Reply" +
+ " " +
"
" + "