added "new" page

This commit is contained in:
Sacha Greif 2012-09-18 11:49:17 +09:00
parent 248fa129b3
commit dfd6ac149e
11 changed files with 68 additions and 32 deletions

View file

@ -33,6 +33,8 @@ if (Meteor.is_client) {
},
routes: {
'': 'top',
'top':'top',
'new':'new',
'test':'test',
'signin':'signin',
'signup':'signup',
@ -45,14 +47,14 @@ if (Meteor.is_client) {
'comments/:id/edit':'comment_edit',
'settings':'settings'
},
top: function() { console.log("top"); this.goto('top'); },
test: function() {console.log("test"); this.goto('test'); },
signup: function() {console.log("signup"); this.goto('signup'); },
signin: function() {console.log("signin"); this.goto('signin'); },
submit: function() {console.log("submit"); this.goto('post_submit'); },
settings: function() {console.log("settings"); this.goto('settings'); },
post_deleted: function() {console.log("post_deleted"); this.goto('post_deleted'); },
comment_deleted: function() {console.log("comment_deleted"); this.goto('comment_deleted'); },
top: function() { this.goto('posts_top'); },
new: function() { this.goto('posts_new'); },
signup: function() { this.goto('signup'); },
signin: function() { this.goto('signin'); },
submit: function() { this.goto('post_submit'); },
settings: function() { this.goto('settings'); },
post_deleted: function() { this.goto('post_deleted'); },
comment_deleted: function() { this.goto('comment_deleted'); },
post: function(id) {
console.log("post, id="+id);
Session.set('selected_post_id', id);

View file

@ -1,13 +1,13 @@
<template name="nav">
<div id="pageslide" class="hidden">
<ul>
<li><a href="/top">Top</a></li>
<li><a href="/new">New</a></li>
<li><a href="/ask">Ask</a></li>
<li><a class="top" href="/top">Top</a></li>
<li><a class="new" href="/new">New</a></li>
<!-- <li><a href="/ask">Ask</a></li>
<li><a href="/show">Show</a></li>
<li><a href="/jobs">Jobs </a></li>
<li><a href="/signup">Sign Up </a></li>
<li><a href="/signin">Log In</a></li>
<li><a href="/signin">Log In</a></li> -->
</ul>
</div>
<header class="header grid">
@ -15,11 +15,11 @@
<a id="mobile-menu" href="#menu" class="mobile mobile-button menu"><i class="icon-menu"></i><span>Menu</span></a>
<!-- <a href="/submit" class="mobile mobile-button submit"><i class="icon-plus"></i><span>Submit</span></a> -->
<ul class="nav site-nav desktop">
<li><a href="top">Top</a></li>
<li><a href="new">New</a></li>
<li><a href="ask">Ask</a></li>
<li><a class="top" href="top">Top</a></li>
<li><a class="new" href="new">New</a></li>
<!-- <li><a href="ask">Ask</a></li>
<li><a href="show">Show</a></li>
<li><a href="jobs">Jobs</a></li>
<li><a href="jobs">Jobs</a></li> -->
</ul>
<ul class="nav user-nav desktop">
<!-- {{#if logged_in}}

View file

@ -37,6 +37,16 @@ Template.nav.events = {
iframe: false
});
}
, 'click .top': function(event){
event.preventDefault();
Router.navigate('top', {trigger: true});
}
, 'click .new': function(event){
event.preventDefault();
Router.navigate('new', {trigger: true});
}
};
Template.nav.logged_in = function(){

View file

@ -89,10 +89,19 @@ Template.post_item.voted = function(){
};
var getRank = function(post){
var filter = {$or: [
{score: {$gt: post.score}},
{$and: [{score: post.score}, {submitted: {$lt: post.submitted}}]}
]};
console.log(window.sortBy);
if(window.sortBy=="score"){
var filter = {$or: [
{score: {$gt: post.score}},
{$and: [{score: post.score}, {submitted: {$lt: post.submitted}}]}
]};
}else{
var filter = {$or: [
{submitted: {$gt: post.submitted}},
{$and: [{submitted: post.submitted}, {score: {$lt: post.score}}]}
]};
}
return Posts.find(filter).count()+1;
}

View file

@ -1,4 +1,4 @@
<template name="top">
<template name="posts_new">
<div class="posts grid list">
{{#each posts}}
{{> post_item}}

View file

@ -0,0 +1,8 @@
Template.posts_new.posts = function(){
var posts = Posts.find({}, {sort: {submitted: -1}});
return posts;
};
Template.posts_new.created = function(){
window.sortBy="time";
}

View file

@ -0,0 +1,7 @@
<template name="posts_top">
<div class="posts grid list">
{{#each posts}}
{{> post_item}}
{{/each}}
</div>
</template>

View file

@ -0,0 +1,8 @@
Template.posts_top.posts = function(){
var posts = Posts.find({}, {sort: {score: -1}});
return posts;
};
Template.posts_top.created = function(){
window.sortBy="score";
}

View file

@ -1,11 +0,0 @@
Template.top.show = function(){
return Session.equals('state', 'list');
};
Template.top.posts = function(){
var posts = Posts.find({}, {sort: {score: -1}});
return posts;
};
Template.top.rendered = function(){
};

View file

@ -0,0 +1,3 @@
<template name="users">
</template>

View file