improved user dashboard even more!

This commit is contained in:
Sacha Greif 2013-11-08 11:10:23 +09:00
parent c164e67572
commit 1c5c8fb575
8 changed files with 57 additions and 15 deletions

View file

@ -1,3 +1,11 @@
## v0.7.1
* Added karma redistribution.
* Improved user dashboard.
* Improved user profiles.
Note: run the "update user profile" script from the toolbox after updating.
## v0.7 “IronScope”
#### Huge update!

View file

@ -5,15 +5,15 @@
<td>{{createdAtFormatted}}</td>
<td>{{profile.email}}</td>
<td>
<a href="#">{{postsCount}}</a>
<a href="#">{{postCount}}</a>
<ul class="posts-list hidden">
{{#each posts}}
<li><a href="/posts/{{_id}}">{{headline}}</a></li>
{{/each}}
</ul>
</td>
<td><a href="#">{{commentsCount}}</a></td>
<td>{{karma}}</td>
<td><a href="#">{{commentCount}}</a></td>
<td>{{getKarma}}</td>
<td>{{#if isInvited}}<a class="uninvite-link" href="#"><i class="icon-check"></i>Uninvite</a>{{else}}<a href="#" class="invite-link">Invite</a>{{/if}}</td>
<td>{{#if userIsAdmin}}<a class="unadmin-link" href="#"><i class="icon-check unadmin-link"></i>Unadmin</a>{{else}}<a href="#" class="admin-link">Make admin</a>{{/if}}</td>
<td><a class="delete-link" href="#">Delete User</a></td>

View file

@ -14,21 +14,17 @@ Template.user_item.helpers({
posts: function(){
return Posts.find({'userId':this._id});
},
postsCount: function(){
return Posts.find({'userId':this._id}).count();
},
comments: function(){
return Comments.find({'userId':this._id});
},
commentsCount: function(){
// Posts.find({'user_id':this._id}).forEach(function(post){console.log(post.headline);});
return Comments.find({'userId':this._id}).count();
},
userIsAdmin: function(){
return isAdmin(this);
},
profileUrl: function () {
return getProfileUrl(this);
},
getKarma: function() {
return Math.round(100*this.karma)/100;
}
});

View file

@ -15,6 +15,8 @@
<a class="{{activeClass 'createdAt'}}" href="{{sortBy 'createdAt'}}">Created</a>
<a class="{{activeClass 'karma'}}" href="{{sortBy 'karma'}}">Karma</a>
<a class="{{activeClass 'username'}}" href="{{sortBy 'username'}}">Username</a>
<a class="{{activeClass 'postCount'}}" href="{{sortBy 'postCount'}}">Posts</a>
<a class="{{activeClass 'commentCount'}}" href="{{sortBy 'commentCount'}}">Comments</a>
</p>
</div>
<table>

View file

@ -59,6 +59,9 @@ Meteor.methods({
var newCommentId=Comments.insert(comment);
// increment comment count
Meteor.users.update({_id: userId}, {$inc: {commentCount: 1}});
// extend comment with newly created _id
comment = _.extend(comment, {_id: newCommentId});
@ -123,6 +126,10 @@ Meteor.methods({
if(canEdit(Meteor.user(), comment)){
// decrement post comment count
Posts.update(comment.post, {$inc: {comments: -1}});
// decrement user comment count
Meteor.users.update({_id: comment.userId}, {$inc: {commentCount: -1}});
// note: should we also decrease user's comment karma ?
Comments.remove(commentId);
}else{

View file

@ -86,6 +86,9 @@ Meteor.methods({
postId = Posts.insert(post);
// increment posts count
Meteor.users.update({_id: userId}, {$inc: {postCount: 1}});
post = _.extend(post, {_id: postId});
var postAuthor = Meteor.users.findOne(post.userId);
@ -124,9 +127,13 @@ Meteor.methods({
},
deletePostById: function(postId) {
// remove post comments
if(!this.isSimulation) {
Comments.remove({post: postId});
}
// if(!this.isSimulation) {
// Comments.remove({post: postId});
// }
// NOTE: actually, keep comments afer all
// decrement post count
Meteor.users.update({_id: post.userId}, {$inc: {postCount: -1}});
Posts.remove(postId);
}
});

View file

@ -94,6 +94,11 @@ getUsersParameters = function(filterBy, sortBy, limit) {
case 'karma':
sort = {karma: -1};
break;
case 'postCount':
sort = {postCount: -1};
break;
case 'commentCount':
sort = {commentCount: -1};
}
return {
find: find,

View file

@ -17,8 +17,14 @@ Meteor.methods({
Meteor.users.update({}, {$inc:{invitesCount: 1}}, {multi:true});
},
updateUserProfiles: function () {
console.log('//--------------------------//\nUpdating user profiles…')
if(isAdmin(Meteor.user())){
Meteor.users.find().forEach(function(user){
var allUsers = Meteor.users.find();
console.log('> Found '+allUsers.count()+' users.\n');
allUsers.forEach(function(user){
console.log('> Updating user '+user._id+' ('+user.username+')');
// update user slug
if(getUserName(user))
Meteor.users.update(user._id, {$set:{slug: slugify(getUserName(user))}});
@ -26,8 +32,19 @@ Meteor.methods({
// update user isAdmin flag
if(typeof user.isAdmin === 'undefined')
Meteor.users.update(user._id, {$set: {isAdmin: false}});
// update postCount
var postsByUser = Posts.find({userId: user._id});
Meteor.users.update(user._id, {$set: {postCount: postsByUser.count()}});
console.log(postsByUser.count())
// update commentCount
var commentsByUser = Comments.find({userId: user._id});
Meteor.users.update(user._id, {$set: {commentCount: commentsByUser.count()}});
console.log(commentsByUser.count())
});
}
}
console.log('Done updating user profiles.\n//--------------------------//')
},
updatePostsSlugs: function () {
//TODO