Merge branch 'master' of github.com:SachaG/Telescope

This commit is contained in:
Sacha Greif 2012-09-28 17:20:59 +09:00
commit 7d4a3f7cb9
21 changed files with 69 additions and 136 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

@ -1,6 +1,6 @@
<template name="comment_item">
<li class="comment comment-displayed" id="{{_id}}">
<!-- <div class="comment-notification"><a href="#" class="open-comment-link">{{author}}</a></div>
<!-- <div class="comment-notification"><a href="#" class="open-comment-link">{{author.username}}</a></div>
--> <div class="comment-body">
<div class="comment-content">
<div class="comment-actions {{#if upvoted}}upvoted{{/if}} {{#if downvoted}}downvoted{{/if}}">
@ -14,14 +14,14 @@
</a>
</div>
<div class="comment-meta">
<a class="comment-username" href="/users/{{user_id}}">{{author}}</a>
<a class="comment-username" href="/users/{{user_id}}">{{author.username}}</a>
<span class="comment-time">{{ago}},</span>
<span class="points">{{votes}} <span class="unit">points </span>
<a href="/comments/{{_id}}" class="comment-permalink icon-link goto-comment">link</a>
{{#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

@ -16,30 +16,30 @@
$queuedAncestors=$comment.parents(".comment-queued");
if($queuedAncestors.exists()){
// console.log("----------- case 1: Queued Ancestor -----------");
// 1.
// 1.
// our comment has one or more queued ancestor, so we look for the root-most
// ancestor's queue container
$container=$queuedAncestors.last().data("queue");
}else if($prev.hasClass("queue-container")){
// console.log("----------- case 2: Queued Brother -----------");
// 2.
// 2.
// the comment just above is queued, so we use the same queue container as him
$container=$prev.data("queue");
}else if($prev.find(".comment").last().hasClass("comment-queued")){
// console.log("----------- case 3: Queued Cousin -----------");
// 3.
// there are no queued comments going up on the same level,
// there are no queued comments going up on the same level,
// but the bottom-most child of the comment directly above is queued
$container=$prev.find(".comment").last().data("queue");
}else if($down.hasClass("queue-container")){
// console.log("----------- case 4: Queued Sister -----------");
// 3.
// 3.
// the comment just below is queued, so we use the same queue container as him
$container=$next.data("queue");
}else if($up.hasClass('comment-displayed') || !$up.exists()){
// console.log("----------- case 5: No Queue -----------");
// 4.
// we've found containers neither above or below, but
// 4.
// we've found containers neither above or below, but
// A) we've hit a displayed comment or
// B) we've haven't found any comments (i.e. we're at the beginning of the list)
// so we put our queue container just before the comment
@ -77,18 +77,14 @@
}
,author: function(){
if(Meteor.users.findOne(this.user_id)){
return Meteor.users.findOne(this.user_id).username;
}
return Meteor.users.findOne(this.user_id);
}
,can_edit: function(){
if(this.user_id){
if(Meteor.user() && (isAdmin(Meteor.user()) || Meteor.user()._id==this.user_id)){
return true;
}
}
return false;
if(this.user_id && Meteor.userId())
return Meteor.user().isAdmin || (Meteor.userId() === this.user_id);
else
return false;
}
,body_formatted: function(){
@ -99,15 +95,8 @@
}
}
,is_admin: function(){
return currentUserIsAdmin();
}
,repress_recursion: function(){
if(window.repress_recursion){
return true;
}
return false;
return window.repress_recursion;
}
,ago: function(){
@ -115,15 +104,11 @@
}
,upvoted: function(){
var user = Meteor.user();
if(!user) return false;
return _.include(this.upvoters, user._id);
return Meteor.user() && _.include(this.upvoters, Meteor.user()._id);
}
,downvoted: function(){
var user = Meteor.user();
if(!user) return false;
return _.include(this.downvoters, user._id);
return Meteor.user() && _.include(this.downvoters, Meteor.user()._id);
}
});
@ -182,7 +167,7 @@ Template.comment_item.rendered=function(){
event.preventDefault();
var href=event.target.href.replace(/^(?:\/\/|[^\/]+)*\//, "");
Session.set('selected_comment', this);
Session.set('selected_comment_id', this._id);
// Session.set('state', 'reply');
Router.navigate(href, {trigger: true});
},
@ -222,7 +207,7 @@ Template.comment_item.rendered=function(){
// 'click .queue-container, click .queue-container a': function(e, instance){
// e.preventDefault();
// var $this=$(e.target);
// var queueContainer= $this.is("a") ? $this.closest('.queue-container') : $this;
// console.log($this, queueContainer);
// queueContainer.find("a").each(function(){
@ -233,6 +218,6 @@ Template.comment_item.rendered=function(){
// }
};
})();

View file

@ -1,15 +1,21 @@
<template name="comment_page">
<div class="post grid comment-page">
{{#if postLoaded}}
{{#with post}}
{{> post_item}}
{{/with}}
{{#if post}}
{{#with post}}
{{> 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

@ -1,28 +1,6 @@
Template.comment_page.show = function(){
return Session.equals('state', 'reply');
};
Template.comment_page.show_comment_form = function(){
return Meteor.user() !== null;
};
Template.comment_page.postLoaded = function(){
var selected_comment = Comments.findOne(Session.get('selected_comment_id'));
if(selected_comment){
return true;
}else{
return false;
}
}
Template.comment_page.post = function(){
var selected_comment = Comments.findOne(Session.get('selected_comment_id'));
if(selected_comment){
var post = selected_comment.post;
return Posts.findOne(post);
}
return selected_comment && Posts.findOne(selected_comment.post);
};
Template.comment_page.comment = function(){

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

@ -36,11 +36,11 @@
{{/if}}
{{#if url}}<span class="post-domain">{{domain}}</span>{{/if}}
</h3>
<p class="post-meta"><span class="points">{{votes}} <span class="unit">points </span></span>by <a class="post-author" href="/users/{{user_id}}">{{author}}</a> <span class="post-time">{{ago}}</span><span class="comments">, <a class="go-to-comments" href="posts/{{_id}}">{{comments}} comments</a></span>
<p class="post-meta"><span class="points">{{votes}} <span class="unit">points </span></span>by <a class="post-author" href="/users/{{user_id}}">{{authorName}}</a> <span class="post-time">{{ago}}</span><span class="comments">, <a class="go-to-comments" href="posts/{{_id}}">{{comments}} comments</a></span>
{{#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

@ -100,19 +100,13 @@ Template.post_item.current_domain = function(){
}
Template.post_item.can_edit = function(){
if(this.user_id){
if(Meteor.user() && (isAdmin(Meteor.user()) || Meteor.user()._id==this.user_id)){
return true;
}
}
return false;
if(this.user_id && Meteor.userId())
return Meteor.user().isAdmin || (Meteor.userId() === this.user_id);
else
return false;
};
Template.post_item.is_admin = function(){
return currentUserIsAdmin();
};
Template.post_item.author = function(){
Template.post_item.authorName = function(){
if(this.user_id && Meteor.users.findOne(this.user_id)){
return Meteor.users.findOne(this.user_id).username;
}else{

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

@ -36,7 +36,7 @@ Template.user_edit.events = {
Template.user_edit.user = function(){
var current_user=Meteor.user();
if(window.selected_user_id && !current_user.loading && isAdmin(current_user)){
if(window.selected_user_id && !current_user.loading && current_user.isAdmin){
return Meteor.users.findOne(window.selected_user_id);
}else{
return current_user;

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

@ -1,4 +0,0 @@
isAdmin=function(userOrId){
var user= typeof userOrId === 'string' ? Meteor.users.findOne(userOrId) : userOrId;
return user && user.isAdmin;
}

View file

@ -1,4 +1,8 @@
// Users
isAdmin=function(userId){
var user = Meteor.users.findOne(userId);
return user && user.isAdmin;
}
Meteor.publish('users', function() {
if (this.userId() && isAdmin(this.userId())) {
@ -92,7 +96,7 @@ Meteor.startup(function(){
if(isAdmin(userId) || (docs[0].user_id && docs[0].user_id==userId)){
return true;
}
return false;
return false;
}
});
});

View file

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