Răsfoiți Sursa

Implement addIngredient for edit recipes sidebar.

Lee Morgan 5 ani în urmă
părinte
comite
00c3c197db

+ 1 - 1
views/dashboardPage/ejs/sidebars/editRecipe.ejs

@@ -36,7 +36,7 @@
             </div>
 
             <div>
-                <input type="number" step="0.01" min="0">
+                <input type="number" step="0.01" min="0" placeholder="QUANTITY">
 
                 <select>
                     <optgroup label="MASS/WEIGHT">

+ 4 - 0
views/dashboardPage/js/classes/Recipe.js

@@ -26,6 +26,10 @@ class RecipeIngredient{
         return this._baseUnitMultiplier;
     }
 
+    get unit(){
+        return this._unit;
+    }
+
     getQuantityDisplay(){
         return `${this._quantity.toFixed(2)} ${this._unit.toUpperCase()}`;
     }

+ 21 - 3
views/dashboardPage/js/sidebars/editRecipe.js

@@ -15,9 +15,11 @@ module.exports = {
             tempList.push(recipe.ingredients[i].ingredient.id);
 
             let ingredient = template.cloneNode(true);
+            ingredient.ingredient = recipe.ingredients[i].ingredient;
             ingredient.children[0].children[0].innerText = recipe.ingredients[i].ingredient.name;
             ingredient.children[0].children[1].onclick = ()=>{this.removeIngredient(recipe.ingredients[i])};
-            ingredient.children[1].children[0].placeholder = "QUANTITY";
+            ingredient.children[1].children[0].value = recipe.ingredients[i].quantity;
+            ingredient.children[1].children[1].value = recipe.ingredients[i].unit;
             used.appendChild(ingredient);
         }
 
@@ -28,14 +30,30 @@ module.exports = {
             button.innerText = merchant.inventory[i].ingredient.name;
             button.classList.add("choosable");
             button.classList.add("selection");
-            button.onclick = ()=>{this.addIngredient(merchant.inventory[i].ingredient)};
+            button.ingredient = merchant.inventory[i].ingredient;
+            button.onclick = ()=>{this.addIngredient(button)};
             this.unused.push(button);
             unused.appendChild(button);
         }
     },
 
     addIngredient: function(ingredient){
-        console.log(ingredient);
+        for(let i = 0; i < this.unused.length; i++){
+            if(this.unused[i] === ingredient){
+                this.unused.splice(i, 1);
+                break;
+            }
+        }
+
+        let unused = document.getElementById("editRecipeUnused");
+        unused.removeChild(ingredient);
+        let used = document.getElementById("editRecipeUsed");
+        
+        let newItem = document.getElementById("editRecipeInputItem").content.children[0].cloneNode(true);
+        newItem.ingredient = ingredient.ingredient;
+        newItem.children[0].children[0].innerText = ingredient.ingredient.name;
+        newItem.children[0].children[1].onclick = ()=>{this.removeIngredient(ingredient.ingredient)};
+        used.appendChild(newItem);
     },
 
     removeIngredient: function(ingredient){