mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
clean up; remove flatten call from Form.jsx; make it possible to specify id:null to not sort by id
This commit is contained in:
parent
e87fc07351
commit
4ad845440c
6 changed files with 24 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
import { Components, getRawComponent, replaceComponent } from 'meteor/vulcan:core';
|
||||
import React from 'react';
|
||||
import { FormattedMessage, FormattedRelative } from 'meteor/vulcan:i18n';
|
||||
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
||||
import { Link } from 'react-router';
|
||||
import Posts from "meteor/vulcan:posts";
|
||||
import moment from 'moment';
|
||||
|
|
|
@ -45,7 +45,6 @@ const resolvers = {
|
|||
|
||||
// get selector and options from terms and perform Mongo query
|
||||
let {selector, options} = Comments.getParameters(terms);
|
||||
options.limit = (terms.limit < 1 || terms.limit > 100) ? 100 : terms.limit;
|
||||
options.skip = terms.offset;
|
||||
const comments = Comments.find(selector, options).fetch();
|
||||
|
||||
|
|
|
@ -468,7 +468,7 @@ class Form extends Component {
|
|||
if (this.props.formType === "new") { // new document form
|
||||
|
||||
// remove any empty properties
|
||||
let document = _.compactObject(flatten(data));
|
||||
let document = _.compactObject(data);
|
||||
|
||||
// call method with new document
|
||||
this.props.newMutation({document}).then(this.newMutationSuccessCallback).catch(this.mutationErrorCallback);
|
||||
|
@ -478,7 +478,7 @@ class Form extends Component {
|
|||
const document = this.getDocument();
|
||||
|
||||
// put all keys with data on $set
|
||||
const set = _.compactObject(flatten(data));
|
||||
const set = _.compactObject(data);
|
||||
|
||||
// put all keys without data on $unset
|
||||
const setKeys = _.keys(set);
|
||||
|
|
|
@ -3,6 +3,7 @@ import SimpleSchema from 'simpl-schema';
|
|||
import { GraphQLSchema } from './graphql.js';
|
||||
import { Utils } from './utils.js';
|
||||
import { runCallbacks } from './callbacks.js';
|
||||
import { getSetting } from './settings.js';
|
||||
|
||||
export const Collections = [];
|
||||
|
||||
|
@ -192,20 +193,25 @@ export const createCollection = options => {
|
|||
// iterate over posts.parameters callbacks
|
||||
parameters = runCallbacks(`${collectionName.toLowerCase()}.parameters`, parameters, _.clone(terms), apolloClient);
|
||||
|
||||
// extend sort to sort posts by _id to break ties
|
||||
// extend sort to sort posts by _id to break ties, unless there's already an id sort
|
||||
// NOTE: always do this last to avoid overriding another sort
|
||||
parameters = Utils.deepExtend(true, parameters, {options: {sort: {_id: -1}}});
|
||||
if (!(parameters.options.sort && parameters.options.sort._id)) {
|
||||
parameters = Utils.deepExtend(true, parameters, {options: {sort: {_id: -1}}});
|
||||
}
|
||||
|
||||
// remove any null fields (setting a field to null means it should be deleted)
|
||||
_.keys(parameters.selector).forEach(key => {
|
||||
if (parameters.selector[key] === null) delete parameters.selector[key];
|
||||
});
|
||||
_.keys(parameters.options).forEach(key => {
|
||||
if (parameters.options[key] === null) delete parameters.options[key];
|
||||
});
|
||||
|
||||
// limit number of items to 200
|
||||
parameters.options.limit = (terms.limit < 1 || terms.limit > 200) ? 200 : terms.limit;
|
||||
if (parameters.options.sort) {
|
||||
_.keys(parameters.options.sort).forEach(key => {
|
||||
if (parameters.options.sort[key] === null) delete parameters.options.sort[key];
|
||||
});
|
||||
}
|
||||
|
||||
// limit number of items to 200 by default
|
||||
const maxDocuments = getSetting('maxDocumentsPerRequest', 200);
|
||||
parameters.options.limit = (!terms.limit || terms.limit < 1 || terms.limit > maxDocuments) ? maxDocuments : terms.limit;
|
||||
|
||||
// console.log(parameters);
|
||||
|
||||
|
|
|
@ -42,6 +42,9 @@ export const removeFromFragment = (fragmentName, propertyName) => {
|
|||
registerFragment(newFragmentText);
|
||||
}
|
||||
|
||||
// get fragment name from fragment object
|
||||
export const getFragmentName = fragment => fragment && fragment.definitions[0] && fragment.definitions[0].name.value;
|
||||
|
||||
// get actual gql fragment
|
||||
export const getFragment = fragmentName => {
|
||||
|
||||
|
@ -52,7 +55,9 @@ export const getFragment = fragmentName => {
|
|||
throw new Error(`Fragment "${fragmentName}" not registered.`)
|
||||
}
|
||||
if (!fragment.fragmentObject) {
|
||||
throw new Error(`Fragment "${fragmentName}" not initialized.`)
|
||||
console.log('// !fragment.fragmentObject: '+fragmentName)
|
||||
initializeFragment(fragmentName);
|
||||
// throw new Error(`Fragment "${fragmentName}" not initialized.`)
|
||||
}
|
||||
|
||||
// return fragment object created by gql
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
},
|
||||
|
||||
"defaultEmail": "hello@world.com",
|
||||
"mailUrl": "smtp://postmaster%40foo.mailgun.org:foo123@smtp.mailgun.org:587/",
|
||||
"mailUrl": "smtp://username%40yourdomain.mailgun.org:yourpassword123@smtp.mailgun.org:587/",
|
||||
"scoreUpdateInterval": "30",
|
||||
|
||||
"embedlyKey":"123foo",
|
||||
|
|
Loading…
Add table
Reference in a new issue