2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-06-23 15:00:58 +09:00
|
|
|
import Users from 'meteor/nova:users';
|
2016-06-23 15:11:56 +09:00
|
|
|
import Categories from "../collection.js";
|
2016-06-23 11:40:35 +09:00
|
|
|
|
2015-04-22 07:50:11 +09:00
|
|
|
Meteor.publish('categories', function() {
|
2016-07-20 10:25:05 +09:00
|
|
|
|
|
|
|
const currentUser = this.userId && Users.findOne(this.userId);
|
|
|
|
|
|
|
|
if(Users.canDo(currentUser, "posts.view.approved.all")){
|
|
|
|
|
2016-08-12 14:33:51 +02:00
|
|
|
var categories = Categories.find({}, {fields: Categories.publishedFields.list});
|
2015-09-08 09:49:30 +09:00
|
|
|
var publication = this;
|
|
|
|
|
|
|
|
categories.forEach(function (category) {
|
2015-09-14 17:11:07 +09:00
|
|
|
var childrenCategories = category.getChildren();
|
|
|
|
var categoryIds = [category._id].concat(_.pluck(childrenCategories, "_id"));
|
|
|
|
var cursor = Posts.find({$and: [{categories: {$in: categoryIds}}, {status: Posts.config.STATUS_APPROVED}]});
|
2016-04-03 15:56:12 +09:00
|
|
|
// Counts.publish(publication, category.getCounterName(), cursor, { noReady: true });
|
2015-09-08 09:49:30 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
return categories;
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
return [];
|
2016-02-25 17:44:43 +09:00
|
|
|
});
|