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"> <template name="postInfo">
<div class="post-meta-item"> <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}} {{#if can_edit}}
| <a href="/posts/{{_id}}/edit" class="edit-link goto-edit">{{_ "edit"}}</a> | <a href="/posts/{{_id}}/edit" class="edit-link goto-edit">{{_ "edit"}}</a>
{{/if}} {{/if}}
</div> </div>
</template> </template>

View file

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

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, { Meteor.users.update(user._id, {
$set: update $set: update
}, function(error){ }, function(error){
@ -89,4 +93,4 @@ Template[getTemplate('user_edit')].events({
} }
}); });

View file

@ -1,6 +1,5 @@
var Schema = {}; var Schema = {};
var userSchemaObj = {
Schema.User = new SimpleSchema({
_id: { _id: {
type: String, type: String,
optional: true optional: true
@ -42,7 +41,14 @@ Schema.User = new SimpleSchema({
optional: true, optional: true,
blackbox: 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); // Meteor.users.attachSchema(Schema.User);

View file

@ -93,7 +93,12 @@ getCurrentUserEmail = function(){
return Meteor.user() ? getEmail(Meteor.user()) : ''; return Meteor.user() ? getEmail(Meteor.user()) : '';
}; };
userProfileComplete = function(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){ findLast = function(user, collection){

View file

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

View file

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