From 93d8a8d33e19ce271963f3ba09d675c020f2709b Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 2 Jul 2019 17:28:07 +0200 Subject: [PATCH] Library attribute insert form complete --- .jshintrc | 2 +- .../api/creature/properties/Attributes.js | 4 ++ app/imports/api/library/LibraryNodes.js | 5 +- .../ui/components/forms/schemaFormMixin.js | 56 +++++++++------- .../properties/attributes/AttributeForm.vue | 29 ++++---- .../ui/library/LibraryNodeCreationDialog.vue | 50 ++++++++------ app/imports/ui/library/LibraryNodeForm.vue | 16 ----- .../ui/library/LibraryNodeInsertForm.vue | 67 +++++++++++++++++++ app/imports/ui/pages/Library.vue | 2 + 9 files changed, 152 insertions(+), 79 deletions(-) delete mode 100644 app/imports/ui/library/LibraryNodeForm.vue create mode 100644 app/imports/ui/library/LibraryNodeInsertForm.vue 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 @@
@@ -51,7 +51,7 @@ label="Reset" clearable :items="resetOptions" - :value="attribute.reset" + :value="model.reset" :error-messages="errors.reset" :menu-props="{auto: true, lazy: true}" @change="(reset, ack) => $emit('change', {reset}, ack)" @@ -60,9 +60,9 @@ @@ -72,7 +72,7 @@ diff --git a/app/imports/ui/library/LibraryNodeForm.vue b/app/imports/ui/library/LibraryNodeForm.vue deleted file mode 100644 index def2308b..00000000 --- a/app/imports/ui/library/LibraryNodeForm.vue +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/app/imports/ui/library/LibraryNodeInsertForm.vue b/app/imports/ui/library/LibraryNodeInsertForm.vue new file mode 100644 index 00000000..98a16457 --- /dev/null +++ b/app/imports/ui/library/LibraryNodeInsertForm.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/app/imports/ui/pages/Library.vue b/app/imports/ui/pages/Library.vue index 3fb9c3f9..b4ab3bfc 100644 --- a/app/imports/ui/pages/Library.vue +++ b/app/imports/ui/pages/Library.vue @@ -33,6 +33,8 @@ elementId: 'insert-library-node-fab', callback(libraryNode){ if (!libraryNode) return; + console.log({libraryNode}); + throw "TODO: give this library node ancestry before inserting it" let libraryNodeId = insertNode.call(libraryNode); return libraryNodeId; }