소스 검색

Remove all references to unitType.

Lee Morgan 5 년 전
부모
커밋
5644f06b69

+ 0 - 28
controllers/helper.js

@@ -126,34 +126,6 @@ module.exports = {
         return result;
     },
 
-    getUnitType: function(unit){
-        let unitType = "";
-
-        switch(unit){
-            case "g": unitType = "mass"; break;
-            case "kg": unitType = "mass"; break;
-            case "oz": unitType = "mass"; break;
-            case "lb": unitType = "mass"; break;
-            case "ml": unitType = "volume"; break;
-            case "l": unitType = "volume"; break;
-            case "tsp": unitType = "volume"; break;
-            case "tbsp": unitType = "volume"; break;
-            case "ozfl": unitType = "volume"; break;
-            case "cup": unitType = "volume"; break;
-            case "pt": unitType = "volume"; break;
-            case "qt": unitType = "volume"; break;
-            case "gal": unitType = "volume"; break;
-            case "mm": unitType = "length"; break;
-            case "cm": unitType = "length"; break;
-            case "m": unitType = "length"; break;
-            case "in": unitType = "length"; break;
-            case "ft": unitType = "length"; break;
-            default: unitType = "other"; break;
-        }
-
-        return unitType;
-    },
-
     createRecipesFromSquare: function(squareItems, categories, merchantId){
         let recipes = [];
 

+ 0 - 92
controllers/ingredientData.js

@@ -184,98 +184,6 @@ module.exports = {
             });
     },
 
-    createFromSpreadsheet: function(req, res){
-        //read file, get the correct sheet, create array from sheet
-        let workbook = xlsx.readFile(req.file.path);
-        fs.unlink(req.file.path, ()=>{});
-
-        let sheets = Object.keys(workbook.Sheets);
-        let sheet = {};
-        for(let i = 0; i < sheets.length; i++){
-            let str = sheets[i].toLowerCase();
-            if(str === "ingredient" || str === "ingredients"){
-                sheet = workbook.Sheets[sheets[i]];
-            }
-        }
-        const array = xlsx.utils.sheet_to_json(sheet, {
-            header: 1
-        });
-
-        //get property locations
-        let locations = {};
-        for(let i = 0; i < array[0].length; i++){
-            switch(array[0][i].toLowerCase()){
-                case "name": locations.name = i; break;
-                case "category": locations.category = i; break;
-                case "quantity": locations.quantity = i; break;
-                case "unit": locations.unit = i; break;
-                case "bottle size": locations.bottleSize = i; break;
-                case "bottle unit": locations.bottleUnit = i; break;
-            }
-        }
-
-        //Create ingredients
-        let ingredients = [];
-        let merchantData = [];
-        for(let i = 1; i < array.length; i++){
-            let ingredient = new Ingredient({
-                name: array[i][locations.name],
-                category: array[i][locations.category],
-                unitType: helper.getUnitType(array[i][locations.unit].toLowerCase())
-            });
-
-            if(array[i][locations.unit] === "bottle"){
-                ingredient.unitType = array[i][locations.bottleUnit];
-                ingredient.unitSize = helper.convertQuantityToBaseUnit(array[i][locations.bottleSize], array[i][locations.bottleUnit]);
-            }
-
-            let merchantItem = {
-                ingredient: ingredient,
-                quantity: helper.convertQuantityToBaseUnit(array[i][locations.quantity], array[i][locations.unit]),
-                defaultUnit: array[i][locations.unit]
-            }
-            
-            merchantData.push(merchantItem);
-            ingredients.push(ingredient);
-        }
-
-        for(let i = 0; i < merchantData.length; i++){
-            res.locals.merchant.inventory.push(merchantData[i]);
-        }
-
-        //Update the database
-        Promise.all([Ingredient.create(ingredients), res.locals.merchant.save()])
-            .then((response)=>{
-                return res.json(merchantData);
-            })
-            .catch((err)=>{
-                if(typeof(err) === "string"){
-                    return res.json(err);
-                }
-                if(err.name === "ValidationError"){
-                    return res.json(err.errors[Object.keys(err.errors)[0]].properties.message);
-                }
-                return "ERROR: UNABLE TO CREATE YOUR INGREDIENTS";
-            });
-    },
-
-    spreadsheetTemplate: function(req, res){
-        let workbook = xlsx.utils.book_new();
-        workbook.SheetNames.push("Ingredients");
-        let workbookData = [];
-
-        workbookData.push(["Name", "Category", "Quantity", "Unit", "Bottle Size", "Bottle Unit"]);
-        workbookData.push(["Example Ingredient 1", "Produce", 100, "lbs"]);
-        workbookData.push(["Example Ingredient 2", "Fruit", 3.24, "kg"]);
-        workbookData.push(["Example Ingredient 3", "Beverage", 5, "bottle", 750, "ml"]);
-
-        workbook.Sheets.Ingredients = xlsx.utils.aoa_to_sheet(workbookData);
-        xlsx.writeFile(workbook, "SublineIngredients.xlsx");
-        return res.download("SublineIngredients.xlsx", (err)=>{
-            fs.unlink("SublineIngredients.xlsx", ()=>{});
-        });
-    },
-
     //DELETE - Removes an ingredient from the merchant's inventory
     removeIngredient: function(req, res){
         for(let i = 0; i < res.locals.merchant.inventory.length; i++){

+ 1 - 1
views/dashboardPage/js/classes/Ingredient.js

@@ -11,7 +11,7 @@ class SubIngredient{
     }
 
     getDisplayQuantity(){
-        let mult = controller.unitMultiplier(controller.unitType(this.parent.unit), this.parent.unit);
+        let mult = controller.unitMultiplier(controller.getUnitType(this.parent.unit), this.parent.unit);
         return `${this.quantity * mult} ${this.unit} / ${this.parent.unit}`;
     }
 }

+ 1 - 4
views/dashboardPage/js/classes/Merchant.js

@@ -248,7 +248,6 @@ class Merchant{
             _id: String,
             name: String,
             category: String,
-            unitType: String,
             specialUnit: String || undefined,
             unitSize: Number || undefined
         }
@@ -291,9 +290,7 @@ class Merchant{
             inventoryItem.quantity = ingredients[i].quantity;
             inventoryItem.ingredient.id = ingredients[i].ingredient._id;
             inventoryItem.ingredient.name = ingredients[i].ingredient.name;
-            inventoryItem.ingredient.unitType = ingredients[i].ingredient.unitType;
-            inventoryItem.ingredient.unit = ingredients[i].defaultUnit;
-            inventoryItem.ingredient.unitSize = ingredients[i].ingredient.unitSize;
+            inventoryItem.ingredient.unit = ingredients[i].ingredient.unit;
             inventoryItem.ingredient.addIngredients(ingredients[i].ingredient.ingredients);
         }
     }

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

@@ -27,13 +27,6 @@ class RecipeIngredient{
     getQuantityDisplay(){
         return `${this._quantity.toFixed(2)} ${this._unit.toUpperCase()}`;
     }
-
-    getQuantityAsBase(){
-        if(controller.unitType(this._unit) === "mass") return this._quantity / this._ingredient.convert.toMass;
-        if(controller.unitType(this._unit) === "volume") return this._quantity / this._ingredient.convert.toVolume;
-        if(controller.unittype(this._unit) === "length") return this._quantity / this._ingredient.convert.toLength;
-        return this._quantity;
-    }
 }
 
 /*

+ 21 - 6
views/dashboardPage/js/dashboard.js

@@ -426,12 +426,27 @@ controller = {
         }
     },
 
-    //TOREMOVE
-    unitType(unit){
-        if(["g", "kg", "oz", "lb"].includes(unit)) return "mass";
-        if(["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"].includes(unit)) return "volume";
-        if(["mm", "cm", "m", "in", "ft"].includes(unit)) return "length";
-        return "other";
+    getUnitType(unit){
+        switch(unit){
+            case "g": return "mass";
+            case "kg": return "mass";
+            case "oz": return "mass";
+            case "lb": return "mass";
+            case "l": return "volume";
+            case "ml": return "volume";
+            case "tsp": return "volume";
+            case "tbsp": return "volume";
+            case "ozfl": return "volume";
+            case "cup": return "volume";
+            case "pt": return "volume";
+            case "qt": return "volume";
+            case "gal": return "volume";
+            case "mm": return "length";
+            case "cm": return "length";
+            case "m": return "length";
+            case "in": return "length";
+            case "ft": return "length";
+        }
     },
 
     getBaseUnit(unit){

+ 2 - 2
views/dashboardPage/js/modal.js

@@ -207,7 +207,7 @@ let modal = {
 
             createOptGroup(
                 div.children[1].children[2].children[1],
-                ingredient.unitType,
+                controller.getUnitType(ingredient.unit),
                 ingredient.getPotentialUnits()
             );
 
@@ -252,7 +252,7 @@ let modal = {
 
                     createOptGroup(
                         div.children[1].children[2].children[1],
-                        ingredient.unitType,
+                        controller.getUnitType(ingredient.unit),
                         ingredient.getPotentialUnits()    
                     );
                     div.children[1].children[0].children[1].value = ingredient.unit;

+ 0 - 16
views/dashboardPage/js/sidebars/editIngredient.js

@@ -18,22 +18,6 @@ let editIngredient = {
         quantLabel.innerText = `CURRENT STOCK (${ingredient.ingredient.unit.toUpperCase()})`;
         document.getElementById("editIngSubmit").onclick = ()=>{this.submit(ingredient)};
 
-        //Make any changes for special ingredients
-        if(ingredient.ingredient.unit === "bottle"){
-            specialLabel.style.display = "flex";
-            specialLabel.innerText = `BOTTLE SIZE (${ingredient.ingredient.unitType.toUpperCase()}):`;
-            
-            let sizeInput = document.createElement("input");
-            sizeInput.id = "editIngSpecialSize";
-            sizeInput.type = "number";
-            sizeInput.min = "0";
-            sizeInput.step = "0.01";
-            sizeInput.value = ingredient.ingredient.unitSize.toFixed(2);
-            specialLabel.appendChild(sizeInput);
-        }else{
-            specialLabel.style.display = "none";
-        }
-
         //Populate the unit buttons
         const units = ingredient.ingredient.getPotentialUnits();
 

+ 5 - 13
views/dashboardPage/js/sidebars/editRecipe.js

@@ -87,19 +87,11 @@ module.exports = {
         newItem.children[0].children[1].onclick = ()=>{this.removeIngredient(newItem)};
 
         let select = newItem.children[1].children[1];
-        if(ingredient.ingredient.convert.toMass !== undefined) select.children[0].style.display = "block";
-        if(ingredient.ingredient.convert.toVolume !== undefined) select.children[1].style.display = "block";
-        if(ingredient.ingredient.convert.toLength !== undefined) select.children[2].style.display = "block";
-
-        switch(ingredient.ingredient.unitType){
-            case "mass": select.value = "g"; break;
-            case "volume": select.value = "ml"; break;
-            case "length": select.value = "mm"; break;
-            case "other":
-                select.value = "each";
-                select.children[3].style.display = "block";
-                break;
-        }
+        if(ingredient.ingredient.convert.toMass <= 0) select.children[0].style.display = "block";
+        if(ingredient.ingredient.convert.toVolume <= 0) select.children[1].style.display = "block";
+        if(ingredient.ingredient.convert.toLength <= 0) select.children[2].style.display = "block";
+
+        select.value = ingredient.ingredient.unit;
 
         used.appendChild(newItem);
     },

+ 3 - 7
views/dashboardPage/js/sidebars/newIngredient.js

@@ -26,19 +26,19 @@ let newIngredient = {
         let convertMass = document.getElementById("newIngMassConvert");
         let convertVolume = document.getElementById("newIngVolumeConvert");
         let convertLength = document.getElementById("newIngLengthConvert");
-        if(controller.unitType(select.value) === "mass"){
+        if(controller.getUnitType(select.value) === "mass"){
             convertMass.style.display = "none";
             convertVolume.style.display = "flex";
             convertLength.style.display = "flex";
             document.getElementById("volumeConvertUnitLeft").innerText = select.value.toUpperCase();
             document.getElementById("lengthConvertUnitLeft").innerText = select.value.toUpperCase();
-        }else if(controller.unitType(select.value) === "volume"){
+        }else if(controller.getUnitType(select.value) === "volume"){
             convertMass.style.display = "flex";
             convertVolume.style.display = "none";
             convertLength.style.display = "flex";
             document.getElementById("massConvertUnitLeft").innerText = select.value.toUpperCase();
             document.getElementById("lengthConvertUnitLeft").innerText = select.value.toUpperCase();
-        }else if(controller.unitType(select.value) === "length"){
+        }else if(controller.getUnitType(select.value) === "length"){
             convertMass.style.display = "flex";
             convertVolume.style.display = "flex";
             convertLength.style.display = "none";
@@ -78,10 +78,6 @@ let newIngredient = {
             quantity: controller.baseUnit(quantityValue, unit)
         }
 
-        if(controller.unitType(unit) === "mass") newIngredient.convert.toMass = 1;
-        if(controller.unitType(unit) === "volume") newIngredient.convert.toVolume = 1;
-        if(controller.unitType(unit) === "length") newIngredient.convert.toLength = 1;
-
         if(isNaN(newIngredient.convert.toMass)) newIngredient.convert.toMass = undefined;
         if(isNaN(newIngredient.convert.toVolume)) newIngredient.convert.toVolume = undefined;
         if(isNaN(newIngredient.convert.toLength)) newIngredient.convert.toLength = undefined;

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

@@ -65,15 +65,7 @@ let newRecipe = {
         if(ingredient.convert.toVolume !== undefined) select.children[1].style.display = "block";
         if(ingredient.convert.toLength !== undefined) select.children[2].style.display = "block";
 
-        switch(ingredient.unitType){
-            case "mass": select.value = "g"; break;
-            case "volume": select.value = "ml"; break;
-            case "length": select.value = "mm"; break;
-            case "other":
-                select.children[3].style.display = "block";
-                select.value = "each";
-                break;
-        }
+        select.value = ingredient.unit;
 
         document.getElementById("newRecipeChosenList").appendChild(element);
     },