From e07daec6f3c9c87429f409153cc6d8c84b982347 Mon Sep 17 00:00:00 2001
From: Matt DeBergalis
Date: Wed, 26 Sep 2012 22:11:44 -0700
Subject: [PATCH] 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.
---
client/app.js | 9 +++------
client/templates/comment_form.html | 24 +++++++++++-------------
client/templates/comment_form.js | 7 -------
client/templates/comment_item.html | 2 +-
client/templates/comment_item.js | 4 ----
client/templates/comment_page.html | 8 +++++++-
client/templates/nav.html | 8 ++++----
client/templates/nav.js | 9 ---------
client/templates/post_item.html | 2 +-
client/templates/post_item.js | 4 ----
client/templates/post_page.html | 4 +++-
client/templates/settings.html | 2 +-
client/templates/settings.js | 3 ---
client/templates/user_item.html | 2 +-
client/templates/user_item.js | 4 ----
lib/helpers.js | 4 ----
smart.lock | 2 +-
17 files changed, 33 insertions(+), 65 deletions(-)
diff --git a/client/app.js b/client/app.js
index 6deaf26e8..899768915 100644
--- a/client/app.js
+++ b/client/app.js
@@ -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');
diff --git a/client/templates/comment_form.html b/client/templates/comment_form.html
index 929cdbbf0..4ec82dd96 100644
--- a/client/templates/comment_form.html
+++ b/client/templates/comment_form.html
@@ -1,16 +1,14 @@
-{{#if show_comment_form}}
-
+
diff --git a/client/templates/comment_form.js b/client/templates/comment_form.js
index 99a52ede4..ea2e6030d 100644
--- a/client/templates/comment_form.js
+++ b/client/templates/comment_form.js
@@ -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 = {
}
};
-
diff --git a/client/templates/comment_item.html b/client/templates/comment_item.html
index 7f40946dc..60c43491a 100644
--- a/client/templates/comment_item.html
+++ b/client/templates/comment_item.html
@@ -21,7 +21,7 @@
{{#if can_edit}}
| Edit
{{/if}}
- {{#if is_admin}}
+ {{#if currentUser.isAdmin}}
|
| {{full_date}}
{{/if}}
diff --git a/client/templates/comment_item.js b/client/templates/comment_item.js
index 8b5955ed8..91e033537 100644
--- a/client/templates/comment_item.js
+++ b/client/templates/comment_item.js
@@ -99,10 +99,6 @@
}
}
- ,is_admin: function(){
- return currentUserIsAdmin();
- }
-
,repress_recursion: function(){
if(window.repress_recursion){
return true;
diff --git a/client/templates/comment_page.html b/client/templates/comment_page.html
index dd98ffd49..0ecfe5dc4 100644
--- a/client/templates/comment_page.html
+++ b/client/templates/comment_page.html
@@ -5,11 +5,17 @@
{{> post_item}}
{{/with}}
{{/if}}
+
+ {{#if comment}}
{{#with comment}}
{{/with}}
- {{> comment_form}}
+ {{/if}}
+
+ {{#if currentUser}}
+ {{> comment_form}}
+ {{/if}}
diff --git a/client/templates/nav.html b/client/templates/nav.html
index d20387b21..f98b1e047 100644
--- a/client/templates/nav.html
+++ b/client/templates/nav.html
@@ -3,7 +3,7 @@
- Top
- New
- {{#if is_admin}}
+ {{#if currentUser.isAdmin}}
- Users
- Settings
{{/if}}
@@ -21,7 +21,7 @@
-
- {{#if logged_in}}
+ {{#if currentUser}}
- Post
{{/if}}
diff --git a/client/templates/nav.js b/client/templates/nav.js
index aaf21e046..57de1cd02 100644
--- a/client/templates/nav.js
+++ b/client/templates/nav.js
@@ -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();
diff --git a/client/templates/post_item.html b/client/templates/post_item.html
index d48d3dcd1..1075068c1 100644
--- a/client/templates/post_item.html
+++ b/client/templates/post_item.html
@@ -40,7 +40,7 @@
{{#if can_edit}}
| Edit
{{/if}}
- {{#if is_admin}}
+ {{#if currentUser.isAdmin}}
| votes: {{votes}}, baseScore: {{baseScore}}, score: {{short_score}}
{{/if}}
diff --git a/client/templates/post_item.js b/client/templates/post_item.js
index df1925d48..78b5249eb 100644
--- a/client/templates/post_item.js
+++ b/client/templates/post_item.js
@@ -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;
diff --git a/client/templates/post_page.html b/client/templates/post_page.html
index bfb6c7d39..dbdd5dd88 100644
--- a/client/templates/post_page.html
+++ b/client/templates/post_page.html
@@ -3,7 +3,9 @@
{{#with post}}
{{> post_item}}
{{/with}}
- {{> comment_form}}
+ {{#if currentUser}}
+ {{> comment_form}}
+ {{/if}}
{{> comment_list}}
diff --git a/client/templates/settings.html b/client/templates/settings.html
index e98910954..519e1efb8 100644
--- a/client/templates/settings.html
+++ b/client/templates/settings.html
@@ -6,7 +6,7 @@
{{#if no_settings}}
No settings yet.
{{/if}}
- {{#if currentUserIsAdmin}}
+ {{#if currentUser.isAdmin}}
diff --git a/client/templates/settings.js b/client/templates/settings.js
index 346595f53..47b70babb 100644
--- a/client/templates/settings.js
+++ b/client/templates/settings.js
@@ -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;
diff --git a/client/templates/user_item.html b/client/templates/user_item.html
index adacd91d5..a831331ef 100644
--- a/client/templates/user_item.html
+++ b/client/templates/user_item.html
@@ -14,6 +14,6 @@
{{comments_count}} |
{{karma}} |
-
{{#if is_admin}}{{/if}} |
+
{{#if currentUser.isAdmin}}{{/if}} |
\ No newline at end of file
diff --git a/client/templates/user_item.js b/client/templates/user_item.js
index 7f68ea913..bb890297f 100644
--- a/client/templates/user_item.js
+++ b/client/templates/user_item.js
@@ -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);
-}
\ No newline at end of file
diff --git a/lib/helpers.js b/lib/helpers.js
index cb95c92a8..0387f6aa4 100644
--- a/lib/helpers.js
+++ b/lib/helpers.js
@@ -8,10 +8,6 @@ var breakTag = '
';
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){
diff --git a/smart.lock b/smart.lock
index 2bf1a1a10..f41a51f12 100644
--- a/smart.lock
+++ b/smart.lock
@@ -2,7 +2,7 @@
"meteor": {
"git": "https://github.com/meteor/meteor.git",
"branch": "auth",
- "commit": "687407a4d3be776635d3b59242e8304d9e29abdb"
+ "commit": "d2616308361203215c122f962ae9a5c763b5ca09"
},
"dependencies": {
"basePackages": {