working on methods

This commit is contained in:
Sacha Greif 2016-02-18 12:16:32 +09:00
parent aa54340e05
commit 38d0f03d39
11 changed files with 87 additions and 72 deletions

View file

@ -29,6 +29,7 @@ caching-html-compiler@1.0.3-modules.8
callback-hook@1.0.5-modules.8
cfs:http-methods@0.0.30
check@1.1.1-modules.8
chuangbo:marked@0.3.5_1
coffeescript@1.0.12-modules.8
cosmos:browserify@0.9.3
dburles:collection-helpers@1.0.4
@ -41,6 +42,7 @@ ddp-rate-limiter@1.0.1-modules.8
ddp-server@1.2.3-modules.8
deps@1.0.9
diff-sequence@1.0.2-modules.8
djedi:sanitize-html@1.11.2
ecmascript@0.4.0-modules.8
ecmascript-runtime@0.2.7-modules.8
ejson@1.0.8-modules.8
@ -92,6 +94,7 @@ oauth@1.1.7-modules.8
oauth1@1.1.6-modules.8
oauth2@1.1.6-modules.8
observe-sequence@1.0.8-modules.8
ongoworks:speakingurl@6.0.0
ordered-dict@1.0.4
percolatestudio:synced-cron@1.1.0
promise@0.5.2-modules.8

View file

@ -1,9 +1,9 @@
Comments.methods = {};
// ------------------------------------------------------------------------------------------- //
// -------------------------------------- Submit Comment ------------------------------------- //
// ------------------------------------------------------------------------------------------- //
Comments.submit = function (comment) {
Comments.methods.new = function (comment) {
var userId = comment.userId; // at this stage, a userId is expected
@ -45,7 +45,7 @@ Comments.submit = function (comment) {
return comment;
};
Comments.edit = function (commentId, modifier, comment) {
Comments.methods.edit = function (commentId, modifier, comment) {
// ------------------------------ Callbacks ------------------------------ //
@ -68,7 +68,8 @@ Comments.edit = function (commentId, modifier, comment) {
// ------------------------------------------------------------------------------------------- //
Meteor.methods({
submitComment: function(comment){
'comments.new': function(comment){
// checking might be redundant because SimpleSchema already enforces the schema, but you never know
check(comment, Comments.simpleSchema());
@ -128,10 +129,10 @@ Meteor.methods({
comment.userId = user._id;
}
return Comments.submit(comment);
return Comments.methods.new(comment);
},
editComment: function (modifier, commentId) {
'comments.edit': function (modifier, commentId) {
// checking might be redundant because SimpleSchema already enforces the schema, but you never know
check(modifier, {$set: Comments.simpleSchema()});
@ -162,10 +163,10 @@ Meteor.methods({
});
});
Comments.edit(commentId, modifier, comment);
Comments.methods.edit(commentId, modifier, comment);
},
deleteCommentById: function (commentId) {
'comments.deleteById': function (commentId) {
check(commentId, String);
@ -199,5 +200,26 @@ Meteor.methods({
Messages.flash("You don't have permission to delete this comment.", "error");
}
},
'comments.upvote': function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "upvote");
},
'comments.downvote': function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "downvote");
},
'comments.cancelUpvote': function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "cancelUpvote");
},
'comments.cancelDownvote': function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "cancelDownvote");
}
});

View file

@ -16,7 +16,7 @@ const Header = props => {
<ListContainer collection={Categories} publication="categories" component={CategoriesList} limit={0}/>
</div>
<LogInButtons />
<a href={FlowRouter.path("postNew")}>New Post</a>
<a href={FlowRouter.path("posts.new")}>New Post</a>
</header>
)
}

View file

@ -58,6 +58,7 @@ const PostNew = React.createClass({
label="Body"
type="text"
/>
{/*
<CheckboxGroup
name="categories"
value=""
@ -65,6 +66,7 @@ const PostNew = React.createClass({
type="text"
options={categoriesOptions}
/>
*/}
<button type="submit" >Submit</button>
</Formsy.Form>
</div>

View file

@ -1,7 +1,7 @@
let views = ["top", "new", "best", "daily"];
const adminViews = ["pending", "rejected", "scheduled"];
const PostViews = props => {
let views = ["top", "new", "best", "daily"];
const adminViews = ["pending", "rejected", "scheduled"];
if (Users.is.admin(Meteor.user())) {
views = views.concat(adminViews);
@ -12,7 +12,7 @@ const PostViews = props => {
<ul>
<li>Sort by:</li>
{views.map(view =>
<li key={view}><a href={FlowRouter.extendPathWithQueryParams("PostDefault", {}, {view: view})}>{view}</a></li>
<li key={view}><a href={FlowRouter.extendPathWithQueryParams("posts.list", {}, {view: view})}>{view}</a></li>
)}
</ul>
</div>

View file

@ -1,7 +1,7 @@
// ------------------------------------- Posts -------------------------------- //
FlowRouter.route('/', {
name: 'postDefault',
name: 'posts.list',
action: function (params, queryParams) {
({AppContainer, ListContainer, PostList} = Telescope.components);
({selector, options} = Posts.parameters.get(queryParams));
@ -28,8 +28,8 @@ FlowRouter.route('/', {
// }
// });
FlowRouter.route('/post/new', {
name: 'postNew',
FlowRouter.route('/posts/new', {
name: 'posts.new',
action: function (params, queryParams) {
({AppContainer, PostNewContainer} = Telescope.components);
ReactLayout.render(AppContainer, {content: <PostNewContainer />})
@ -37,8 +37,8 @@ FlowRouter.route('/post/new', {
}
});
FlowRouter.route('/post/:_id', {
name: 'postPage',
FlowRouter.route('/posts/:_id', {
name: 'posts.single',
action: function (params, queryParams) {
({AppContainer, ItemContainer, Post} = Telescope.components);
ReactLayout.render(AppContainer, {content: <ItemContainer collection={Posts} publication="posts.single" terms={params} component={Post}/>})
@ -46,8 +46,8 @@ FlowRouter.route('/post/:_id', {
}
});
FlowRouter.route('/post/:_id/edit', {
name: 'postEdit',
FlowRouter.route('/posts/:_id/edit', {
name: 'posts.edit',
action: function (params, queryParams) {
({AppContainer, ItemContainer, Post} = Telescope.components);
ReactLayout.render(AppContainer, {content: <ItemContainer collection={Posts} publication="posts.single" terms={params} component={PostEdit}/>})

View file

@ -45,7 +45,7 @@ Package.onUse(function (api) {
// 'kadira:dochead@1.4.0',
'dburles:collection-helpers@1.0.4',
'matb33:collection-hooks@0.8.1',
// 'chuangbo:marked@0.3.5_1',
'chuangbo:marked@0.3.5_1',
// 'meteorhacks:fast-render@2.11.0',
// 'meteorhacks:subs-manager@1.6.3',
'percolatestudio:synced-cron@1.1.0',
@ -58,12 +58,11 @@ Package.onUse(function (api) {
// 'utilities:avatar@0.9.2',
// 'fortawesome:fontawesome@4.5.0',
// 'ccan:cssreset@1.0.0',
// 'djedi:sanitize-html@1.11.2',
'djedi:sanitize-html@1.11.2',
// 'jparker:gravatar@0.4.1',
// 'sanjo:meteor-files-helpers@1.2.0_1',
// 'cmather:handlebars-server@2.0.0',
// 'chuangbo:cookie@1.1.0',
// 'ongoworks:speakingurl@6.0.0',
'ongoworks:speakingurl@6.0.0',
// 'okgrow:router-autoscroll@0.1.6',
'tmeasday:publish-counts@0.7.3',
// 'utilities:onsubscribed@0.1.2',

View file

@ -51,20 +51,12 @@ Posts.before.update(function (userId, doc, fieldNames, modifier) {
* Increment the user's post count and upvote the post
*/
function afterPostSubmitOperations (post) {
console.log(this)
var userId = post.userId;
Meteor.users.update({_id: userId}, {$inc: {"telescope.postCount": 1}});
return post;
}
Telescope.callbacks.add("postSubmitAsync", afterPostSubmitOperations);
function upvoteOwnPost (post) {
var postAuthor = Meteor.users.findOne(post.userId);
Telescope.operateOnItem(Posts, post._id, postAuthor, "upvote");
return post;
}
Telescope.callbacks.add("postSubmitAsync", upvoteOwnPost);
function setPostedAt (post) {
if (post.isApproved() && !post.postedAt) {
Posts.update(post._id, {$set: {postedAt: new Date()}});
@ -72,7 +64,20 @@ function setPostedAt (post) {
}
Telescope.callbacks.add("postEditAsync", setPostedAt);
// notifications
// ------------------------------------- Votes -------------------------------- //
if (typeof Telescope.operateOnItem !== "undefined") {
function upvoteOwnPost (post) {
var postAuthor = Meteor.users.findOne(post.userId);
Telescope.operateOnItem(Posts, post._id, postAuthor, "upvote");
return post;
}
Telescope.callbacks.add("postSubmitAsync", upvoteOwnPost);
}
// ------------------------------------- Notifications -------------------------------- //
if (typeof Herald !== "undefined") {

View file

@ -36,7 +36,7 @@ Posts.helpers({getLinkTarget: function () {return Posts.getLinkTarget(this);}});
Posts.getPageUrl = function(post, isAbsolute){
var isAbsolute = typeof isAbsolute === "undefined" ? false : isAbsolute; // default to false
var prefix = isAbsolute ? Telescope.utils.getSiteUrl().slice(0,-1) : "";
return prefix + FlowRouter.path("postPage", post);
return prefix + FlowRouter.path("posts.single", post);
};
Posts.helpers({getPageUrl: function (isAbsolute) {return Posts.getPageUrl(this, isAbsolute);}});
@ -47,7 +47,7 @@ Posts.helpers({getPageUrl: function (isAbsolute) {return Posts.getPageUrl(this,
Posts.getEditUrl = function(post, isAbsolute){
var isAbsolute = typeof isAbsolute === "undefined" ? false : isAbsolute; // default to false
var prefix = isAbsolute ? Telescope.utils.getSiteUrl().slice(0,-1) : "";
return prefix + FlowRouter.path("postEdit", post);
return prefix + FlowRouter.path("posts.edit", post);
};
Posts.helpers({getEditUrl: function (isAbsolute) {return Posts.getEditUrl(this, isAbsolute);}});

View file

@ -121,7 +121,6 @@ Meteor.methods({
check(post, Posts.simpleSchema());
console.log("// submitting post…")
// required properties:
// title
@ -318,6 +317,26 @@ Meteor.methods({
'posts.checkForDuplicates': function (url) {
Posts.checkForSameUrl(url);
},
'posts.upvote': function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "upvote");
},
'posts.downvote': function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "downvote");
},
'posts.cancelUpvote': function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "cancelUpvote");
},
'posts.cancelDownvote': function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "cancelDownvote");
}
});

View file

@ -91,39 +91,4 @@ Telescope.operateOnItem = function (collection, itemId, user, operation) {
}
}
Meteor.methods({
upvotePost: function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "upvote");
},
downvotePost: function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "downvote");
},
cancelUpvotePost: function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "cancelUpvote");
},
cancelDownvotePost: function (postId) {
check(postId, String);
return Telescope.operateOnItem.call(this, Posts, postId, Meteor.user(), "cancelDownvote");
},
upvoteComment: function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "upvote");
},
downvoteComment: function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "downvote");
},
cancelUpvoteComment: function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "cancelUpvote");
},
cancelDownvoteComment: function (commentId) {
check(commentId, String);
return Telescope.operateOnItem.call(this, Comments, commentId, Meteor.user(), "cancelDownvote");
}
});
};