2017-03-23 16:27:59 +09:00
|
|
|
import Posts from "meteor/vulcan:posts";
|
2017-01-29 09:51:38 +09:00
|
|
|
import { getCategoriesAsOptions } from './schema.js';
|
2016-11-03 17:16:12 +09:00
|
|
|
|
2017-03-21 21:40:54 +08:00
|
|
|
Posts.addField([
|
2015-04-22 07:50:11 +09:00
|
|
|
{
|
2015-05-10 14:36:47 +09:00
|
|
|
fieldName: 'categories',
|
|
|
|
fieldSchema: {
|
2017-03-16 01:25:08 +08:00
|
|
|
type: Array,
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "checkboxgroup",
|
2015-04-22 07:50:11 +09:00
|
|
|
optional: true,
|
2016-12-06 10:55:47 +01:00
|
|
|
insertableBy: ['members'],
|
|
|
|
editableBy: ['members'],
|
|
|
|
viewableBy: ['guests'],
|
2016-10-05 08:43:13 +02:00
|
|
|
form: {
|
2015-04-22 07:50:11 +09:00
|
|
|
noselect: true,
|
2015-08-07 11:17:03 +09:00
|
|
|
type: "bootstrap-category",
|
2015-10-20 14:34:24 +09:00
|
|
|
order: 50,
|
2017-01-29 09:51:38 +09:00
|
|
|
options: formProps => getCategoriesAsOptions(formProps.client),
|
2016-02-17 19:39:43 +09:00
|
|
|
},
|
2017-07-08 11:36:27 +09:00
|
|
|
resolveAs: {
|
|
|
|
fieldName: 'categories',
|
|
|
|
type: '[Category]',
|
|
|
|
resolver: async (post, args, {currentUser, Users, Categories}) => {
|
|
|
|
if (!post.categories) return [];
|
|
|
|
const categories = _.compact(await Categories.loader.loadMany(post.categories));
|
|
|
|
return Users.restrictViewableFields(currentUser, Categories, categories);
|
|
|
|
}
|
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2017-03-16 01:25:08 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldName: 'categories.$',
|
|
|
|
fieldSchema: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
}
|
2017-01-11 18:02:12 +01:00
|
|
|
}
|
2017-03-21 21:40:54 +08:00
|
|
|
]);
|