Finalizing display issues for news release

This commit is contained in:
Nathan Leniz
2015-03-08 16:50:51 +09:00
parent bac22c1d96
commit f367a0310e
10 changed files with 156 additions and 67 deletions

View File

@ -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);
}
}
};

View File

@ -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});

View File

@ -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);
if (err) {
return next(err);
}
req.flash('success', {msg: 'Profile information updated.'});
res.redirect('/account');
resources.updateUserStoryPictures(user._id.toString(), user.profile.picture);
});
});
});

View File

@ -30,3 +30,10 @@ var commentSchema = new mongoose.Schema({
});
module.exports = mongoose.model('Comment', commentSchema);
/*
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
*/

View File

@ -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'
}
},
*/

View File

@ -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;

View File

@ -27,7 +27,7 @@
.html(
"<div class='comment row col-xs-12'>" +
"<div class='col-xs-1'>" +
"<img class='img-responsive' src=" + commentDetails.author.picture + "></img>" +
"<img class='img-news' src=" + commentDetails.author.picture + "></img>" +
"</div>" +
"<div class='col-xs-10'>" +
"<div class='row'>" +
@ -35,25 +35,19 @@
commentDetails.body +
"</div>" +
"</div>" +
"<div class='row'>" +
"<div>" +
"<h6>" +
"<div class='col-xs-12 negative-15'>" +
"<div class='col-xs-12 negative-15 comment-a-comment'>" +
"commented " + moment(commentDetails.commentedOn).fromNow() + " by " +
"<a href='/" + commentDetails.author.username + "'>@" + commentDetails.author.username + "</a>" +
"</div>" +
"</h6>" +
"</div>" +
"<div class='row negative-20'>" +
"<div class='col-xs-6 comment-a-comment'>" +
"<h6>" +
"<a href='/" + commentDetails.author.username + "'>@" + commentDetails.author.username + "</a> · " +
"<a id='" + commentDetails._id + "'>Reply</a>" +
"</h6>" +
"</div>" +
"</h6>" +
"</div>" +
"</div>" +
"</div>"
)
.addClass(offSetClass + ' row ' + rowClass + ' comment_' + commentDetails._id)
.addClass('comment-wrapper comment_' + commentDetails._id)
.appendTo($(containerSelector));
sentinel += commentDetails.comments.length;
@ -70,7 +64,7 @@
var commentId = $(this).attr('id');
$(div).html(
"<div class='formgroup'>" +
"<textarea class='form-control' id='comment-to-comment-textarea'></textarea>" +
"<textarea class='form-control' id='comment-to-comment-textarea' maxlength='500' rows='5'></textarea>" +
"<button class='btn btn-small btn-primary' id='submit-comment-to-comment'>Submit</button>" +
"</div>"
)

View File

@ -1,3 +1,4 @@
.spacer
.col-xs-12
#story-list.story-list

View File

@ -1,10 +1,12 @@
h3
ul#story-list.story-list
.spacer
.col-xs-12
#story-list.story-list
script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js")
script.
var getLinkedName = function getLinkedName(name) {
return name.toLowerCase().replace(/\s/g, '-');
return name.trim().toLowerCase().replace(/\s/g, '-');
}
$.ajax({
url: '/stories/recentStories',
@ -13,22 +15,20 @@ h3
.success(
function(data) {
for (var i = 0; i < data.length; i++) {
var li = document.createElement('li');
var div = document.createElement('div');
var linkedName = getLinkedName(data[i].storyLink);
var rank = data[i].rank;
$(li)
$(div)
.html(
"<div class='row text-left'>" +
"<div class='col-xs-3 col-sm-1'>" +
"<div class='positive-5'>" +
"<span>" + rank + "</span>" +
"</div>" +
"<div class='col-xs-12 text-left'>" +
"<div class='col-xs-1 col-sm-1 positive-5'>" +
(i + 1) +
"</div>" +
"<div class='col-xs-2 col-sm-1'>" +
"<img src='" + data[i].author.picture + "' class='img-responsive'/>" +
"<img src='" + data[i].author.picture + "' class='img-news'/>" +
"</div>" +
"<div class='col-xs-7 col-sm-10'>" +
"<div class='col-xs-9 col-sm-10'>" +
"<div class='row'>" +
"<div class='col-xs-12'>" +
"<a href='/stories/" + linkedName + "'>"
@ -36,14 +36,17 @@ h3
"</a>" +
"</div>" +
"<div class='col-xs-12'>" +
"<span>Posted " +
"<span>" +
rank + " points, posted " +
moment(data[i].timePosted).fromNow() +
" by <a href='/" + data[i].author.username + "'>@" + data[i].author.username + "</a> " +
"</span" +
"</span>" +
"</div>" +
"</div>" +
"</div>" +
"</div>"
)
$(li).appendTo($('#story-list'));
);
$(div).addClass('story-list')
$(div).appendTo($('#story-list'));
}
});

View File

@ -17,7 +17,7 @@
h3.story-up-votes
span#storyRank= rank
.col-xs-2.col-sm-1
img(src="#{author.picture}", class='img-responsive')
img(src="#{author.picture}", class='img-news')
.col-xs-7.col-sm-10
.col-xs-12.negative-28
a(href="#{link}")
@ -26,17 +26,29 @@
.col-xs-12.negative-15
span Posted #{timeAgo}
span &nbsp;by&nbsp;
a(href="/" + author.username) @#{author.username}
a(href="/" + author.username)
| @#{author.username}
| &nbsp;·&nbsp;
a#reply-to-main-post Reply
.col-xs-10.col-xs-offset-1
p= description
.col-xs-12#reply-area
.hidden-element#initial-comment-submit
form.form-horizontal.control-label-story-submission
.col-xs-12
.form-group
h3.row.col-xs-12
h3.row
textarea#comment-box.form-control(name="comment-box", rows=5)
h3.row.text-center
.col-xs-6.col-xs-offset-3
button.btn.btn-block.btn-primary#comment-button Comment
script.
$('#reply-to-main-post').on('click', function() {
$('#initial-comment-submit').removeClass('hidden-element');
$(this).unbind('click');
});
include ./comments