diff --git a/.jshintrc b/.jshintrc index 7e1af9b7..719690f2 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,4 +1,4 @@ { "undef": false, - "esversion": 6 + "esversion": 9, } diff --git a/app/imports/api/creature/properties/Attributes.js b/app/imports/api/creature/properties/Attributes.js index aaec6397..81dcd4ed 100644 --- a/app/imports/api/creature/properties/Attributes.js +++ b/app/imports/api/creature/properties/Attributes.js @@ -26,11 +26,14 @@ let AttributeSchema = schema({ name: { type: String, optional: true, + defaultValue: 'New Attribute', }, // The technical, lowercase, single-word name used in formulae variableName: { type: String, regEx: VARIABLE_NAME_REGEX, + min: 3, + defaultValue: 'newAttribute', }, // How it is displayed and computed is determined by type type: { @@ -46,6 +49,7 @@ let AttributeSchema = schema({ 'spellSlot', // Level 1, 2, 3... spell slots 'utility', // Aren't displayed, Jump height, Carry capacity ], + defaultValue: 'stat', index: 1, }, // The starting value, before effects diff --git a/app/imports/api/library/LibraryNodes.js b/app/imports/api/library/LibraryNodes.js index 197131db..4d0602e8 100644 --- a/app/imports/api/library/LibraryNodes.js +++ b/app/imports/api/library/LibraryNodes.js @@ -65,10 +65,7 @@ function assertNodeEditPermission(node, userId){ const insertNode = new ValidatedMethod({ name: 'LibraryNodes.methods.insert', - mixins: [ - simpleSchemaMixin, - ], - schema: LibraryNodeSchema, + validate: null, run(libraryNode) { assertNodeEditPermission(libraryNode, this.userId); return LibraryNodes.insert(libraryNode); diff --git a/app/imports/ui/components/forms/schemaFormMixin.js b/app/imports/ui/components/forms/schemaFormMixin.js index d8dabe3f..dfc84447 100644 --- a/app/imports/ui/components/forms/schemaFormMixin.js +++ b/app/imports/ui/components/forms/schemaFormMixin.js @@ -2,29 +2,37 @@ * Forms that take in a schema and a model of the current data, manages smart * inputs, and sends update events when valid data model changes must occur */ -export default function schemaFormMixin(schema){ - return { - data(){ return { - valid: true, - };}, - created(){ - this.validationContext = schema.newContext(); +const schemaFormMixin = { + data(){ return { + valid: true, + };}, + computed: { + errors(){ + this.valid = true; + if (!this.model){ + throw new Error("this.model must be set"); + } + if (!this.validationContext) return {}; + let cleanModel = this.validationContext.clean(this.model, { + getAutoValues: false, + }); + this.validationContext.validate(cleanModel); + let errors = {}; + this.validationContext.validationErrors().forEach(error => { + if (this.valid) this.valid = false; + errors[error.name] = this.schema.messageForError(error); + }); + return errors; }, - computed: { - errors(){ - this.valid = true; - if (!this.model){ - throw new Error("this.model must be set"); - } - let cleanModel = this.validationContext.clean(this.model); - this.validationContext.validate(cleanModel); - let errors = {}; - this.validationContext.validationErrors().forEach(error => { - if (this.valid) this.valid = false; - errors[error.name] = Attributes.simpleSchema().messageForError(error); - }); - return errors; - }, + }, + methods: { + change(modifier, ack){ + for (let key in modifier){ + this.$set(this.model, key, modifier[key]) + } + if (ack) ack(); }, - }; -} + }, +}; + +export default schemaFormMixin; diff --git a/app/imports/ui/creature/properties/attributes/AttributeForm.vue b/app/imports/ui/creature/properties/attributes/AttributeForm.vue index b93b78e2..c96344aa 100644 --- a/app/imports/ui/creature/properties/attributes/AttributeForm.vue +++ b/app/imports/ui/creature/properties/attributes/AttributeForm.vue @@ -2,14 +2,14 @@