diff --git a/app/imports/api/creature/CreatureProperties.js b/app/imports/api/creature/CreatureProperties.js index d3d1701f..840cb11a 100644 --- a/app/imports/api/creature/CreatureProperties.js +++ b/app/imports/api/creature/CreatureProperties.js @@ -1,7 +1,11 @@ +import { Meteor } from 'meteor/meteor'; +import { Mongo } from 'meteor/mongo'; +import { ValidatedMethod } from 'meteor/mdg:validated-method'; import SimpleSchema from 'simpl-schema'; import ChildSchema, { RefSchema } from '/imports/api/parenting/ChildSchema.js'; import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js'; import LibraryNodes from '/imports/api/library/LibraryNodes.js'; +import Creatures from '/imports/api/creature/Creatures.js'; import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js'; import { softRemove } from '/imports/api/parenting/softRemove.js'; import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js'; @@ -150,7 +154,7 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({ const updateProperty = new ValidatedMethod({ name: 'CreatureProperties.methods.update', - validate({_id, path, value}){ + validate({_id, path}){ if (!_id) return false; // We cannot change these fields with a simple update switch (path[0]){ @@ -166,9 +170,15 @@ const updateProperty = new ValidatedMethod({ run({_id, path, value}) { let property = CreatureProperties.findOne(_id); assertPropertyEditPermission(property, this.userId); - CreatureProperties.update(_id, { - $set: {[path.join('.')]: value}, - }, { + let pathString = path.join('.'); + let modifier; + // unset empty values + if (value === null || value === undefined){ + modifier = {$unset: {[pathString]: 1}}; + } else { + modifier = {$set: {[pathString]: value}}; + } + CreatureProperties.update(_id, modifier, { selector: {type: property.type}, }); recomputeCreatures(property); diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js index 6f8940c8..a4b23aae 100644 --- a/app/imports/api/library/LibraryNodes.js +++ b/app/imports/api/library/LibraryNodes.js @@ -1,3 +1,6 @@ +import { Meteor } from 'meteor/meteor'; +import { Mongo } from 'meteor/mongo'; +import { ValidatedMethod } from 'meteor/mdg:validated-method'; import SimpleSchema from 'simpl-schema'; import ChildSchema from '/imports/api/parenting/ChildSchema.js'; import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js'; @@ -56,7 +59,7 @@ const insertNode = new ValidatedMethod({ const updateLibraryNode = new ValidatedMethod({ name: 'LibraryNodes.methods.update', - validate({_id, path, value, ack}){ + validate({_id, path}){ if (!_id) return false; // We cannot change these fields with a simple update switch (path[0]){ @@ -70,9 +73,15 @@ const updateLibraryNode = new ValidatedMethod({ run({_id, path, value}) { let node = LibraryNodes.findOne(_id); assertNodeEditPermission(node, this.userId); - return LibraryNodes.update(_id, { - $set: {[path.join('.')]: value}, - }, { + let pathString = path.join('.'); + let modifier; + // unset empty values + if (value === null || value === undefined){ + modifier = {$unset: {[pathString]: 1}}; + } else { + modifier = {$set: {[pathString]: value}}; + } + return LibraryNodes.update(_id, modifier, { selector: {type: node.type}, }); }, @@ -127,5 +136,4 @@ export { pullFromLibraryNode, pushToLibraryNode, softRemoveLibraryNode, - libraryNodesToTree, }; diff --git a/app/imports/ui/properties/forms/ActionForm.vue b/app/imports/ui/properties/forms/ActionForm.vue index 48fa296b..d060b542 100644 --- a/app/imports/ui/properties/forms/ActionForm.vue +++ b/app/imports/ui/properties/forms/ActionForm.vue @@ -109,7 +109,7 @@ :error-messages="errors.reset" :menu-props="{auto: true, lazy: true}" :debounce-time="debounceTime" - @change="(value, ack) => $emit('change', {path: ['reset'], value: value || '', ack})" + @change="(value, ack) => $emit('change', {path: ['reset'], value, ack})" /> diff --git a/app/imports/ui/properties/forms/AttributeForm.vue b/app/imports/ui/properties/forms/AttributeForm.vue index 2c3529a6..efe05d90 100644 --- a/app/imports/ui/properties/forms/AttributeForm.vue +++ b/app/imports/ui/properties/forms/AttributeForm.vue @@ -86,7 +86,7 @@ :error-messages="errors.reset" :menu-props="{auto: true, lazy: true}" :debounce-time="debounceTime" - @change="(value, ack) => $emit('change', {path: ['reset'], value: value || '', ack})" + @change="(value, ack) => $emit('change', {path: ['reset'], value: value, ack})" /> diff --git a/app/imports/ui/properties/forms/SkillForm.vue b/app/imports/ui/properties/forms/SkillForm.vue index 2aff9522..33ae90bf 100644 --- a/app/imports/ui/properties/forms/SkillForm.vue +++ b/app/imports/ui/properties/forms/SkillForm.vue @@ -61,10 +61,9 @@ @@ -120,9 +119,6 @@ }, ] };}, - methods: { - log: console.log, - }, }; diff --git a/app/imports/ui/properties/forms/shared/ProficiencySelect.vue b/app/imports/ui/properties/forms/shared/ProficiencySelect.vue index aa4337f0..5e02578d 100644 --- a/app/imports/ui/properties/forms/shared/ProficiencySelect.vue +++ b/app/imports/ui/properties/forms/shared/ProficiencySelect.vue @@ -1,6 +1,7 @@