2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-11-03 17:16:12 +09:00
|
|
|
|
2015-05-17 15:38:02 +09:00
|
|
|
Posts.addField(
|
2015-04-22 07:50:11 +09:00
|
|
|
{
|
2015-05-10 14:36:47 +09:00
|
|
|
fieldName: 'categories',
|
|
|
|
fieldSchema: {
|
2017-01-11 18:02:12 +01:00
|
|
|
type: [String],
|
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,
|
2016-11-17 10:22:31 +01:00
|
|
|
options: function (formProps) {
|
2016-11-23 17:22:29 +09:00
|
|
|
|
2016-11-17 10:22:31 +01:00
|
|
|
// catch the ApolloClient from the form props
|
|
|
|
const {client} = formProps;
|
2016-11-03 17:16:12 +09:00
|
|
|
|
2016-11-17 10:22:31 +01:00
|
|
|
// get the current data of the store
|
|
|
|
const apolloData = client.store.getState().apollo.data;
|
2016-11-03 18:25:33 +09:00
|
|
|
|
2016-11-17 10:22:31 +01:00
|
|
|
// filter these data based on their typename: we are interested in the categories data
|
|
|
|
const categories = _.filter(apolloData, (object, key) => {
|
|
|
|
return object.__typename === 'Category'
|
|
|
|
});
|
|
|
|
|
|
|
|
// give the form component (here: checkboxgroup) exploitable data
|
2016-11-03 18:25:33 +09:00
|
|
|
const categoriesOptions = categories.map(function (category) {
|
2015-04-22 07:50:11 +09:00
|
|
|
return {
|
|
|
|
value: category._id,
|
2017-01-13 09:21:07 +01:00
|
|
|
label: category.name,
|
|
|
|
slug: category.slug, // note: it may be used to look up from prefilled props
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
});
|
2016-11-03 18:25:33 +09:00
|
|
|
|
|
|
|
return categoriesOptions;
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2016-02-17 19:39:43 +09:00
|
|
|
},
|
2017-01-11 18:02:12 +01:00
|
|
|
// publish: true,
|
|
|
|
// join: {
|
|
|
|
// joinAs: "categoriesArray",
|
|
|
|
// collection: () => Categories
|
|
|
|
// },
|
2016-11-08 14:56:39 +09:00
|
|
|
resolveAs: 'categories: [Category]'
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2017-01-11 18:02:12 +01:00
|
|
|
}
|
2015-04-22 07:50:11 +09:00
|
|
|
);
|