Răsfoiți Sursa

Update the style on the edit recipe sidebar.
No functionality on this sidebar yet.

Lee Morgan 5 ani în urmă
părinte
comite
ba3ef69d4d

+ 36 - 0
views/dashboardPage/css/dashboard.css

@@ -271,6 +271,42 @@ Multi-strand use classes
             color: black;
         }
 
+.choosable.selection{
+    justify-content: left;
+    background: rgb(240, 252, 255);
+    color: black;
+    margin: 2px 0;
+    width: 100%;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
+
+.chosenSelection{
+    width: 95%;
+    margin: 15px auto;
+}
+
+    .chosenSelection div{
+        display: flex;
+        justify-content: space-between;
+        align-items: center;
+        height: 32px;
+    }
+
+    .chosenSelection input, .chosenSelection select{
+        height: 30px;
+        border: none;
+        width: 47%;
+    }
+
+    .chosenSelection button{
+        padding: 0;
+        margin: 0 5px;
+        max-height: none;
+        min-width: none;
+    }
+
 .tooltipContainer{
     position: relative;
 }

+ 29 - 22
views/dashboardPage/css/sidebars/editRecipe.css

@@ -1,28 +1,35 @@
-#editRecipe{
+#editRecipeContents{
     display: flex;
-    flex-direction: column;
-    align-items: center;
-    width: 100%;
+    flex-grow: 2;
 }
 
-    #editRecipeIngList{
-        width: 100%;
-        max-height: 75%;
-        overflow-y: auto;
+    #editRecipeLeft, #editRecipeRight{
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        width: 50%;
+    }
+
+    #editRecipeLeft{
+        border-right: 2px solid rgb(255, 99, 107);
+    }
+
+    #editRecipeUnused, #editRecipeUsed{
+        display: flex;
+        flex-direction: column;
+        width: 95%;
     }
 
-        .editRecipeIng{
-            background: rgb(0, 27, 45);
-            color: white;
-            width: 90%;
-            border-radius: 5px;
-            text-align: center;
-            padding: 5px;
-            margin: 5px auto;
-            position: relative;
-        }
+.editRecipeInputItem{
+    display: flex;
+    flex-direction: column;
+}
+
+    .editRecipeInputItem > div{
+        display: flex;
+        align-items: center;
+    }
 
-            .editRecipeIng button{
-                position: absolute;
-                right: 5px;
-            }
+    .editRecipeInputItem input{
+        width: 150px;
+    }

+ 28 - 0
views/dashboardPage/css/sidebars/editRecipe2.css

@@ -0,0 +1,28 @@
+#editRecipe{
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    width: 100%;
+}
+
+    #editRecipeIngList{
+        width: 100%;
+        max-height: 75%;
+        overflow-y: auto;
+    }
+
+        .editRecipeIng{
+            background: rgb(0, 27, 45);
+            color: white;
+            width: 90%;
+            border-radius: 5px;
+            text-align: center;
+            padding: 5px;
+            margin: 5px auto;
+            position: relative;
+        }
+
+            .editRecipeIng button{
+                position: absolute;
+                right: 5px;
+            }

+ 0 - 12
views/dashboardPage/css/sidebars/newRecipe.css

@@ -7,18 +7,6 @@
     height: 100%;
 }
 
-    #addRecipe .choosable{
-        display: flex;
-        justify-content: left;
-        background: rgb(240, 252, 255);
-        color: black;
-        margin: 2px 0;
-        width: 100%;
-        white-space: nowrap;
-        overflow: hidden;
-        text-overflow: ellipsis;
-    }
-
     #newRecipeContent{
         display: flex;
         flex-grow: 10;

+ 53 - 40
views/dashboardPage/ejs/sidebars/editRecipe.ejs

@@ -9,55 +9,68 @@
         </button>
     </div>
 
-    <label>NAME:
-        <input id="editRecipeName" type="text">
-    </label>
+    <h1 id="editRecipeTitle"></h1>
 
-    <h1 id="editRecipeNoName"></h1>
-    
-    <label style="display:none">CATEGORY:
-        <input id="editRecipeCategory" type="text">
-    </label>
+    <div id="editRecipeContents">
+        <div id="editRecipeLeft">
+            <input id="editRecipeSearch" type="text" placeholder="SEARCH">
 
-    <h3>INGREDIENTS</h3>
-
-    <div id="editRecipeIngList"></div>
-
-    <button id="addRecIng" class="iconButton">
-        <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
-            <circle cx="12" cy="12" r="10"></circle>
-            <line x1="12" y1="8" x2="12" y2="16"></line>
-            <line x1="8" y1="12" x2="16" y2="12"></line>
-        </svg>
-    </button>
-
-    <div class="lineBorder"></div>
-
-    <h3>PRICE</h3>
-
-    <input id="editRecipePrice" type="number" min="0" step="0.01">
+            <div id="editRecipeUnused"></div>
+        </div>
 
-    <div class="lineBorder"></div>
+        <div id="editRecipeRight">
+            <h2>LIST OF INGREDIENTS</h2>
 
-    <div class="buttonBox">
-        <button id="editRecipeSubmit" class="sidebarButton">UPDATE</button>
-        <button id="editRecipeCancel" class="sidebarButton">CANCEL</button>
+            <div id="editRecipeUsed"></div>
+        </div>
     </div>
 
-    <template id="editRecipeIng">
-        <div class="editRecipeIng">
-            <button class="iconButton">
-                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
-                    <polyline points="3 6 5 6 21 6"></polyline>
-                    <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
-                </svg>
-            </button>
+    <button id="editRecipeSubmit" class="sidebarButton">SUBMIT</button>
+
+    <template id="editRecipeInputItem">
+        <div class="chosenSelection">
+            <div>
+                <p></p>
 
-            <p></p>
+                <button id="editRecipeRemoveBtn" class="sidebarButton">REMOVE</button>
+            </div>
 
-            <select></select>
+            <div>
+                <input type="number" step="0.01" min="0">
 
-            <input type="number" min="0" step="0.01">
+                <select>
+                    <optgroup label="MASS/WEIGHT">
+                        <option type="mass" value="g">G</option>
+                        <option type="mass" value="kg">KG</option>
+                        <option type="mass" value="oz">OZ</option>
+                        <option type="mass" value="lb">LB</option>
+                    </optgroup>
+        
+                    <optgroup label="VOLUME">
+                        <option type="volume" value="ml">ML</option>
+                        <option type="volume" value="l">L</option>
+                        <option type="volume" value="tsp">TSP</option>
+                        <option type="volume" value="tbsp">TBSP</option>
+                        <option type="volume" value="ozfl">OZ. FL</option>
+                        <option type="volume" value="cup">CUP</option>
+                        <option type="volume" value="pt">PT</option>
+                        <option type="volume" value="qt">QT</option>
+                        <option type="volume" value="gal">GAL</option>
+                    </optgroup>
+        
+                    <optgroup label="LENGTH">
+                        <option type="length" value="mm">MM</option>
+                        <option type="length" value="cm">CM</option>
+                        <option type="length" value="m">M</option>
+                        <option type="length" value="in">IN</option>
+                        <option type="length" value="ft">FT</option>
+                    </optgroup>
+        
+                    <optgroup label="OTHER">
+                        <option type="other" value="each">EACH</option>
+                    </optgroup>
+                </select>
+            </div>
         </div>
     </template>
 </div>

+ 63 - 0
views/dashboardPage/ejs/sidebars/editRecipe2.ejs

@@ -0,0 +1,63 @@
+<div id="editRecipe">
+    <div class="sidebarIconButtons">
+        <button class="iconButton tooltipContainer" onclick="controller.closeSidebar()">
+            <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+                <line x1="5" y1="12" x2="19" y2="12"></line>
+                <polyline points="12 5 19 12 12 19"></polyline>
+            </svg>
+            <span class="tooltip">CLOSE</span>
+        </button>
+    </div>
+
+    <label>NAME:
+        <input id="editRecipeName" type="text">
+    </label>
+
+    <h1 id="editRecipeNoName"></h1>
+    
+    <label style="display:none">CATEGORY:
+        <input id="editRecipeCategory" type="text">
+    </label>
+
+    <h3>INGREDIENTS</h3>
+
+    <div id="editRecipeIngList"></div>
+
+    <button id="addRecIng" class="iconButton">
+        <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+            <circle cx="12" cy="12" r="10"></circle>
+            <line x1="12" y1="8" x2="12" y2="16"></line>
+            <line x1="8" y1="12" x2="16" y2="12"></line>
+        </svg>
+    </button>
+
+    <div class="lineBorder"></div>
+
+    <h3>PRICE</h3>
+
+    <input id="editRecipePrice" type="number" min="0" step="0.01">
+
+    <div class="lineBorder"></div>
+
+    <div class="buttonBox">
+        <button id="editRecipeSubmit" class="sidebarButton">UPDATE</button>
+        <button id="editRecipeCancel" class="sidebarButton">CANCEL</button>
+    </div>
+
+    <template id="editRecipeIng">
+        <div class="editRecipeIng">
+            <button class="iconButton">
+                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+                    <polyline points="3 6 5 6 21 6"></polyline>
+                    <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
+                </svg>
+            </button>
+
+            <p></p>
+
+            <select></select>
+
+            <input type="number" min="0" step="0.01">
+        </div>
+    </template>
+</div>

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

@@ -36,7 +36,7 @@
     </div>
 
     <template id="newRecipeChosenIngredient">
-        <div class="newRecipeChosenIngredient">
+        <div class="chosenSelection">
             <div>
                 <p></p>
                 

+ 39 - 122
views/dashboardPage/js/sidebars/editRecipe.js

@@ -1,135 +1,52 @@
-let editRecipe = {
-    display: function(recipe){
-        let nameInput = document.getElementById("editRecipeName");
-        if(merchant.pos === "none"){
-            nameInput.value = recipe.name;
-            let categoryInput = document.getElementById("editRecipeCategory");
-            categoryInput.value = recipe.category;
-            categoryInput.parentElement.style.display = "block";
-        }else{
-            document.getElementById("editRecipeNoName").innerText = recipe.name;
-            nameInput.parentNode.style.display = "none";
-        }
-
-        //Populate ingredients
-        let ingredientList = document.getElementById("editRecipeIngList");
+module.exports = {
+    unused: [],
 
-        while(ingredientList.children.length > 0){
-            ingredientList.removeChild(ingredientList.firstChild);
-        }
+    display: function(recipe){
+        document.getElementById("sidebarDiv").classList.add("sidebarWide");
+        document.getElementById("editRecipeTitle").innerText = recipe.name;
+        document.getElementById("editRecipeSearch").onchange = ()=>{this.search()};
+        document.getElementById("editRecipeSubmit").onclick = ()=>{this.submit()};
+        let used = document.getElementById("editRecipeUsed");
+        let unused = document.getElementById("editRecipeUnused");
+        let template = document.getElementById("editRecipeInputItem").content.children[0];
+        let tempList = [];
 
-        let template = document.getElementById("editRecipeIng").content.children[0];
         for(let i = 0; i < recipe.ingredients.length; i++){
-            let ingredientDiv = template.cloneNode(true);
-            ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
-            ingredientDiv.children[1].innerText = recipe.ingredients[i].ingredient.getNameAndUnit();
-            ingredientDiv.children[2].style.display = "none";
-            ingredientDiv.children[3].value = recipe.ingredients[i].quantity;
-            ingredientDiv.ingredient = recipe.ingredients[i];
-            
-            ingredientList.appendChild(ingredientDiv);
-        }
+            tempList.push(recipe.ingredients[i].ingredient.id);
 
-        document.getElementById("addRecIng").onclick = ()=>{this.newIngredient()};
-        document.getElementById("editRecipePrice").value = recipe.price;
-        document.getElementById("editRecipeSubmit").onclick = ()=>{this.submit(recipe)};
-        document.getElementById("editRecipeCancel").onclick = ()=>{controller.openSidebar("recipeDetails", recipe)};
-    },
-
-    newIngredient: function(){
-        let ingredientList = document.getElementById("editRecipeIngList");
-
-        let ingredientDiv = document.getElementById("editRecipeIng").content.children[0].cloneNode(true);
-        ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
-        ingredientDiv.children[1].style.display = "none";
-        ingredientDiv.children[3].value = "0.00";
-
-        //Populate selector
-        let categories = merchant.categorizeIngredients();
-        for(let i = 0; i < categories.length; i++){
-            let group = document.createElement("optgroup");
-            group.label = categories[i].name;
-
-            for(let j = 0; j < categories[i].ingredients.length; j++){
-                let option = document.createElement("option");
-                option.innerText = categories[i].ingredients[j].ingredient.getNameAndUnit();
-                option.ingredient = categories[i].ingredients[j];
-                group.appendChild(option);
-            }
-            
-            ingredientDiv.children[2].appendChild(group);
+            let ingredient = template.cloneNode(true);
+            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";
+            used.appendChild(ingredient);
         }
 
-        ingredientList.appendChild(ingredientDiv);
-    },
+        for(let i = 0; i < merchant.inventory.length; i++){
+            if(tempList.includes(merchant.inventory[i].ingredient.id)) continue;
 
-    submit: function(recipe){
-        let data = {
-            id: recipe.id,
-            name: recipe.name,
-            price: document.getElementById("editRecipePrice").value * 100,
-            category: document.getElementById("editRecipeCategory").value,
-            ingredients: []
+            let button = document.createElement("button");
+            button.innerText = merchant.inventory[i].ingredient.name;
+            button.classList.add("choosable");
+            button.classList.add("selection");
+            button.onclick = ()=>{this.addIngredient(merchant.inventory[i].ingredient)};
+            this.unused.push(button);
+            unused.appendChild(button);
         }
+    },
 
-        if(merchant.pos === "none"){
-            data.name = document.getElementById("editRecipeName").value;
-        }
-
-        let ingredients = document.getElementById("editRecipeIngList").children;
-        for(let i = 0; i < ingredients.length; i++){
-            const quantity = parseFloat(ingredients[i].children[3].value);
-            let newIngredient = {};
-            let ingredient = {};
-
-            if(ingredients[i].children[1].style.display === "none"){
-                let selector = ingredients[i].children[2];
-                ingredient = selector.options[selector.selectedIndex].ingredient;
-
-                newIngredient = {
-                    ingredient: ingredient.ingredient.id,
-                    quantity: controller.baseUnit(quantity, ingredient.ingredient.unit)
-                };
-            }else{
-                ingredient = ingredients[i].ingredient;
-
-                newIngredient = {
-                    ingredient: ingredient.ingredient.id,
-                    quantity: controller.baseUnit(quantity, ingredient.ingredient.unit)
-                };
-            }
+    addIngredient: function(ingredient){
+        console.log(ingredient);
+    },
 
-            data.ingredients.push(newIngredient);
-        }
+    removeIngredient: function(ingredient){
+        console.log(ingredient);
+    },
 
-        let loader = document.getElementById("loaderContainer");
-        loader.style.display = "flex";
+    search: function(){
+        console.log("searching");
+    },
 
-        fetch("/recipe/update", {
-            method: "put",
-            headers: {
-                "Content-Type": "application/json;charset=utf-8"
-            },
-            body: JSON.stringify(data)
-        })
-            .then(response => response.json())
-            .then((response)=>{
-                if(typeof(response) === "string"){
-                    controller.createBanner(response, "error");
-                }else{
-                    merchant.updateRecipe(recipe, response);
-                    state.updateRecipes();
-                    controller.openStrand("recipeBook");
-                    controller.createBanner("RECIPE UPDATED", "success");
-                }
-            })
-            .catch((err)=>{
-                controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
-            })
-            .finally(()=>{
-                loader.style.display = "none";
-            });
+    submit: function(){
+        console.log("submitting");
     }
-}
-
-module.exports = editRecipe;
+}

+ 136 - 0
views/dashboardPage/js/sidebars/editRecipe2.js

@@ -0,0 +1,136 @@
+let editRecipe = {
+    display: function(recipe){
+        document.getElementById("sidebarDiv").classList.add("sidebarWide");
+        let nameInput = document.getElementById("editRecipeName");
+        if(merchant.pos === "none"){
+            nameInput.value = recipe.name;
+            let categoryInput = document.getElementById("editRecipeCategory");
+            categoryInput.value = recipe.category;
+            categoryInput.parentElement.style.display = "block";
+        }else{
+            document.getElementById("editRecipeNoName").innerText = recipe.name;
+            nameInput.parentNode.style.display = "none";
+        }
+
+        //Populate ingredients
+        let ingredientList = document.getElementById("editRecipeIngList");
+
+        while(ingredientList.children.length > 0){
+            ingredientList.removeChild(ingredientList.firstChild);
+        }
+
+        let template = document.getElementById("editRecipeIng").content.children[0];
+        for(let i = 0; i < recipe.ingredients.length; i++){
+            let ingredientDiv = template.cloneNode(true);
+            ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
+            ingredientDiv.children[1].innerText = recipe.ingredients[i].ingredient.getNameAndUnit();
+            ingredientDiv.children[2].style.display = "none";
+            ingredientDiv.children[3].value = recipe.ingredients[i].quantity;
+            ingredientDiv.ingredient = recipe.ingredients[i];
+            
+            ingredientList.appendChild(ingredientDiv);
+        }
+
+        document.getElementById("addRecIng").onclick = ()=>{this.newIngredient()};
+        document.getElementById("editRecipePrice").value = recipe.price;
+        document.getElementById("editRecipeSubmit").onclick = ()=>{this.submit(recipe)};
+        document.getElementById("editRecipeCancel").onclick = ()=>{controller.openSidebar("recipeDetails", recipe)};
+    },
+
+    newIngredient: function(){
+        let ingredientList = document.getElementById("editRecipeIngList");
+
+        let ingredientDiv = document.getElementById("editRecipeIng").content.children[0].cloneNode(true);
+        ingredientDiv.children[0].onclick = ()=>{ingredientDiv.parentNode.removeChild(ingredientDiv)};
+        ingredientDiv.children[1].style.display = "none";
+        ingredientDiv.children[3].value = "0.00";
+
+        //Populate selector
+        let categories = merchant.categorizeIngredients();
+        for(let i = 0; i < categories.length; i++){
+            let group = document.createElement("optgroup");
+            group.label = categories[i].name;
+
+            for(let j = 0; j < categories[i].ingredients.length; j++){
+                let option = document.createElement("option");
+                option.innerText = categories[i].ingredients[j].ingredient.getNameAndUnit();
+                option.ingredient = categories[i].ingredients[j];
+                group.appendChild(option);
+            }
+            
+            ingredientDiv.children[2].appendChild(group);
+        }
+
+        ingredientList.appendChild(ingredientDiv);
+    },
+
+    submit: function(recipe){
+        let data = {
+            id: recipe.id,
+            name: recipe.name,
+            price: document.getElementById("editRecipePrice").value * 100,
+            category: document.getElementById("editRecipeCategory").value,
+            ingredients: []
+        }
+
+        if(merchant.pos === "none"){
+            data.name = document.getElementById("editRecipeName").value;
+        }
+
+        let ingredients = document.getElementById("editRecipeIngList").children;
+        for(let i = 0; i < ingredients.length; i++){
+            const quantity = parseFloat(ingredients[i].children[3].value);
+            let newIngredient = {};
+            let ingredient = {};
+
+            if(ingredients[i].children[1].style.display === "none"){
+                let selector = ingredients[i].children[2];
+                ingredient = selector.options[selector.selectedIndex].ingredient;
+
+                newIngredient = {
+                    ingredient: ingredient.ingredient.id,
+                    quantity: controller.baseUnit(quantity, ingredient.ingredient.unit)
+                };
+            }else{
+                ingredient = ingredients[i].ingredient;
+
+                newIngredient = {
+                    ingredient: ingredient.ingredient.id,
+                    quantity: controller.baseUnit(quantity, ingredient.ingredient.unit)
+                };
+            }
+
+            data.ingredients.push(newIngredient);
+        }
+
+        let loader = document.getElementById("loaderContainer");
+        loader.style.display = "flex";
+
+        fetch("/recipe/update", {
+            method: "put",
+            headers: {
+                "Content-Type": "application/json;charset=utf-8"
+            },
+            body: JSON.stringify(data)
+        })
+            .then(response => response.json())
+            .then((response)=>{
+                if(typeof(response) === "string"){
+                    controller.createBanner(response, "error");
+                }else{
+                    merchant.updateRecipe(recipe, response);
+                    state.updateRecipes();
+                    controller.openStrand("recipeBook");
+                    controller.createBanner("RECIPE UPDATED", "success");
+                }
+            })
+            .catch((err)=>{
+                controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
+            })
+            .finally(()=>{
+                loader.style.display = "none";
+            });
+    }
+}
+
+module.exports = editRecipe;

+ 1 - 0
views/dashboardPage/js/sidebars/newRecipe.js

@@ -30,6 +30,7 @@ let newRecipe = {
                 let ingredient = document.createElement("button");
                 ingredient.innerText = this.unchosen[i].name;
                 ingredient.classList.add("choosable");
+                ingredient.classList.add("selection");
                 ingredient.onclick = ()=>{
                     this.add(this.unchosen[i]);
                     this.unchosen.splice(i, 1);