Lee Morgan 6 năm trước cách đây
mục cha
commit
bf2a726a98

+ 15 - 1
controllers/home.js

@@ -64,7 +64,9 @@ module.exports = {
             });
     },
 
-    merchantSetup: function(req, res){
+    //Display page to set up new merchant with Clover POS
+    //TODO: This is for development, needs updating for production
+    merchantSetupClover: function(req, res){
         Ingredient.find()
             .then((ingredients)=>{
                 axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${merchantId}/items?access_token=${token}`)
@@ -82,6 +84,18 @@ module.exports = {
             });
     },
 
+    //Display page to set up merchant with no POS system
+    merchantSetupNone: function(req, res){
+        Ingredient.find()
+            .then((ingredients)=>{
+                return res.render("merchantSetupPage/merchantSetup", {ingredients: ingredients});
+            })
+            .catch((err)=>{
+                console.log(err);
+                return res.render("error");
+            });
+    },
+
     displayRecipes: function(req, res){
         if(!req.session.user){
             return res.render("error");

+ 1 - 4
models/merchant.js

@@ -18,10 +18,7 @@ const MerchantSchema = new mongoose.Schema({
         type: String,
         required: true
     },
-    posId: {
-        type: String,
-        required: true
-    },
+    posId: String,
     lastUpdatedTime: {
         type: String,
         default: Date.now()

+ 2 - 1
routes.js

@@ -4,7 +4,8 @@ module.exports = function(app){
     //Render page
     app.get("/", home.landingPage);
     app.get("/inventory", home.displayInventory);
-    app.get("/merchant/new", home.merchantSetup);
+    app.get("/merchant/new/clover", home.merchantSetupClover);
+    app.get("/merchant/new/none", home.merchantSetupNone);
     app.get("/recipes", home.displayRecipes);
 
     //Merchant

+ 0 - 3
views/landingPage/landing.css

@@ -4,9 +4,6 @@ body{
     font-family: 'Saira', sans-serif;
 }
 
-#register{
-    display: none;
-}
 
 #login{
     display: none;

+ 6 - 21
views/landingPage/landing.ejs

@@ -15,37 +15,22 @@
             <button onclick="landingPage.choosePos()">Register</button>
         </div>
 
-        <form id="login">
-
-        </form>
+        <form id="login"></form>
 
         <div id="pos">
             <h1>Choose your POS System</h1>
             <div class="cards">
-                <div>
+                <a href="/merchant/new/clover">
                     <img src="../shared/images/clover-logo.jpeg">
-                </div>
-                <div>
+                </a>
+                <a href="/merchant/new/none">
                     <img src="../shared/images/logo.png">
                     <p>None</p>
-                </div>
+                </a>
             </div>
         </div>
 
-        <form id="register" onsubmit="landingPage.register()">
-            <label>Email
-                <input id="regEmail" type="email" required>
-            </label>
-
-            <label>Password
-                <input id="regPass" type="password" required>
-            </label>
-
-            <label>Confirm Password
-                <input id="regConfirmPass" type="password" required>
-            </label>
-        </form>
-
+        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
         <script src="../shared/validation.js"></script>
         <script src="/landingPage/landing.js"></script>
     </body>

+ 9 - 6
views/landingPage/landing.js

@@ -1,14 +1,17 @@
 let landingPage = {
-    clearScreen: function(){
-        document.querySelector("#main").style.display = "none";
-        document.querySelector("#login").style.display = "none";
-        document.querySelector("#pos").style.display = "none";
-        document.querySelector("#register").style.display = "none";
+    mainComp: document.querySelector("#main"),
+    loginComp: document.querySelector("#login"),
+    posComp: document.querySelector("#pos"),
 
+    //Remove all displayed components
+    clearScreen: function(){
+        this.mainComp.style.display = "none";
+        this.loginComp.style.display = "none";
+        this.posComp.style.display = "none";
     },
 
     choosePos: function(){
         this.clearScreen();
-        document.querySelector("#pos").style.display = "flex";
+        this.posComp.style.display = "flex";
     }
 }

+ 42 - 14
views/merchantSetupPage/controller.js

@@ -1,18 +1,46 @@
-let data = {}; //For storing all data from user to pass to backend
-
-//Divs to switch out to show different pages
-let addIngredients = document.querySelector("#addIngredients");
-let newIngredients = document.querySelector("#newIngredients");
-let createRecipes = document.querySelector("#createRecipes");
-
-//General purpose  data validator
-let checkValid = (valueToCheck, inputField)=>{
-    if(!validator.ingredient[valueToCheck](inputField.value, createBanner = false)){
-        inputField.classList += " input-error"
-    }else{
-        inputField.classList.remove("input-error");
+// let data = {}; //For storing all data from user to pass to backend
+
+// //Divs to switch out to show different pages
+// let addIngredients = document.querySelector("#addIngredients");
+// let newIngredients = document.querySelector("#newIngredients");
+// let createRecipes = document.querySelector("#createRecipes");
+
+// //General purpose  data validator
+// let checkValid = (valueToCheck, inputField)=>{
+//     if(!validator.ingredient[valueToCheck](inputField.value, createBanner = false)){
+//         inputField.classList += " input-error"
+//     }else{
+//         inputField.classList.remove("input-error");
+//     }
+// }
+
+let controller = {
+    data: {},  //For storing all data from user to pass to backend
+
+    //Component divs
+    addIngredientsComp: document.querySelector("#addIngredients"),
+    newIngredientsComp: document.querySelector("#newIngredients"),
+    createRecipesComp: document.querySelector("#createRecipes"),
+
+    run: function(){
+        
+    },
+
+    //General purpose data validator
+    checkValid: function(valueToCheck, inputField){
+        if(!validator.ingredient[valueToCheck](inputField.value, createBanner = false)){
+            inputField.classList += " input-error"
+        }else{
+            inputField.classList.remove("input-error");
+        }
+    },
+
+    clearScreen: function(){
+        this.addIngredientsComp.style.display = "none";
+        this.newIngredientsComp.style.display = "none";
+        this.createRecipesComp.style.display = "none";
     }
 }
 
 //Run first function
-ingredientSetup.populateIngredients();
+controller.run();

+ 3 - 3
views/merchantSetupPage/ingredientSetup.js

@@ -53,9 +53,9 @@ let ingredientSetup = {
     //Display existing ingredients table
     //Hide other tables
     displayExistingIngredients: function(){
-        addIngredients.style.display = "flex";
-        newIngredients.style.display = "none";
-        createRecipes.style.display = "none";
+        controller.addIngredients.style.display = "flex";
+        controller.newIngredients.style.display = "none";
+        controller.createRecipes.style.display = "none";
     },
 
     //Display new ingredients table

+ 5 - 1
views/merchantSetupPage/merchantSetup.ejs

@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <html>
     <head>
+        <title>The Subline</title>
         <link rel="stylesheet" href="/merchantSetupPage/merchantSetup.css">
         <link rel="stylesheet" href="/shared/shared.css">
     </head>
@@ -77,7 +78,10 @@
 
         <script>
             let ingredients = <%- JSON.stringify(ingredients) %>;
-            let recipes = <%- JSON.stringify(recipes) %>;
+            if(locals.recipes){
+                console.log("something");
+                
+            }
         </script>
         <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
         <script src="../shared/validation.js"></script>

+ 20 - 0
views/shared/validation.js

@@ -49,6 +49,26 @@ let validator = {
                 return false;
             }
 
+            return true;
+        }
+    },
+
+    merchant: {
+        password: function(pass, confirmPass, createBanner = true){
+            if(pass !== confirmPass){
+                if(createBanner){
+                    banner.createError("Your passwords do not match");
+                }
+                return false;
+            }
+
+            if(pass.length < 15){
+                if(createBanner){
+                    banner.createError("Your password must contain at least 15 characters");
+                }
+                return false;
+            }
+
             return true;
         }
     }