mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Add dbCollectionName option to createCollection
This commit is contained in:
parent
968bf55848
commit
5bad048505
7 changed files with 42 additions and 63 deletions
|
@ -13,7 +13,10 @@ import './permissions.js';
|
|||
|
||||
const Comments = createCollection({
|
||||
|
||||
collectionName: 'comments',
|
||||
collectionName: 'Comments',
|
||||
|
||||
// avoid conflicts with 'comments' collection in vulcan:comments
|
||||
dbCollectionName: 'commentsInstagram',
|
||||
|
||||
typeName: 'Comment',
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import './permissions.js';
|
|||
|
||||
const Pics = createCollection({
|
||||
|
||||
collectionName: 'pics',
|
||||
collectionName: 'Pics',
|
||||
|
||||
typeName: 'Pic',
|
||||
|
||||
|
|
|
@ -44,7 +44,9 @@ class HeadTags extends Component {
|
|||
// add <link /> markup specific to the page rendered
|
||||
const link = Headtags.link.concat([
|
||||
{ rel: "canonical", href: Utils.getSiteUrl() },
|
||||
{ rel: "shortcut icon", href: getSetting("faviconUrl", "/img/favicon.ico") }
|
||||
{ rel: "shortcut icon", href: getSetting("faviconUrl", "/img/favicon.ico") },
|
||||
{ rel: 'stylesheet', type: 'text/css', href: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css' },
|
||||
{ rel: 'stylesheet', type: 'text/css', href: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css' },
|
||||
]);
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
import Posts from "meteor/vulcan:posts";
|
||||
import Comments from "meteor/vulcan:comments";
|
||||
import Users from 'meteor/vulcan:users';
|
||||
import { addCallback } from 'meteor/vulcan:core';
|
||||
|
||||
Users.addField({
|
||||
fieldName: 'isDummy',
|
||||
fieldSchema: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
hidden: true // never show this
|
||||
}
|
||||
});
|
||||
|
||||
Posts.addField({
|
||||
fieldName: 'dummySlug',
|
||||
fieldSchema: {
|
||||
type: String,
|
||||
optional: true,
|
||||
hidden: true // never show this
|
||||
}
|
||||
});
|
||||
|
||||
Posts.addField({
|
||||
fieldName: 'isDummy',
|
||||
fieldSchema: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
hidden: true // never show this
|
||||
}
|
||||
});
|
||||
|
||||
Comments.addField({
|
||||
fieldName: 'isDummy',
|
||||
fieldSchema: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
hidden: true // never show this
|
||||
}
|
||||
});
|
|
@ -5,6 +5,27 @@ import Comments from "meteor/vulcan:comments";
|
|||
import Users from 'meteor/vulcan:users';
|
||||
import Events from "meteor/vulcan:events";
|
||||
|
||||
const dummyFlag = {
|
||||
fieldName: 'isDummy',
|
||||
fieldSchema: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
hidden: true
|
||||
}
|
||||
}
|
||||
Users.addField(dummyFlag);
|
||||
Posts.addField(dummyFlag);
|
||||
Comments.addField(dummyFlag);
|
||||
|
||||
Posts.addField({
|
||||
fieldName: 'dummySlug',
|
||||
fieldSchema: {
|
||||
type: String,
|
||||
optional: true,
|
||||
hidden: true // never show this
|
||||
}
|
||||
});
|
||||
|
||||
var toTitleCase = function (str) {
|
||||
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
||||
};
|
||||
|
@ -58,6 +79,7 @@ var createComment = function (slug, username, body, parentBody) {
|
|||
};
|
||||
|
||||
var createDummyUsers = function () {
|
||||
console.log('// inserting dummy users…');
|
||||
Accounts.createUser({
|
||||
username: 'Bruce',
|
||||
email: 'dummyuser1@telescopeapp.org',
|
||||
|
@ -82,6 +104,7 @@ var createDummyUsers = function () {
|
|||
};
|
||||
|
||||
var createDummyPosts = function () {
|
||||
console.log('// inserting dummy posts');
|
||||
|
||||
createPost("read_this_first", moment().toDate(), "Bruce", "telescope.png");
|
||||
|
||||
|
@ -96,6 +119,7 @@ var createDummyPosts = function () {
|
|||
};
|
||||
|
||||
var createDummyComments = function () {
|
||||
console.log('// inserting dummy comments…');
|
||||
|
||||
createComment("read_this_first", "Bruce", "What an awesome app!");
|
||||
|
||||
|
@ -109,32 +133,21 @@ var createDummyComments = function () {
|
|||
|
||||
};
|
||||
|
||||
var deleteDummyContent = function () {
|
||||
const deleteDummyContent = function () {
|
||||
Users.remove({'profile.isDummy': true});
|
||||
Posts.remove({isDummy: true});
|
||||
Comments.remove({isDummy: true});
|
||||
};
|
||||
|
||||
Meteor.methods({
|
||||
addGettingStartedContent: function () {
|
||||
if (Users.isAdmin(Meteor.user())) {
|
||||
createDummyUsers();
|
||||
createDummyPosts();
|
||||
createDummyComments();
|
||||
}
|
||||
},
|
||||
removeGettingStartedContent: function () {
|
||||
if (Users.isAdmin(Meteor.user()))
|
||||
deleteDummyContent();
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.startup(function () {
|
||||
// insert dummy content only if createDummyContent hasn't happened and there aren't any posts or users in the db
|
||||
if (!Users.find().count() && !Events.findOne({name: 'createDummyContent'}) && !Posts.find().count()) {
|
||||
if (!Users.find().count()) {
|
||||
createDummyUsers();
|
||||
}
|
||||
if (!Posts.find().count()) {
|
||||
createDummyPosts();
|
||||
}
|
||||
if (!Comments.find().count()) {
|
||||
createDummyComments();
|
||||
Events.log({name: 'createDummyContent', unique: true, important: true});
|
||||
}
|
||||
});
|
|
@ -89,10 +89,10 @@ Mongo.Collection.prototype.helpers = function(helpers) {
|
|||
|
||||
export const createCollection = options => {
|
||||
|
||||
const {collectionName, typeName, schema, resolvers, mutations, generateGraphQLSchema = true } = options;
|
||||
const {collectionName, typeName, schema, resolvers, mutations, generateGraphQLSchema = true, dbCollectionName } = options;
|
||||
|
||||
// initialize new Mongo collection
|
||||
const collection = collectionName === 'users' ? Meteor.users : new Mongo.Collection(collectionName);
|
||||
const collection = collectionName === 'users' ? Meteor.users : new Mongo.Collection(dbCollectionName ? dbCollectionName : collectionName.toLowerCase());
|
||||
|
||||
// decorate collection with options
|
||||
collection.options = options;
|
||||
|
|
|
@ -95,7 +95,8 @@ export const GraphQLSchema = {
|
|||
// generate a GraphQL schema corresponding to a given collection
|
||||
generateSchema(collection) {
|
||||
|
||||
const collectionName = collection._name;
|
||||
const collectionName = collection.options.collectionName;
|
||||
|
||||
const mainTypeName = collection.typeName ? collection.typeName : Utils.camelToSpaces(_.initial(collectionName).join('')); // default to posts -> Post
|
||||
|
||||
// backward-compatibility code: we do not want user.telescope fields in the graphql schema
|
||||
|
|
Loading…
Add table
Reference in a new issue