cleanup while getting familiar with the codebase

This commit is contained in:
Mitchell Wulfman 2014-09-16 15:18:27 -04:00
parent 8250f52450
commit 6fc6b9eb78
30 changed files with 67 additions and 67 deletions

View file

@ -20,7 +20,7 @@ SharrreOptions={
share: { share: {
googlePlus: true, googlePlus: true,
// facebook: true, // facebook: true,
twitter: true, twitter: true
}, },
buttons: { buttons: {
googlePlus: {size: 'tall', annotation:'bubble'}, googlePlus: {size: 'tall', annotation:'bubble'},

View file

@ -10,7 +10,7 @@ Template[getTemplate('comment_edit')].rendered = function(){
}); });
} }
} }
} };
Template[getTemplate('comment_edit')].events({ Template[getTemplate('comment_edit')].events({
'click input[type=submit]': function(e, instance){ 'click input[type=submit]': function(e, instance){
@ -38,7 +38,7 @@ Template[getTemplate('comment_edit')].events({
if(confirm(i18n.t("Are you sure?"))){ if(confirm(i18n.t("Are you sure?"))){
Meteor.call('removeComment', comment._id); Meteor.call('removeComment', comment._id);
Router.go("/posts/"+comment.postId) Router.go("/posts/"+comment.postId);
throwError("Your comment has been deleted."); throwError("Your comment has been deleted.");
// Router.go("/comments/deleted"); // Router.go("/comments/deleted");
} }

View file

@ -2,7 +2,7 @@ Template[getTemplate('comment_form')].helpers({
canComment: function(){ canComment: function(){
return canComment(Meteor.user()); return canComment(Meteor.user());
} }
}) });
Template[getTemplate('comment_form')].rendered = function(){ Template[getTemplate('comment_form')].rendered = function(){
if(Meteor.user() && !this.editor){ if(Meteor.user() && !this.editor){
@ -11,7 +11,7 @@ Template[getTemplate('comment_form')].rendered = function(){
$(window.editor).closest('form').find('input[type="submit"]').click(); $(window.editor).closest('form').find('input[type="submit"]').click();
}); });
} }
} };
Template[getTemplate('comment_form')].events({ Template[getTemplate('comment_form')].events({
'submit form': function(e, instance){ 'submit form': function(e, instance){

View file

@ -60,7 +60,7 @@ Template[getTemplate('comment_item')].created = function() {
// if comments are supposed to be queued, then queue this comment on create // if comments are supposed to be queued, then queue this comment on create
this.isQueued = window.queueComments; this.isQueued = window.queueComments;
window.openedComments = []; window.openedComments = [];
} };
Template[getTemplate('comment_item')].helpers({ Template[getTemplate('comment_item')].helpers({
comment_item: function () { comment_item: function () {
@ -138,7 +138,7 @@ Template[getTemplate('comment_item')].rendered=function(){
// // TODO: take the user back to their previous scroll position // // TODO: take the user back to their previous scroll position
// } // }
// } // }
} };
Template.comment_item.events({ Template.comment_item.events({
'click .queue-comment': function(e){ 'click .queue-comment': function(e){

View file

@ -1,6 +1,6 @@
Template[getTemplate('comment_list')].created = function(){ Template[getTemplate('comment_list')].created = function(){
postObject = this.data; postObject = this.data;
} };
Template[getTemplate('comment_list')].helpers({ Template[getTemplate('comment_list')].helpers({
comment_item: function () { comment_item: function () {
@ -16,4 +16,4 @@ Template[getTemplate('comment_list')].helpers({
Template[getTemplate('comment_list')].rendered = function(){ Template[getTemplate('comment_list')].rendered = function(){
// once all comments have been rendered, activate comment queuing for future real-time comments // once all comments have been rendered, activate comment queuing for future real-time comments
window.queueComments = true; window.queueComments = true;
} };

View file

@ -1,10 +1,10 @@
Template[getTemplate('error_item')].helpers({ Template[getTemplate('error_item')].helpers({
}) });
Template[getTemplate('error_item')].created = function(){ Template[getTemplate('error_item')].created = function(){
var error_id=this.data._id; var error_id=this.data._id;
Meteor.setTimeout(function(){ Meteor.setTimeout(function(){
Errors.update(error_id, {$set: {seen:true}}); Errors.update(error_id, {$set: {seen:true}});
}, 100); }, 100);
} };

View file

@ -30,11 +30,11 @@ Template[getTemplate('layout')].helpers({
Template[getTemplate('layout')].created = function(){ Template[getTemplate('layout')].created = function(){
Session.set('currentScroll', null); Session.set('currentScroll', null);
} };
Template[getTemplate('layout')].rendered = function(){ Template[getTemplate('layout')].rendered = function(){
if(currentScroll=Session.get('currentScroll')){ if(currentScroll=Session.get('currentScroll')){
$('body').scrollTop(currentScroll); $('body').scrollTop(currentScroll);
Session.set('currentScroll', null); Session.set('currentScroll', null);
} }
} };

View file

@ -8,7 +8,7 @@ Template[getTemplate('unsubscribe')].created = function(){
} }
}); });
trackEvent('notificationsUnsubcribe', {hash: hash}); trackEvent('notificationsUnsubcribe', {hash: hash});
} };
Template[getTemplate('unsubscribe')].helpers({ Template[getTemplate('unsubscribe')].helpers({
unsubscribed : function(){ unsubscribed : function(){

View file

@ -2,4 +2,4 @@ Template[getTemplate('loading')].helpers({
log: function () { log: function () {
console.log('loading…') console.log('loading…')
} }
}) });

View file

@ -20,14 +20,14 @@ Template[getTemplate('mobile_nav')].helpers({
}); });
Template[getTemplate('mobile_nav')].events({ Template[getTemplate('mobile_nav')].events({
'click .dropdown-sub-level':function(event){ 'click .dropdown-sub-level': function () {
$('body').toggleClass('mobile-nav-open'); $('body').toggleClass('mobile-nav-open');
} }
}); });
Template[getTemplate('mobile_nav')].rendered = function () { Template[getTemplate('mobile_nav')].rendered = function () {
$('.mobile-nav .dropdown-menu').hide(); $('.mobile-nav .dropdown-menu').hide();
} };
Template[getTemplate('mobile_nav')].events({ Template[getTemplate('mobile_nav')].events({
'click .dropdown-top-level': function (e) { 'click .dropdown-top-level': function (e) {

View file

@ -62,7 +62,7 @@ Template[getTemplate('nav')].events({
e.preventDefault(); e.preventDefault();
Router.go('/account'); Router.go('/account');
}, },
'click #login-name-link': function(e){ 'click #login-name-link': function(){
if(Meteor.user() && !$('account-link').exists()){ if(Meteor.user() && !$('account-link').exists()){
$('#login-buttons-logout').before('<a href="/users/'+Meteor.user().slug+'" class="account-link button">View Profile</a>'); $('#login-buttons-logout').before('<a href="/users/'+Meteor.user().slug+'" class="account-link button">View Profile</a>');
$('#login-buttons-logout').before('<a href="/account" class="account-link button">Edit Account</a>'); $('#login-buttons-logout').before('<a href="/account" class="account-link button">Edit Account</a>');

View file

@ -1,7 +1,7 @@
var filteredModules = function (group) { var filteredModules = function (group) {
// return the modules whose positions start with group // return the modules whose positions start with group
return _.filter(postModules, function(module){return module.position.indexOf(group) == 0}); return _.filter(postModules, function(module){return module.position.indexOf(group) == 0});
} };
var post = {}; var post = {};

View file

@ -11,10 +11,10 @@ Template[getTemplate('post_page')].helpers({
comment_list: function () { comment_list: function () {
return getTemplate('comment_list'); return getTemplate('comment_list');
} }
}) });
Template[getTemplate('post_page')].rendered = function(){ Template[getTemplate('post_page')].rendered = function(){
$('body').scrollTop(0); $('body').scrollTop(0);
if(this.data) // XXX if(this.data) // XXX
document.title = $(".post-title").text(); document.title = $(".post-title").text();
} };

View file

@ -32,7 +32,7 @@ Template[getTemplate('user_edit')].helpers({
hasPassword: function () { hasPassword: function () {
return hasPassword(Meteor.user()); return hasPassword(Meteor.user());
} }
}) });
Template[getTemplate('user_edit')].events({ Template[getTemplate('user_edit')].events({
'submit #account-form': function(e){ 'submit #account-form': function(e){

View file

@ -66,4 +66,4 @@ Template[getTemplate('user_item')].events({
if(confirm(i18n.t("Are you sure you want to delete ")+getDisplayName(instance.data)+"?")) if(confirm(i18n.t("Are you sure you want to delete ")+getDisplayName(instance.data)+"?"))
Meteor.users.remove(instance.data._id); Meteor.users.remove(instance.data._id);
} }
}) });

View file

@ -3,7 +3,7 @@ Template[getTemplate('user_profile')].created = function () {
Session.set('upvotedPostsShown', 5); Session.set('upvotedPostsShown', 5);
Session.set('downvotedPostsShown', 5); Session.set('downvotedPostsShown', 5);
Session.set('commentsShown', 5); Session.set('commentsShown', 5);
} };
Template[getTemplate('user_profile')].helpers({ Template[getTemplate('user_profile')].helpers({
avatarUrl: function() { avatarUrl: function() {

View file

@ -17,7 +17,7 @@ Comments = new Meteor.Collection("comments", {
optional: true optional: true
}, },
body: { body: {
type: String, type: String
}, },
htmlBody: { htmlBody: {
type: String, type: String,
@ -102,9 +102,9 @@ Comments.before.update(function (userId, doc, fieldNames, modifier, options) {
Meteor.methods({ Meteor.methods({
comment: function(postId, parentCommentId, text){ comment: function(postId, parentCommentId, text){
var user = Meteor.user(), var user = Meteor.user(),
post=Posts.findOne(postId), post = Posts.findOne(postId),
postUser=Meteor.users.findOne(post.userId), postUser = Meteor.users.findOne(post.userId),
timeSinceLastComment=timeSinceLast(user, Comments), timeSinceLastComment = timeSinceLast(user, Comments),
commentInterval = Math.abs(parseInt(getSetting('commentInterval',15))), commentInterval = Math.abs(parseInt(getSetting('commentInterval',15))),
now = new Date(); now = new Date();
@ -157,13 +157,13 @@ Meteor.methods({
var notificationProperties = { var notificationProperties = {
comment: _.pick(comment, '_id', 'userId', 'author', 'body'), comment: _.pick(comment, '_id', 'userId', 'author', 'body'),
post: _.pick(post, '_id', 'title', 'url') post: _.pick(post, '_id', 'title', 'url')
} };
if(!this.isSimulation){ if(!this.isSimulation){
if(parentCommentId){ if(parentCommentId){
// child comment // child comment
var parentComment=Comments.findOne(parentCommentId); var parentComment = Comments.findOne(parentCommentId);
var parentUser=Meteor.users.findOne(parentComment.userId); var parentUser = Meteor.users.findOne(parentComment.userId);
notificationProperties.parentComment = _.pick(parentComment, '_id', 'userId', 'author'); notificationProperties.parentComment = _.pick(parentComment, '_id', 'userId', 'author');
@ -187,7 +187,7 @@ Meteor.methods({
return comment; return comment;
}, },
removeComment: function(commentId){ removeComment: function(commentId){
var comment=Comments.findOne(commentId); var comment = Comments.findOne(commentId);
if(canEdit(Meteor.user(), comment)){ if(canEdit(Meteor.user(), comment)){
// decrement post comment count and remove user ID from post // decrement post comment count and remove user ID from post
Posts.update(comment.postId, { Posts.update(comment.postId, {

View file

@ -27,5 +27,5 @@ Invites = new Meteor.Collection("invites", {
Invites.deny({ Invites.deny({
insert: function(){ return true; }, insert: function(){ return true; },
update: function(){ return true; }, update: function(){ return true; },
remove: function(){ return true; }, remove: function(){ return true; }
}); });

View file

@ -38,7 +38,7 @@ createNotification = function(event, properties, userToNotify) {
properties: properties, properties: properties,
read: false read: false
}; };
var newNotificationId=Notifications.insert(notification); var newNotificationId = Notifications.insert(notification);
// 2. Send notification by email (if on server) // 2. Send notification by email (if on server)
if(Meteor.isServer && getUserSetting('notifications.replies', false, userToNotify)){ if(Meteor.isServer && getUserSetting('notifications.replies', false, userToNotify)){
@ -56,14 +56,14 @@ buildSiteNotification = function (notification) {
post = notification.properties.post, post = notification.properties.post,
userToNotify = Meteor.users.findOne(notification.userId), userToNotify = Meteor.users.findOne(notification.userId),
template, template,
html html;
var properties = { var properties = {
profileUrl: getProfileUrlById(comment.userId), profileUrl: getProfileUrlById(comment.userId),
author: comment.author, author: comment.author,
postCommentUrl: getPostCommentUrl(post._id, comment._id), postCommentUrl: getPostCommentUrl(post._id, comment._id),
postTitle: post.title postTitle: post.title
} };
switch(event){ switch(event){
case 'newReply': case 'newReply':

View file

@ -13,7 +13,7 @@ postSchemaObject = {
}, },
title: { title: {
type: String, type: String,
label: "Title", label: "Title"
}, },
url: { url: {
type: String, type: String,
@ -119,7 +119,7 @@ clickedPosts = [];
getPostProperties = function(post) { getPostProperties = function(post) {
var postAuthor = Meteor.users.findOne(post.userId) var postAuthor = Meteor.users.findOne(post.userId);
var p = { var p = {
postAuthorName : getDisplayName(postAuthor), postAuthorName : getDisplayName(postAuthor),
postTitle : cleanUp(post.title), postTitle : cleanUp(post.title),
@ -136,7 +136,7 @@ getPostProperties = function(post) {
p.htmlBody = post.htmlBody; p.htmlBody = post.htmlBody;
return p; return p;
} };
getPostPageUrl = function(post){ getPostPageUrl = function(post){
return getSiteUrl()+'posts/'+post._id; return getSiteUrl()+'posts/'+post._id;
@ -149,7 +149,7 @@ getPostEditUrl = function(id){
// for a given post, return its link if it has one, or else its post page URL // for a given post, return its link if it has one, or else its post page URL
getPostLink = function (post) { getPostLink = function (post) {
return !!post.url ? getOutgoingUrl(post.url) : getPostPageUrl(post); return !!post.url ? getOutgoingUrl(post.url) : getPostPageUrl(post);
} };
Posts.before.insert(function (userId, doc) { Posts.before.insert(function (userId, doc) {
if(Meteor.isServer && !!doc.body) if(Meteor.isServer && !!doc.body)
@ -222,8 +222,8 @@ Meteor.methods({
commentsCount: 0, commentsCount: 0,
baseScore: 0, baseScore: 0,
score: 0, score: 0,
inactive: false, inactive: false
} };
// UserId // UserId
if(isAdmin(Meteor.user()) && !!post.userId){ // only let admins post as other users if(isAdmin(Meteor.user()) && !!post.userId){ // only let admins post as other users
@ -288,7 +288,7 @@ Meteor.methods({
var postedAt = new Date(); // default to current date and time var postedAt = new Date(); // default to current date and time
if(isAdmin(Meteor.user()) && typeof customPostedAt !== 'undefined') // if user is admin and a custom datetime has been set if(isAdmin(Meteor.user()) && typeof customPostedAt !== 'undefined') // if user is admin and a custom datetime has been set
var postedAt = customPostedAt; postedAt = customPostedAt;
Posts.update(post._id, {$set: {postedAt: postedAt}}); Posts.update(post._id, {$set: {postedAt: postedAt}});
}, },
@ -323,7 +323,7 @@ Meteor.methods({
// if(!this.isSimulation) { // if(!this.isSimulation) {
// Comments.remove({post: postId}); // Comments.remove({post: postId});
// } // }
// NOTE: actually, keep comments afer all // NOTE: actually, keep comments after all
// decrement post count // decrement post count
var post = Posts.findOne({_id: postId}); var post = Posts.findOne({_id: postId});

View file

@ -62,7 +62,7 @@ settingsSchemaObject = {
label: view.label label: view.label
} }
}) })
}, }
}, },
postInterval: { postInterval: {
type: Number, type: Number,

View file

@ -76,7 +76,7 @@ analyticsRequest = function() {
// Google Analytics // Google Analytics
if (typeof window.ga !== 'undefined'){ if (typeof window.ga !== 'undefined'){
ga('send', 'pageview', { ga('send', 'pageview', {
'page': window.location.pathname, 'page': window.location.pathname
}); });
} }

View file

@ -1,6 +1,6 @@
cl = function(something){ cl = function(something){
console.log(l); console.log(l);
} };
getCurrentTemplate = function() { getCurrentTemplate = function() {
return Router.current().lookupTemplate(); return Router.current().lookupTemplate();
@ -111,7 +111,7 @@ sanitize = function (s) {
// console.log(s) // console.log(s)
} }
return s; return s;
} };
stripHTML = function(s){ stripHTML = function(s){
return s.replace(/<(?:.|\n)*?>/gm, ''); return s.replace(/<(?:.|\n)*?>/gm, '');
}; };

View file

@ -22,7 +22,7 @@ getUserName = function(user){
return user.services.twitter.screenName return user.services.twitter.screenName
} }
catch (error){ catch (error){
console.log(error) console.log(error);
return null; return null;
} }
}; };
@ -143,17 +143,17 @@ setUserSetting = function (setting, value, userArgument) {
} }
if(!user) if(!user)
throw new Meteor.Error(500, 'User not defined') throw new Meteor.Error(500, 'User not defined');
console.log('Setting user setting "'+setting+'" to "'+value+'" for '+getUserName(user)) console.log('Setting user setting "'+setting+'" to "'+value+'" for '+getUserName(user));
var find = {_id: user._id}; var find = {_id: user._id};
var field = {}; var field = {};
field['profile.'+setting] = value; field['profile.'+setting] = value;
var options = {$set: field}; var options = {$set: field};
console.log(find) console.log(find);
console.log(options) console.log(options);
var result = Meteor.users.update(find, options, {validate: false}); var result = Meteor.users.update(find, options, {validate: false});
} };
getProperty = function(object, property){ getProperty = function(object, property){
// recursive function to get nested properties // recursive function to get nested properties

View file

@ -29,7 +29,7 @@
var removeVote = function (userId, itemId, collection, upOrDown) { var removeVote = function (userId, itemId, collection, upOrDown) {
var field = 'votes.' + upOrDown + 'voted' + collection; var field = 'votes.' + upOrDown + 'voted' + collection;
var remove = {}; var remove = {};
remove[field] = {itemId: itemId} remove[field] = {itemId: itemId};
Meteor.users.update({_id: userId}, { Meteor.users.update({_id: userId}, {
$pull: remove $pull: remove
}); });

View file

@ -68,7 +68,7 @@ Meteor.methods({
actionLink : user ? getSigninUrl() : getSignupUrl(), actionLink : user ? getSigninUrl() : getSignupUrl(),
invitedBy : getDisplayName(currentUser), invitedBy : getDisplayName(currentUser),
profileUrl : getProfileUrl(currentUser) profileUrl : getProfileUrl(currentUser)
} };
Meteor.setTimeout(function () { Meteor.setTimeout(function () {
buildAndSendEmail(userEmail, emailSubject, getTemplate('emailInvite'), emailProperties); buildAndSendEmail(userEmail, emailSubject, getTemplate('emailInvite'), emailProperties);

View file

@ -18,7 +18,7 @@ var runMigration = function (migrationName) {
if (migration){ if (migration){
if(typeof migration.finishedAt === 'undefined'){ if(typeof migration.finishedAt === 'undefined'){
// if migration exists but hasn't finished, remove it and start fresh // if migration exists but hasn't finished, remove it and start fresh
console.log('!!! Found incomplete migration "'+migrationName+'", removing and running again.') console.log('!!! Found incomplete migration "'+migrationName+'", removing and running again.');
Migrations.remove({name: migrationName}); Migrations.remove({name: migrationName});
}else{ }else{
// do nothing // do nothing
@ -39,7 +39,7 @@ var runMigration = function (migrationName) {
console.log("//----------------------------------------------------------------------//"); console.log("//----------------------------------------------------------------------//");
console.log("//------------// Ending "+migrationName+" Migration //-----------//"); console.log("//------------// Ending "+migrationName+" Migration //-----------//");
console.log("//----------------------------------------------------------------------//"); console.log("//----------------------------------------------------------------------//");
} };
var migrationsList = { var migrationsList = {
updatePostStatus: function () { updatePostStatus: function () {
@ -119,7 +119,7 @@ var migrationsList = {
i++; i++;
console.log('> Updating user '+user._id+' ('+user.username+')'); console.log('> Updating user '+user._id+' ('+user.username+')');
var properties = {} var properties = {};
// update user slug // update user slug
if(getUserName(user)) if(getUserName(user))
properties.slug = slugify(getUserName(user)); properties.slug = slugify(getUserName(user));
@ -219,7 +219,7 @@ var migrationsList = {
console.log("Posts: "+post.title); console.log("Posts: "+post.title);
var createdAt = new Date(post.createdAt); var createdAt = new Date(post.createdAt);
var submitted = new Date(post.submitted); var submitted = new Date(post.submitted);
console.log(createdAt) console.log(createdAt);
Posts.update(post._id, { $set: { 'createdAt': createdAt, submitted: submitted}}, {multi: true, validate: false}); Posts.update(post._id, { $set: { 'createdAt': createdAt, submitted: submitted}}, {multi: true, validate: false});
console.log("---------------------"); console.log("---------------------");
} }
@ -365,4 +365,4 @@ var migrationsList = {
}); });
return i; return i;
} }
} };

View file

@ -40,7 +40,7 @@ buildEmailNotification = function (notification) {
subject: subject, subject: subject,
html: html html: html
} }
} };
newPostNotification = function(post, excludedIDs){ newPostNotification = function(post, excludedIDs){
var excludedIDs = typeof excludedIDs == 'undefined' ? [] : excludedIDs; var excludedIDs = typeof excludedIDs == 'undefined' ? [] : excludedIDs;
@ -54,7 +54,7 @@ newPostNotification = function(post, excludedIDs){
if(excludedIDs.indexOf(user._id) == -1) if(excludedIDs.indexOf(user._id) == -1)
sendEmail(getEmail(user), subject, html); sendEmail(getEmail(user), subject, html);
}); });
} };
Meteor.methods({ Meteor.methods({
unsubscribeUser : function(hash){ unsubscribeUser : function(hash){

View file

@ -1,10 +1,10 @@
Meteor.startup(function () { Meteor.startup(function () {
var scoreInterval = getSetting("scoreUpdateInterval") || 30; var scoreInterval = getSetting("scoreUpdateInterval") || 30;
if(scoreInterval>0){ if (scoreInterval > 0) {
// active items get updated every N seconds // active items get updated every N seconds
intervalId=Meteor.setInterval(function () { intervalId = Meteor.setInterval(function () {
var updatedPosts = 0; var updatedPosts = 0;
var updatedComments = 0; var updatedComments = 0;
// console.log('tick ('+scoreInterval+')'); // console.log('tick ('+scoreInterval+')');
@ -19,7 +19,7 @@ Meteor.startup(function () {
}, scoreInterval * 1000); }, scoreInterval * 1000);
// inactive items get updated every hour // inactive items get updated every hour
inactiveIntervalId=Meteor.setInterval(function () { inactiveIntervalId = Meteor.setInterval(function () {
var updatedPosts = 0; var updatedPosts = 0;
var updatedComments = 0; var updatedComments = 0;
Posts.find({'inactive': true}).forEach(function (post) { Posts.find({'inactive': true}).forEach(function (post) {

View file

@ -79,7 +79,7 @@ Accounts.onCreateUser(function(options, user){
var emailProperties = { var emailProperties = {
profileUrl: getProfileUrl(user), profileUrl: getProfileUrl(user),
username: getUserName(user) username: getUserName(user)
} };
var html = getEmailTemplate('emailNewUser')(emailProperties); var html = getEmailTemplate('emailNewUser')(emailProperties);
sendEmail(getEmail(admin), 'New user account: '+getUserName(user), buildEmailTemplate(html)); sendEmail(getEmail(admin), 'New user account: '+getUserName(user), buildEmailTemplate(html));
} }