Use currentUser builtin to simplify templates.

* {{currentUser.isAdmin}} instead of custom helpers.
* drop currentUserIsAdmin session variable.

relies on fix to meteor's handlebars evaluator in 0.4.2.
This commit is contained in:
Matt DeBergalis 2012-09-26 22:11:44 -07:00
parent 2a2cfbc40d
commit e07daec6f3
17 changed files with 33 additions and 65 deletions

View file

@ -1,7 +1,4 @@
Meteor.subscribe('users', function(){
// once we've subscribed, set a session variable to check if the current user is an admin
Session.set('currentUserIsAdmin', (Meteor.user() && !Meteor.user().loading) ? isAdmin(Meteor.user()) : false );
});
Meteor.subscribe('users');
Posts = new Meteor.Collection('posts');
Meteor.subscribe('posts');
@ -15,10 +12,10 @@ Meteor.subscribe('comments', function() {
Settings = new Meteor.Collection('settings');
Meteor.subscribe('settings', function(){
if(proxinoKey=getSetting('proxinoKey')){
if((proxinoKey=getSetting('proxinoKey'))){
Proxino.key = proxinoKey;
Proxino.track_errors();
}
}
});
Session.set('state', 'list');

View file

@ -1,16 +1,14 @@
<template name="comment_form">
{{#if show_comment_form}}
<div class="comment-new">
<form>
{{#constant}}
<div class="comment-new">
<form>
{{#constant}}
<div class="comment-field" id="editor">
<textarea id="comment" rows="3" autofocus="autofocus"></textarea>
<textarea id="comment" rows="3" autofocus="autofocus"></textarea>
</div>
{{/constant}}
<div class="comment-submit">
<input type="submit" class="button" value="Add Comment" />
</div>
</form>
</div>
{{/if}}
</template>
{{/constant}}
<div class="comment-submit">
<input type="submit" class="button" value="Add Comment" />
</div>
</form>
</div>
</template>

View file

@ -1,9 +1,3 @@
Template.comment_form.helpers({
show_comment_form: function(){
return Meteor.user() !== null;
}
});
Template.comment_form.rendered = function(){
if(Meteor.user() && !this.editor){
this.editor = new EpicEditor(EpicEditorOptions).load();
@ -35,4 +29,3 @@ Template.comment_form.events = {
}
};

View file

@ -21,7 +21,7 @@
{{#if can_edit}}
| <a class="edit-link" href="/comments/{{_id}}/edit">Edit</a>
{{/if}}
{{#if is_admin}}
{{#if currentUser.isAdmin}}
| <a class="queue-comment" href="#">queue</a>
| <span>{{full_date}}</span>
{{/if}}

View file

@ -99,10 +99,6 @@
}
}
,is_admin: function(){
return currentUserIsAdmin();
}
,repress_recursion: function(){
if(window.repress_recursion){
return true;

View file

@ -5,11 +5,17 @@
{{> post_item}}
{{/with}}
{{/if}}
{{#if comment}}
{{#with comment}}
<ul class="selected-comment">
{{> comment_item}}
</ul>
{{/with}}
{{> comment_form}}
{{/if}}
{{#if currentUser}}
{{> comment_form}}
{{/if}}
</div>
</template>

View file

@ -3,7 +3,7 @@
<ul>
<li><a class="top" href="/top">Top</a></li>
<li><a class="new" href="/new">New</a></li>
{{#if is_admin}}
{{#if currentUser.isAdmin}}
<li><a class="users" href="/users">Users</a></li>
<li><a class="settings" href="/settings">Settings</a></li>
{{/if}}
@ -21,7 +21,7 @@
<ul class="nav site-nav desktop">
<li><a class="top" href="/top">Top</a></li>
<li><a class="new" href="/new">New</a></li>
{{#if is_admin}}
{{#if currentUser.isAdmin}}
<li><a class="users" href="/users">Users</a></li>
<li><a class="settings" href="/settings">Settings</a></li>
{{/if}}
@ -30,13 +30,13 @@
<li><a href="jobs">Jobs</a></li> -->
</ul>
<ul class="nav user-nav desktop">
<!-- {{#if logged_in}}
<!-- {{#if currentUser}}
<li><a id="logout" href="logout">Log Out</a></li>
{{else}}
<li><a id="signup" href="signup">Sign Up</a></li>
<li><a id="signin" href="signin">Sign In</a></li>
{{/if}} -->
{{#if logged_in}}
{{#if currentUser}}
<li><a id="submit" class="submit button" href="/submit">Post</a></li>
{{/if}}
</ul>

View file

@ -1,12 +1,3 @@
Template.nav.helpers({
logged_in: function(){
return Meteor.user() !== null;
}
,is_admin: function(){
return currentUserIsAdmin();
}
})
Template.nav.events = {
'click #logout': function(event){
event.preventDefault();

View file

@ -40,7 +40,7 @@
{{#if can_edit}}
| <a href="/posts/{{_id}}/edit" class="edit-link goto-edit">Edit</a>
{{/if}}
{{#if is_admin}}
{{#if currentUser.isAdmin}}
| votes: {{votes}}, baseScore: {{baseScore}}, score: {{short_score}}
{{/if}}
</p>

View file

@ -108,10 +108,6 @@ Template.post_item.can_edit = function(){
return false;
};
Template.post_item.is_admin = function(){
return currentUserIsAdmin();
};
Template.post_item.author = function(){
if(this.user_id && Meteor.users.findOne(this.user_id)){
return Meteor.users.findOne(this.user_id).username;

View file

@ -3,7 +3,9 @@
{{#with post}}
{{> post_item}}
{{/with}}
{{> comment_form}}
{{#if currentUser}}
{{> comment_form}}
{{/if}}
{{> comment_list}}
</div>
</template>

View file

@ -6,7 +6,7 @@
{{#if no_settings}}
<p>No settings yet.</p>
{{/if}}
{{#if currentUserIsAdmin}}
{{#if currentUser.isAdmin}}
<div class="control-group">
<label>Site Title</label>
<div class="controls"><input id="title" name="title" type="text" value="{{title}}" /></div>

View file

@ -41,9 +41,6 @@ Template.settings.events = {
}
};
Template.settings.currentUserIsAdmin = function(){
return currentUserIsAdmin();
}
Template.settings.no_settings = function(){
if(Settings.find().fetch()[0]){
return false;

View file

@ -14,6 +14,6 @@
</td>
<td><a href="#">{{comments_count}}</a></td>
<td>{{karma}}</td>
<td>{{#if is_admin}}<i class="icon-check"></i>{{/if}}</td>
<td>{{#if currentUser.isAdmin}}<i class="icon-check"></i>{{/if}}</td>
</tr>
</template>

View file

@ -34,7 +34,3 @@ Template.user_item.comments_count = function(){
// Posts.find({'user_id':this._id}).forEach(function(post){console.log(post.headline);});
return Comments.find({'user_id':this._id}).count();
}
Template.user_item.is_admin = function(){
return isAdmin(this);
}

View file

@ -8,10 +8,6 @@ var breakTag = '<br />';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
currentUserIsAdmin = function(){
return Session.get('currentUserIsAdmin');
}
getSetting = function(setting){
var settings=Settings.find().fetch()[0];
if(settings){

View file

@ -2,7 +2,7 @@
"meteor": {
"git": "https://github.com/meteor/meteor.git",
"branch": "auth",
"commit": "687407a4d3be776635d3b59242e8304d9e29abdb"
"commit": "d2616308361203215c122f962ae9a5c763b5ca09"
},
"dependencies": {
"basePackages": {