Lee Morgan 5 лет назад
Родитель
Сommit
8800a17d5e

+ 0 - 52
controllers/merchantData.js

@@ -238,58 +238,6 @@ module.exports = {
             });
     },
 
-    /*
-    //POST - Adds an ingredient to merchant's inventory
-    req.body = [{
-        id: ingredient id,
-        quantity: quantity of ingredient for the merchant
-        defaultUnit: default unit of measurement to display
-    }]
-    */
-    addMerchantIngredient: function(req, res){
-        if(!req.session.user){
-            req.session.error = "MUST BE LOGGED IN TO DO THAT";
-            return res.redirect("/");
-        }
-
-        let validation;
-        for(let i = 0; i < req.body.length; i++){
-            validation = Validator.quantity(req.body[i].quantity);
-            if(validation !== true){
-                return res.json(validation);
-            }
-        }
-        
-
-        Merchant.findOne({_id: req.session.user})
-            .then((merchant)=>{
-                for(let i = 0; i < req.body.length; i++){
-                    for(let j = 0; j < merchant.inventory.length; j++){
-                        if(merchant.inventory[j].ingredient.toString() === req.body[i].id){
-                            return res.json("ERROR: DUPLICATE INGREDIENT DETECTED");
-                        }
-                    }
-                    
-                    merchant.inventory.push({
-                        ingredient: req.body[i].id,
-                        quantity: req.body[i].quantity,
-                        defaultUnit: req.body[i].defaultUnit
-                    });
-                }
-
-                merchant.save()
-                    .then((newMerchant)=>{
-                        return res.json({});
-                    })
-                    .catch((err)=>{
-                        return res.json("ERROR: UNABLE TO SAVE NEW INGREDIENT");
-                    });
-            })
-            .catch((err)=>{
-                return res.json("ERROR: UNABLE TO RETRIEVE USER DATA");
-            });
-    },
-
     //POST - Removes an ingredient from the merchant's inventory
     removeMerchantIngredient: function(req, res){
         if(!req.session.user){

+ 0 - 1
routes.js

@@ -18,7 +18,6 @@ module.exports = function(app){
     app.get("/merchant/create/clover", merchantData.createMerchantClover);
     app.get("/merchant/create/square", merchantData.createMerchantSquare);
     app.delete("/merchant/recipes/remove/:id", merchantData.removeRecipe);
-    app.post("/merchant/ingredients/add", merchantData.addMerchantIngredient);
     app.delete("/merchant/ingredients/remove/:id", merchantData.removeMerchantIngredient);
     app.put("/merchant/ingredients/update/:id/:unit", merchantData.ingredientDefaultUnit);
     app.put("/merchant/ingredients/update", merchantData.updateMerchantIngredient);

+ 1 - 2
views/dashboardPage/dashboard.ejs

@@ -150,7 +150,7 @@
                 <div class="strandHead">
                     <h1 class="strandTitle">INGREDIENT INVENTORY</h1>
 
-                    <button class="button mobileHide" onclick="controller.openSidebar('addIngredients')">NEW</button>
+                    <button class="button mobileHide" onclick="controller.openSidebar('newIngredient')">NEW</button>
                 </div>
 
                 <div class="searchBar">
@@ -366,7 +366,6 @@
         </div>
 
         <div id="sidebarDiv" class="sidebarHide">
-            <% include ./sidebars/addIngredients %>
             <% include ./sidebars/newIngredient %>
             <% include ./sidebars/ingredientDetails %>
             <% include ./sidebars/recipeDetails %>

+ 0 - 224
views/dashboardPage/js/addIngredients.js

@@ -1,224 +0,0 @@
-let addIngredients = {
-    isPopulated: false,
-    fakeMerchant: {},
-    chosenIngredients: [],
-
-    display: function(Merchant){
-        if(!this.isPopulated){
-            let loader = document.getElementById("loaderContainer");
-            loader.style.display = "flex";
-
-            fetch("/ingredients")
-                .then((response) => response.json())
-                .then((response)=>{
-                    if(typeof(response) === "string"){
-                        banner.createError(response);
-                    }else{
-                        for(let i = 0; i < merchant.ingredients.length; i++){
-                            for(let j = 0; j < response.length; j++){
-                                if(merchant.ingredients[i].ingredient.id === response[j]._id){
-                                    response.splice(j, 1);
-                                    break;
-                                }
-                            }
-                        }
-                        
-                        for(let i = 0; i < response.length; i++){
-                            response[i] = {ingredient: response[i]}
-                        }
-                        this.fakeMerchant = new Merchant({
-                                name: "none",
-                                inventory: response,
-                                recipes: [],
-                            },
-                            []
-                        );
-
-                        this.populateAddIngredients(true);
-                    }
-                })
-                .catch((err)=>{
-                    banner.createError("UNABLE TO RETRIEVE DATA");
-                })
-                .finally(()=>{
-                    loader.style.display = "none";
-                });
-
-            this.isPopulated = true;
-        }
-    },
-
-    populateAddIngredients: function(newRequest = false){
-        let addIngredientsDiv = document.getElementById("addIngredientList");
-        let categoryTemplate = document.getElementById("addIngredientsCategory");
-        let ingredientTemplate = document.getElementById("addIngredientsIngredient");
-
-        let categories = this.fakeMerchant.categorizeIngredients();
-
-        while(addIngredientsDiv.children.length > 0){
-            addIngredientsDiv.removeChild(addIngredientsDiv.firstChild);
-        }
-        for(let i = 0; i < categories.length; i++){
-            let categoryDiv = categoryTemplate.content.children[0].cloneNode(true);
-            categoryDiv.children[0].children[0].innerText = categories[i].name;
-            categoryDiv.children[0].children[1].onclick = ()=>{this.toggleAddIngredient(categoryDiv)};
-            categoryDiv.children[1].style.display = "none";
-            categoryDiv.children[0].children[1].children[1].style.display = "none";
-
-            addIngredientsDiv.appendChild(categoryDiv);
-            
-            for(let j = 0; j < categories[i].ingredients.length; j++){
-                let ingredientDiv = ingredientTemplate.content.children[0].cloneNode(true);
-                ingredientDiv.children[0].children[0].innerText = categories[i].ingredients[j].ingredient.name;
-                ingredientDiv.children[0].children[1].onclick = ()=>{this.addOne(ingredientDiv)};
-                ingredientDiv.ingredient = categories[i].ingredients[j].ingredient;
-
-                categoryDiv.children[1].appendChild(ingredientDiv);
-            }
-        }
-
-        if(newRequest){
-            let myIngredients = document.getElementById("myIngredients");
-            while(myIngredients.children.length > 0){
-                myIngredients.removeChild(myIngredients.firstChild);
-            }
-        }
-
-        document.getElementById("addIngredientsBtn").onclick = ()=>{this.submit()};
-        document.getElementById("openNewIngredient").onclick = ()=>{controller.openSidebar("newIngredient")};
-    },
-
-    toggleAddIngredient: function(categoryElement){
-        let button = categoryElement.children[0].children[1];
-        let ingredientDisplay = categoryElement.children[1];
-
-        if(ingredientDisplay.style.display === "none"){
-            ingredientDisplay.style.display = "flex";
-
-            button.children[0].style.display = "none";
-            button.children[1].style.display = "block";
-        }else{
-            ingredientDisplay.style.display = "none";
-
-            button.children[0].style.display = "block";
-            button.children[1].style.display = "none";
-        }
-    },
-
-    addOne: function(element){
-        element.parentElement.removeChild(element);
-        document.getElementById("myIngredients").appendChild(element);
-        document.getElementById("myIngredientsDiv").style.display = "flex";
-        element.children[1].style.display = "flex";
-
-        for(let i = 0; i < this.fakeMerchant.ingredients.length; i++){
-            if(this.fakeMerchant.ingredients[i].ingredient === element.ingredient){
-                this.fakeMerchant.ingredients.splice(i, 1);
-                this.chosenIngredients.push(element.ingredient);
-                break;
-            }
-        }
-
-        let select = element.children[1].children[1];
-        let units = merchant.units[element.ingredient.unitType];
-        for(let i = 0; i < units.length; i++){
-            let option = document.createElement("option");
-            option.innerText = units[i].toUpperCase();
-            option.type = element.ingredient.unitType;
-            option.value = units[i];
-            select.appendChild(option);
-        }
-
-        element.children[0].children[1].innerText = "-";
-        element.children[0].children[1].onclick = ()=>{this.removeOne(element)};
-    },
-
-    removeOne: function(element){
-        element.parentElement.removeChild(element);
-        element.children[1].style.display = "none";
-
-        let select = element.children[0].children[1];
-        while(select.children.length > 0){
-            select.removeChild(select.firstChild);
-        }
-
-        element.children[0].children[1].innerText = "+";
-        element.children[0].children[1].onclick = ()=>{this.addOne(element)};
-
-        if(document.getElementById("myIngredients").children.length === 0){
-            document.getElementById("myIngredientsDiv").style.display = "none";
-        }
-
-        for(let i = 0; i < this.chosenIngredients.length; i++){
-            if(this.chosenIngredients[i] === element.ingredient){
-                this.chosenIngredients.splice(i, 1);
-                this.fakeMerchant.ingredients.push({
-                    ingredient: element.ingredient
-                });
-                break;
-            }
-        }
-        
-        this.populateAddIngredients();
-    },
-
-    submit: function(){
-        let ingredients = document.getElementById("myIngredients").children;
-        let newIngredients = [];
-        let fetchable = [];
-
-        for(let i = 0; i < ingredients.length; i++){
-            let quantity = ingredients[i].children[1].children[0].value;
-            let unit = ingredients[i].children[1].children[1].value;
-
-            if(quantity === ""){
-                banner.createError("PLEASE ENTER A QUANTITY FOR EACH INGREDIENT YOU WANT TO ADD TO YOUR INVENTORY");
-                return;
-            }
-            quantity = controller.convertToMain(unit, quantity);
-
-            let newIngredient = {
-                ingredient: ingredients[i].ingredient,
-                quantity: quantity
-            }
-            newIngredient.ingredient.unit = unit;
-
-            newIngredients.push(newIngredient);
-
-            fetchable.push({
-                id: ingredients[i].ingredient.id,
-                quantity: quantity,
-                defaultUnit: unit
-            });
-        }
-
-        let loader = document.getElementById("loaderContainer");
-        loader.style.display = "flex";
-
-        fetch("/merchant/ingredients/add", {
-            method: "POST",
-            headers: {
-                "Content-Type": "application/json;charset=utf-8"
-            },
-            body: JSON.stringify(fetchable)
-        })
-            .then((response) => response.json())
-            .then((response)=>{
-                if(typeof(response) === "string"){
-                    banner.createError(response);
-                }else{
-                    merchant.editIngredients(newIngredients);
-                    this.isPopulated = false;
-                    banner.createNotification("ALL INGREDIENTS ADDED");
-                }
-            })
-            .catch((err)=>{
-                banner.createError("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE");
-            })
-            .finally(()=>{
-                loader.style.display = "none";
-            });
-    }
-}
-
-module.exports = addIngredients;

+ 0 - 64
views/dashboardPage/sidebars/addIngredients.ejs

@@ -1,64 +0,0 @@
-<div id="addIngredients">
-    <div class="sidebarIconButtons">
-        <button class="iconButton" 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>
-        </button>
-    </div>
-    
-    <h2>AVAILABLE INGREDIENTS</h2>
-
-    <div id="addIngredientList"></div>
-
-    <div class="lineBorder"></div>
-
-    <div id="myIngredientsDiv">
-        <h2>MY INGREDIENTS</h2>
-
-        <div id="myIngredients"></div>
-
-        <div class="lineBorder"></div>
-    </div>
-
-    <button id="addIngredientsBtn" class="button">CREATE</button>
-
-    <button class="button2Link" id="openNewIngredient">CAN'T FIND WHAT YOU'RE LOOKING FOR? CREATE IT...</button>
-
-    <template id="addIngredientsCategory">
-        <div class="addIngredientsCategory">
-            <div class="categoryHeader">
-                <h5></h5>
-                
-                <button>
-                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
-                        <polyline points="6 9 12 15 18 9"></polyline>
-                    </svg>
-
-                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
-                        <polyline points="18 15 12 9 6 15"></polyline>
-                    </svg>
-                </button>
-            </div>
-
-            <div class="addIngredientsIngredients"></div>
-        </div>
-    </template>
-
-    <template id="addIngredientsIngredient">
-        <div class="addIngredientsIngredient">
-            <div>
-                <p></p>
-
-                <button class="addButton">+</button>
-            </div>
-
-            <div style="display: none;">
-                <input type="number" min="0" step="0.01" placeholder="QUANTITY">
-
-                <select></select>
-            </div>
-        </div>
-    </template>
-</div>