lokesh341 commited on
Commit
33ddbfe
·
verified ·
1 Parent(s): cff1996

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +34 -168
templates/menu_page.html CHANGED
@@ -68,21 +68,24 @@
68
  <!-- Dynamic Menu Item List -->
69
  <div id="menu-items">
70
  <!-- Menu items will be populated here from the backend -->
 
 
 
 
 
 
 
 
 
 
 
71
  </div>
72
 
73
  <button id="listen-btn">Say "Order" to order an item</button>
74
- <div id="cart-summary" style="display:none;">
75
- <h2>Your Cart:</h2>
76
- <div id="cart-details"></div>
77
- <button id="place-order-btn" onclick="placeOrder()">Place Final Order</button>
78
- </div>
79
  </div>
80
 
81
  <script>
82
  const listenButton = document.getElementById("listen-btn");
83
- const cartSummary = document.getElementById("cart-summary");
84
- const cartDetails = document.getElementById("cart-details");
85
- let cart = []; // Global cart variable to store items
86
  const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
87
  recognition.lang = "en-US";
88
  recognition.interimResults = false;
@@ -93,77 +96,6 @@
93
  window.speechSynthesis.speak(msg);
94
  }
95
 
96
- // Function to fetch and populate the menu
97
- function fetchMenu() {
98
- fetch("/menu")
99
- .then(response => response.json())
100
- .then(data => {
101
- let menuContent = "";
102
- data.forEach(item => {
103
- menuContent += `
104
- <div class="menu-item">
105
- <div class="details">
106
- <h3>${item.name}</h3>
107
- <p><strong>Ingredients:</strong> ${item.ingredients}</p>
108
- <p><strong>Category:</strong> ${item.category}</p>
109
- <p class="price">Price: ₹${item.price}</p>
110
- </div>
111
- <button class="order-btn" onclick="addToCart('${item.name}', ${item.price})">Order</button>
112
- </div>
113
- `;
114
- });
115
- document.getElementById('menu-items').innerHTML = menuContent;
116
- })
117
- .catch(error => console.error("Error fetching menu:", error));
118
- }
119
-
120
- // Function to add item to the cart
121
- function addToCart(itemName, itemPrice) {
122
- const quantity = prompt(`How many ${itemName} would you like?`);
123
- if (quantity && !isNaN(quantity) && quantity > 0) {
124
- cart.push({ name: itemName, price: itemPrice, quantity: parseInt(quantity) });
125
- speak(`${quantity} x ${itemName} added to your cart.`);
126
- showCartDetails();
127
- }
128
- }
129
-
130
- // Function to display cart details
131
- function showCartDetails() {
132
- if (cart.length > 0) {
133
- let cartHtml = "";
134
- cart.forEach(item => {
135
- cartHtml += `<p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>`;
136
- });
137
- cartDetails.innerHTML = cartHtml;
138
- cartSummary.style.display = "block";
139
- } else {
140
- speak("Your cart is empty.");
141
- }
142
- }
143
-
144
- // Function to place the final order
145
- function placeOrder() {
146
- fetch("/place_order", {
147
- method: "POST",
148
- headers: { "Content-Type": "application/json" },
149
- body: JSON.stringify({ cart: cart })
150
- })
151
- .then(response => response.json())
152
- .then(data => {
153
- if (data.message === "Order placed successfully!") {
154
- speak("Your order has been placed successfully.");
155
- cart = []; // Clear cart after order
156
- cartSummary.style.display = "none"; // Hide cart summary
157
- } else {
158
- speak("An error occurred while placing the order. Please try again.");
159
- }
160
- })
161
- .catch(error => {
162
- speak("An error occurred while placing the order. Please try again.");
163
- });
164
- }
165
-
166
- // Event listener for listening button
167
  listenButton.addEventListener("click", () => {
168
  speak("Please say the item you want to order.");
169
  recognition.start();
@@ -172,10 +104,10 @@
172
  recognition.onresult = (event) => {
173
  const command = event.results[0][0].transcript.toLowerCase();
174
  console.log("User said:", command);
 
175
  if (command.includes("order")) {
176
- speak("Which item would you like to order?");
177
- } else {
178
- speak("Sorry, I couldn't understand that. Please try again.");
179
  }
180
  };
181
 
@@ -184,94 +116,28 @@
184
  speak("Sorry, I couldn't understand that. Please try again.");
185
  };
186
 
187
- // Load menu on page load
188
- window.onload = function() {
189
- fetchMenu();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
191
  </script>
192
 
193
  </body>
194
  </html>
195
-
196
- <!DOCTYPE html>
197
- <html lang="en">
198
- <head>
199
- <meta charset="UTF-8">
200
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
201
- <title>Your Cart</title>
202
- <style>
203
- body {
204
- font-family: Arial, sans-serif;
205
- background-color: #f4f4f4;
206
- margin: 0;
207
- padding: 0;
208
- }
209
- .container {
210
- width: 80%;
211
- margin: 50px auto;
212
- }
213
- h1 {
214
- text-align: center;
215
- color: #333;
216
- }
217
- .cart-item {
218
- background-color: #fff;
219
- padding: 20px;
220
- margin: 10px 0;
221
- box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
222
- border-radius: 8px;
223
- }
224
- .item-name {
225
- font-size: 1.5em;
226
- color: #4CAF50;
227
- }
228
- .item-quantity {
229
- font-size: 1.2em;
230
- color: #555;
231
- }
232
- .item-price {
233
- font-size: 1.2em;
234
- font-weight: bold;
235
- color: #000;
236
- }
237
- .btn-proceed {
238
- padding: 12px 20px;
239
- background-color: #4CAF50;
240
- color: white;
241
- border: none;
242
- border-radius: 4px;
243
- cursor: pointer;
244
- text-decoration: none;
245
- display: block;
246
- margin-top: 20px;
247
- text-align: center;
248
- }
249
- .btn-proceed:hover {
250
- background-color: #45a049;
251
- }
252
- </style>
253
- </head>
254
- <body>
255
-
256
- <div class="container">
257
- <h1>Your Cart</h1>
258
-
259
- {% if cart_items %}
260
- <div id="cart-items">
261
- {% for item in cart_items %}
262
- <div class="cart-item">
263
- <div class="item-name">{{ item.name }}</div>
264
- <div class="item-quantity">Quantity: {{ item.quantity }}</div>
265
- <div class="item-price">$ {{ item.price }}</div>
266
- </div>
267
- {% endfor %}
268
- </div>
269
-
270
- <a href="/order-summary" class="btn-proceed">Proceed to Order Summary</a>
271
- {% else %}
272
- <p>Your cart is empty. Please add items to your cart.</p>
273
- {% endif %}
274
- </div>
275
-
276
- </body>
277
- </html>
 
68
  <!-- Dynamic Menu Item List -->
69
  <div id="menu-items">
70
  <!-- Menu items will be populated here from the backend -->
71
+ {% for item in menu_items %}
72
+ <div class="menu-item">
73
+ <div class="details">
74
+ <h3>{{ item.name }}</h3>
75
+ <p><strong>Ingredients:</strong> {{ item.ingredients }}</p>
76
+ <p><strong>Category:</strong> {{ item.category }}</p>
77
+ <p class="price">Price: ₹{{ item.price }}</p>
78
+ </div>
79
+ <button class="order-btn" onclick="addToCart('{{ item.name }}', {{ item.price }})">Add to Cart</button>
80
+ </div>
81
+ {% endfor %}
82
  </div>
83
 
84
  <button id="listen-btn">Say "Order" to order an item</button>
 
 
 
 
 
85
  </div>
86
 
87
  <script>
88
  const listenButton = document.getElementById("listen-btn");
 
 
 
89
  const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
90
  recognition.lang = "en-US";
91
  recognition.interimResults = false;
 
96
  window.speechSynthesis.speak(msg);
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  listenButton.addEventListener("click", () => {
100
  speak("Please say the item you want to order.");
101
  recognition.start();
 
104
  recognition.onresult = (event) => {
105
  const command = event.results[0][0].transcript.toLowerCase();
106
  console.log("User said:", command);
107
+ // Add logic to recognize specific items or trigger actions based on the command
108
  if (command.includes("order")) {
109
+ // For example, navigate or process an order (customize as needed)
110
+ speak("Your order has been placed.");
 
111
  }
112
  };
113
 
 
116
  speak("Sorry, I couldn't understand that. Please try again.");
117
  };
118
 
119
+ function addToCart(itemName, itemPrice) {
120
+ const quantity = prompt(`How many of ${itemName} would you like to add?`);
121
+ if (quantity && !isNaN(quantity) && quantity > 0) {
122
+ // Send the data to the server to add to the cart
123
+ fetch("/add_to_cart", {
124
+ method: "POST",
125
+ headers: {
126
+ "Content-Type": "application/json",
127
+ },
128
+ body: JSON.stringify({
129
+ item_name: itemName,
130
+ quantity: parseInt(quantity),
131
+ }),
132
+ }).then((response) => response.json())
133
+ .then((data) => {
134
+ speak(data.message);
135
+ });
136
+ } else {
137
+ speak("Invalid quantity.");
138
+ }
139
  }
140
  </script>
141
 
142
  </body>
143
  </html>