Merge branch 'AdmitHub-telescope-master-profile-hooks'

This commit is contained in:
Sacha Greif 2014-12-04 13:04:45 +09:00
commit f2965feb5a
9 changed files with 62 additions and 17 deletions

View file

@ -0,0 +1,3 @@
<template name="postAuthor">
By <a class="post-author" href="{{profileUrl}}">{{authorName}}</a>,
</template>

View file

@ -0,0 +1,11 @@
Template[getTemplate('postAuthor')].helpers({
authorName: function(){
return getAuthorName(this);
},
profileUrl: function(){
// note: we don't want the post to be re-rendered every time user properties change
var user = Meteor.users.findOne(this.userId, {reactive: false});
if(user)
return getProfileUrl(user);
}
})

View file

@ -1,8 +1,10 @@
<template name="postInfo">
<div class="post-meta-item">
<span class="points">{{baseScore}} <span class="unit">{{pointsUnitDisplayText}} </span></span>by <a class="post-author" href="{{profileUrl}}">{{authorName}}</a> <span class="post-time">{{timeAgo ago}}</span>
<span class="points">{{baseScore}}</span>
<span class="unit">{{pointsUnitDisplayText}}</span>
<span class="post-time">{{timeAgo ago}}</span>
{{#if can_edit}}
| <a href="/posts/{{_id}}/edit" class="edit-link goto-edit">{{_ "edit"}}</a>
{{/if}}
</div>
</template>
</template>

View file

@ -5,18 +5,12 @@ Template[getTemplate('postInfo')].helpers({
can_edit: function(){
return canEdit(Meteor.user(), this);
},
authorName: function(){
return getAuthorName(this);
},
ago: function(){
// if post is approved show submission time, else show creation time.
time = this.status == STATUS_APPROVED ? this.postedAt : this.createdAt;
return time;
},
profileUrl: function(){
// note: we don't want the post to be re-rendered every time user properties change
var user = Meteor.users.findOne(this.userId, {reactive: false});
if(user)
return getProfileUrl(user);
getTemplate: function() {
return getTemplate("postAuthor");
}
});

View file

@ -71,6 +71,10 @@ Template[getTemplate('user_edit')].events({
});
}
update = userEditClientCallbacks.reduce(function(result, currentFunction) {
return currentFunction(user, result);
}, update);
Meteor.users.update(user._id, {
$set: update
}, function(error){
@ -89,4 +93,4 @@ Template[getTemplate('user_edit')].events({
}
});
});

View file

@ -1,6 +1,5 @@
var Schema = {};
Schema.User = new SimpleSchema({
var userSchemaObj = {
_id: {
type: String,
optional: true
@ -42,7 +41,14 @@ Schema.User = new SimpleSchema({
optional: true,
blackbox: true
}
};
// add any extra properties to postSchemaObject (provided by packages for example)
_.each(addToUserSchema, function(item){
userSchemaObj[item.propertyName] = item.propertySchema;
});
Schema.User = new SimpleSchema(userSchemaObj);
// Meteor.users.attachSchema(Schema.User);

View file

@ -93,7 +93,12 @@ getCurrentUserEmail = function(){
return Meteor.user() ? getEmail(Meteor.user()) : '';
};
userProfileComplete = function(user) {
return !!getEmail(user);
for (var i = 0; i < userProfileCompleteChecks.length; i++) {
if (!userProfileCompleteChecks[i](user)) {
return false;
}
}
return true;
};
findLast = function(user, collection){

View file

@ -4,6 +4,7 @@
addToPostSchema = [];
addToCommentsSchema = [];
addToSettingsSchema = [];
addToUserSchema = [];
SimpleSchema.extendOptions({
editable: Match.Optional(Boolean), // editable: true means the field can be edited by the document's owner
@ -155,13 +156,17 @@ postHeading = [
template: 'postDomain',
order: 5
}
]
];
postMeta = [
{
template: 'postInfo',
template: 'postAuthor',
order: 1
},
{
template: 'postInfo',
order: 2
},
{
template: 'postCommentsLink',
order: 3
@ -193,6 +198,16 @@ commentEditClientCallbacks = [];
commentEditMethodCallbacks = []; // not used yet
commentAfterEditMethodCallbacks = []; // not used yet
userEditRenderedCallbacks = [];
userEditClientCallbacks = [];
userProfileCompleteChecks = [
function(user) {
return !!getEmail(user) && !!user.username;
}
];
// ------------------------------ Dynamic Templates ------------------------------ //

View file

@ -20,6 +20,7 @@ Package.onUse(function (api) {
'addToPostSchema',
'addToCommentsSchema',
'addToSettingsSchema',
'addToUserSchema',
'preloadSubscriptions',
'primaryNav',
'secondaryNav',
@ -50,10 +51,14 @@ Package.onUse(function (api) {
'commentEditClientCallbacks',
'commentEditMethodCallbacks',
'commentAfterEditMethodCallbacks',
'userEditRenderedCallbacks',
'userEditClientCallbacks',
'userProfileCompleteChecks',
'getTemplate',
'templates',
'themeSettings'
]);
});
});