2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-06-23 15:11:56 +09:00
|
|
|
import Categories from "./collection.js";
|
|
|
|
import Users from 'meteor/nova:users';
|
|
|
|
|
2016-07-21 09:39:40 +09:00
|
|
|
const canInsert = user => Users.canDo(user, "categories.new");
|
2016-08-07 19:10:53 +09:00
|
|
|
const canEdit = user => Users.canDo(user, "categories.edit.all");
|
2016-10-29 16:02:43 +09:00
|
|
|
const alwaysPublic = user => true;
|
2016-07-21 09:39:40 +09:00
|
|
|
|
2016-06-23 15:11:56 +09:00
|
|
|
// category schema
|
|
|
|
Categories.schema = new SimpleSchema({
|
|
|
|
name: {
|
|
|
|
type: String,
|
2016-10-29 16:02:43 +09:00
|
|
|
viewableIf: alwaysPublic,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
2016-08-07 19:10:53 +09:00
|
|
|
editableIf: canEdit,
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-10-29 16:02:43 +09:00
|
|
|
viewableIf: alwaysPublic,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
2016-08-07 19:10:53 +09:00
|
|
|
editableIf: canEdit,
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true,
|
2016-10-05 08:43:13 +02:00
|
|
|
form: {
|
2016-06-23 15:11:56 +09:00
|
|
|
rows: 3
|
|
|
|
}
|
|
|
|
},
|
|
|
|
order: {
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
2016-10-29 16:02:43 +09:00
|
|
|
viewableIf: alwaysPublic,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
2016-08-07 19:10:53 +09:00
|
|
|
editableIf: canEdit,
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-10-29 16:02:43 +09:00
|
|
|
viewableIf: alwaysPublic,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
2016-08-07 19:10:53 +09:00
|
|
|
editableIf: canEdit,
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-10-29 16:02:43 +09:00
|
|
|
viewableIf: alwaysPublic,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
2016-08-07 19:10:53 +09:00
|
|
|
editableIf: canEdit,
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true
|
|
|
|
},
|
|
|
|
parentId: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2016-10-29 16:02:43 +09:00
|
|
|
viewableIf: alwaysPublic,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
2016-08-07 19:10:53 +09:00
|
|
|
editableIf: canEdit,
|
2016-06-23 15:11:56 +09:00
|
|
|
publish: true,
|
2016-10-05 08:43:13 +02:00
|
|
|
form: {
|
2016-06-23 15:11:56 +09:00
|
|
|
options: function () {
|
|
|
|
var categories = Categories.find().map(function (category) {
|
|
|
|
return {
|
|
|
|
value: category._id,
|
|
|
|
label: category.name
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Meteor.startup(function(){
|
|
|
|
// Categories.internationalize();
|
|
|
|
// });
|
|
|
|
|
|
|
|
Categories.attachSchema(Categories.schema);
|
|
|
|
|
|
|
|
|
2016-10-29 14:18:16 +09:00
|
|
|
// Telescope.settings.collection.addField([
|
|
|
|
// {
|
|
|
|
// fieldName: 'categoriesBehavior',
|
|
|
|
// fieldSchema: {
|
|
|
|
// type: String,
|
|
|
|
// optional: true,
|
|
|
|
// form: {
|
|
|
|
// group: 'categories',
|
|
|
|
// instructions: 'Let users filter by one or multiple categories at a time.',
|
|
|
|
// options: function () {
|
|
|
|
// return [
|
|
|
|
// {value: "single", label: "categories_behavior_one_at_a_time"},
|
|
|
|
// {value: "multiple", label: "categories_behavior_multiple"}
|
|
|
|
// ];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// fieldName: 'hideEmptyCategories',
|
|
|
|
// fieldSchema: {
|
|
|
|
// type: Boolean,
|
|
|
|
// optional: true,
|
|
|
|
// form: {
|
|
|
|
// group: 'categories',
|
|
|
|
// instructions: 'Hide empty categories in navigation'
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2016-10-29 16:37:33 +09:00
|
|
|
// ]);
|
|
|
|
|
|
|
|
|
|
|
|
Categories.graphQLSchema = `
|
|
|
|
type Category {
|
|
|
|
_id: String
|
|
|
|
name: String
|
|
|
|
description: String
|
|
|
|
order: Int
|
|
|
|
slug: String
|
|
|
|
image: String
|
|
|
|
parent: Category
|
|
|
|
}
|
2016-11-07 23:04:41 +01:00
|
|
|
|
|
|
|
input categoriesInput {
|
|
|
|
name: String!
|
|
|
|
description: String
|
|
|
|
order: Int
|
|
|
|
slug: String
|
|
|
|
image: String
|
|
|
|
parent: String
|
|
|
|
}
|
|
|
|
|
|
|
|
input categoriesUnset {
|
|
|
|
_id: Boolean
|
|
|
|
description: Boolean
|
|
|
|
order: Boolean
|
|
|
|
slug: Boolean
|
|
|
|
image: Boolean
|
|
|
|
parent: Boolean
|
|
|
|
}
|
2016-10-29 16:37:33 +09:00
|
|
|
`;
|
|
|
|
|
|
|
|
Telescope.graphQL.addSchema(Categories.graphQLSchema);
|
|
|
|
|
|
|
|
Telescope.graphQL.addQuery(`
|
|
|
|
categories: [Category]
|
|
|
|
category(_id: String): Category
|
2016-11-03 21:39:09 +09:00
|
|
|
`);
|
|
|
|
|
2016-11-07 23:04:41 +01:00
|
|
|
Categories.graphQLQueries = {
|
|
|
|
single: `
|
|
|
|
_id
|
|
|
|
name
|
|
|
|
description
|
|
|
|
order
|
|
|
|
slug
|
|
|
|
image
|
|
|
|
parent {
|
|
|
|
_id
|
|
|
|
name
|
|
|
|
description
|
|
|
|
order
|
|
|
|
slug
|
|
|
|
image
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2016-11-03 21:39:09 +09:00
|
|
|
Telescope.graphQL.addToContext({ Categories });
|