Преглед изворни кода

Create basic layout for page

Lee Morgan пре 6 година
родитељ
комит
3992b202aa
5 измењених фајлова са 185 додато и 0 уклоњено
  1. 18 0
      controllers/home.js
  2. 1 0
      routes.js
  3. 67 0
      views/recipesPage/recipes.css
  4. 34 0
      views/recipesPage/recipes.ejs
  5. 65 0
      views/recipesPage/recipes.js

+ 18 - 0
controllers/home.js

@@ -213,5 +213,23 @@ module.exports = {
                 console.log(err);
                 return res.json("error");
             });
+    },
+
+    displayRecipes: function(req, res){
+        Merchant.findOne({cloverId: merchantId})
+            .populate({
+                path: "recipes",
+                populate: {
+                    path: "ingredients.id",
+                    model: "Ingredient"
+                }
+            })
+            .then((merchant)=>{
+                return res.render("recipesPage/recipes", {recipes: merchant.recipes});
+            })
+            .catch((err)=>{
+                console.log(err);
+                return res.render("error");
+            });
     }
 }

+ 1 - 0
routes.js

@@ -9,4 +9,5 @@ module.exports = function(app){
     app.post("/ingredients/update", home.updateIngredient);
     app.post("/ingredients/remove", home.removeIngredient);
     app.post("/ingredients/createone", home.createIngredient);
+    app.get("/recipes", home.displayRecipes);
 }

+ 67 - 0
views/recipesPage/recipes.css

@@ -0,0 +1,67 @@
+*{margin:0;padding:0;}
+
+body{
+    text-align: center;
+}
+
+h1{
+    margin-bottom: 25px;
+}
+
+.container{
+    display: flex;
+    justify-content: space-around;
+    flex-wrap: wrap;
+    padding: 25px;
+}
+
+    .recipe-card{
+        border: 2px solid #ff626b;
+        box-shadow: 2px 2px 2px #001b2d;
+        background: #001b2d;
+        color: #ff626b;
+        width: 20%;
+        padding: 35px;
+        margin: 25px;
+        border-radius: 10px;
+        cursor: pointer;
+    }
+
+        .recipe-card:hover{
+            transform: translateY(-3px);
+        }
+
+        h2{
+            border-bottom: 2px solid #ff626b;
+            margin-bottom: 15px;
+        }
+
+    #ingredient{
+        display: none;
+    }
+
+        th{
+            border: 2px solid #ff626b;
+            background: #001b2d;
+            color: darkgray;
+            padding: 3px;
+            min-width: 150px;
+        }
+
+        th:nth-of-type(3){
+            border: none;
+            background: none;
+            color: white;
+            min-width: 0;
+            cursor: auto;
+        }
+
+        td{
+            border: 1px solid black;
+            text-align: center;
+            padding: 1px 10px;
+        }
+
+        td:nth-of-type(3n){
+            border: none;
+        }

+ 34 - 0
views/recipesPage/recipes.ejs

@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <link rel="stylesheet" href="/recipesPage/recipes.css">
+        <link rel="stylesheet" href="/shared/shared.css">
+    </head>
+    <body>
+        <% include ../shared/header %>
+
+        <% include ../shared/banner %>
+
+        <h1>Recipes</h1>
+
+        <div id="recipes" class="container"></div>
+
+        <div id="ingredient" class="container">
+            <table>
+                <thead>
+                    <tr>
+                        <th>Name</th>
+                        <th>Quantity</th>
+                        <th></th>
+                    </tr>
+                </thead>
+                <tbody></tbody>
+            </table>
+        </div>
+
+        <script>let recipes = <%- JSON.stringify(recipes) %>;</script>
+        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
+        <script src="../shared/validation.js"></script>
+        <script src="/recipesPage/recipes.js"></script>
+    </body>
+</html>

+ 65 - 0
views/recipesPage/recipes.js

@@ -0,0 +1,65 @@
+console.log(recipes);
+
+let recipesPage = {
+    //Display all recipes on a card
+    displayRecipes: function(){
+        let body = document.querySelector(".container");
+        
+        for(let recipe of recipes){
+            let recipeDiv = document.createElement("div");
+            recipeDiv.classList = "recipe-card";
+            recipeDiv.onclick = ()=>{this.displayOneRecipe(recipe)};
+            body.appendChild(recipeDiv);
+
+            let title = document.createElement("h2");
+            title.innerText = recipe.name;
+            recipeDiv.appendChild(title);
+
+            let ingredientList = document.createElement("ul");
+            recipeDiv.appendChild(ingredientList);
+
+            for(let ingredient of recipe.ingredients){
+                let ul = document.createElement("li");
+                ul.innerText = ingredient.id.name;
+                ingredientList.appendChild(ul);
+            }
+        }
+    },
+
+    displayOneRecipe: function(recipe){
+        let recipesDiv = document.querySelector("#recipes");
+        let ingredientDiv = document.querySelector("#ingredient");
+        let tbody = document.querySelector("tbody");
+
+        recipesDiv.style.display = "none";
+        ingredientDiv.style.display = "flex";
+
+        for(let ingredient of recipe.ingredients){
+            let row = document.createElement("tr");
+            tbody.appendChild(row);
+
+            let name = document.createElement("td");
+            name.innerText = ingredient.id.name;
+            row.appendChild(name);
+
+            let quantity = document.createElement("td");
+            quantity.innerText = `${ingredient.quantity} ${ingredient.id.unitType}`;
+            row.appendChild(quantity);
+
+            let actions = document.createElement("td");
+            row.appendChild(actions);
+
+            let removeButton = document.createElement("button");
+            removeButton.innerText = "Remove";
+            removeButton.onclick = ()=>{deleteIngredient(ingredient);};
+            actions.appendChild(removeButton);
+
+        }
+    },
+
+    deleteIngredient: function(ingredient){
+        
+    }
+}
+
+recipesPage.displayRecipes();