From 678736b8cc80ac0df2543a0173068497608c0f06 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Fri, 12 Jun 2020 20:02:22 +0200 Subject: [PATCH] - Finished this fucking weird shit oh my god I will DIE. --- .../src/components/spells/edit-spell-card.vue | 80 +++++++++++-------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/client/src/components/spells/edit-spell-card.vue b/client/src/components/spells/edit-spell-card.vue index 629d27a..9423787 100644 --- a/client/src/components/spells/edit-spell-card.vue +++ b/client/src/components/spells/edit-spell-card.vue @@ -33,8 +33,8 @@
- +
@@ -43,7 +43,7 @@
-
@@ -53,7 +53,7 @@
-
@@ -94,25 +94,51 @@ export default { ingredients: Array, }, }, + model: { + event: 'change' + }, data() { return { all_schools: [], all_variables: [], all_ingredients: [], - - spell_school_ids: [], - spell_variable_ids: [], - spell_ingredient_ids: [], } }, computed: { computeSpell() { let output = this.spell - console.log(output) + output.spell_school_ids = [] + output.spell_variable_ids = [] + output.spell_ingredient_ids = [] + output.spell_school_ids_value = [] + output.spell_variable_ids_value = [] + output.spell_ingredient_ids_value = [] + + output.schools.forEach(element => { + output.spell_school_ids.push(element['id']) + }) + output.variables.forEach(element => { + output.spell_variable_ids.push(element['id']) + }) + output.ingredients.forEach(element => { + output.spell_ingredient_ids.push(element['id']) + }) + + output.spell_school_ids.forEach(element => { + output.spell_school_ids_value.push("school_" + element) + }) + output.spell_variable_ids.forEach(element => { + output.spell_variable_ids_value.push("variable_" + element) + }) + output.spell_ingredient_ids.forEach(element => { + output.spell_ingredient_ids_value.push("ingredient_" + element) + }) + return output } }, created() { + // Gets all relevant info for multiple selects let fetchSchools = Schools.getSchools() let fetchVariables = Variables.getVariables() let fetchIngredients = Ingredients.getIngredients() @@ -122,48 +148,32 @@ export default { this.all_schools = v[0].data this.all_variables = v[1].data this.all_ingredients = v[2].data - this.getAssociatedValues(this.spell) }) .catch(err => { console.log(err) }) }, mounted() { - + console.log(this.spell) }, watch: { - spell: { + computeSpell: { deep: true, handler() { - this.getAssociatedValues(this.spell) + console.log(this.spell) } } }, methods: { - setSpell(spell) { - this.spell = spell - }, - getAssociatedValues(spell) { - this.spell_school_ids = [] - this.spell_variable_ids = [] - this.spell_ingredient_ids = [] - - spell.schools.forEach(element => { - this.spell_school_ids.push(element['id']) - }) - spell.variables.forEach(element => { - this.spell_variable_ids.push(element['id']) - }) - spell.ingredients.forEach(element => { - this.spell_ingredient_ids.push(element['id']) - }) + changeSchools() { + console.log(this.spell.spell_school_ids_value) }, updateSpell(e) { e.preventDefault() - let schoolsData = Object.values(this.spell_school_ids).map(v => { return parseInt(v.slice(7)) }) - let variablesData = Object.values(this.spell_variable_ids).map(v => { return parseInt(v.slice(9)) }) - let ingredientsData = Object.values(this.spell_ingredient_ids).map(v => { return parseInt(v.slice(11)) }) + let schoolsData = Object.values(this.spell.spell_school_ids_value).map(v => { return parseInt(v.slice(7)) }) + let variablesData = Object.values(this.spell.spell_variable_ids_value).map(v => { return parseInt(v.slice(9)) }) + let ingredientsData = Object.values(this.spell.spell_ingredient_ids_value).map(v => { return parseInt(v.slice(11)) }) let data = { name: this.spell.name, @@ -174,9 +184,11 @@ export default { ingredients: ingredientsData, } + console.log(data) + Spells.updateSpell(this.spell.id, data) .then(v => { - this.setSpell(v.data) + this.$emit('editSpell', v.data) }) } }