lokesh341 commited on
Commit
6928c0e
·
verified ·
1 Parent(s): c99469e

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +45 -35
templates/menu_page.html CHANGED
@@ -14,17 +14,24 @@
14
  .text { margin-left: 10px; }
15
  .menu-option { margin: 20px; font-size: 1.5rem; text-align: center; }
16
  .menu-option button { font-size: 1.2rem; padding: 10px 20px; margin: 10px; cursor: pointer; }
 
 
17
  </style>
18
  </head>
19
  <body>
20
  <div class="menu-container">
21
  <h1>Welcome to the Menu</h1>
22
  <div id="menu-items"></div>
 
 
 
 
 
 
23
  </div>
24
 
25
  <script>
26
  const menuItems = [
27
- // Vegetarian Items
28
  { name: 'Samosa', price: 9, ingredients: 'Potatoes, Peas, Flour, Spices', description: 'Crispy fried pastry filled with spiced potatoes and peas.', imageUrl: 'https://via.placeholder.com/100', category: 'veg' },
29
  { name: 'Onion Pakoda', price: 10, ingredients: 'Onions, Gram Flour, Spices', description: 'Deep-fried onion fritters seasoned with herbs and spices.', imageUrl: 'https://via.placeholder.com/100', category: 'veg' },
30
  { name: 'Chilli Gobi', price: 12, ingredients: 'Cauliflower, Chili Sauce, Spices', description: 'Cauliflower florets tossed in a spicy chili sauce.', imageUrl: 'https://via.placeholder.com/100', category: 'veg' },
@@ -59,57 +66,60 @@
59
  ];
60
 
61
  const menuContainer = document.getElementById('menu-items');
 
62
 
63
- // Function to automatically display either Veg or Non-Veg menu based on the category
64
- function showMenu(type) {
65
  menuContainer.innerHTML = ''; // Clear previous menu items
66
- const filteredItems = menuItems.filter(item => item.category === type);
67
 
68
- filteredItems.forEach(item => {
69
  const div = document.createElement('div');
70
  div.classList.add('menu-item');
71
- div.innerHTML = `<div class="details"><img src="${item.imageUrl}" alt="${item.name}"><div class="text"><h3>${item.name}</h3><p>${item.description}</p><p><strong>Ingredients:</strong> ${item.ingredients}</p><p><strong>Price:</strong> $${item.price}</p></div></div>`;
 
 
 
 
 
 
 
 
 
 
72
  menuContainer.appendChild(div);
73
  });
74
  }
75
 
76
- // Function to ask user whether they want Veg or Non-Veg items
77
- function askForMenuChoice() {
78
- const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
79
- recognition.lang = 'en-US';
80
- recognition.interimResults = false;
81
-
82
- recognition.onresult = (event) => {
83
- const command = event.results[0][0].transcript.toLowerCase();
84
- if (command.includes('veg')) {
85
- showMenu('veg');
86
- speak('Here are the Veg items.');
87
- } else if (command.includes('non-veg')) {
88
- showMenu('non-veg');
89
- speak('Here are the Non-Veg items.');
90
- } else {
91
- speak('Please say Veg or Non-Veg to choose the menu.');
92
- recognition.start();
93
- }
94
- };
95
-
96
- recognition.onerror = () => { speak('Sorry, I could not understand. Please try again.'); };
97
 
98
- speak('Would you like to see the Veg or Non-Veg menu?', () => {
99
- recognition.start();
 
 
 
 
 
 
 
 
100
  });
 
101
  }
102
 
103
- // Speech synthesis function
104
- function speak(text, callback) {
105
  const msg = new SpeechSynthesisUtterance(text);
106
- msg.onend = callback;
107
  window.speechSynthesis.speak(msg);
108
  }
109
 
110
- window.onload = askForMenuChoice; // Automatically ask for menu choice when page loads
111
  </script>
112
  </body>
113
  </html>
114
-
115
-
 
14
  .text { margin-left: 10px; }
15
  .menu-option { margin: 20px; font-size: 1.5rem; text-align: center; }
16
  .menu-option button { font-size: 1.2rem; padding: 10px 20px; margin: 10px; cursor: pointer; }
17
+ .cart-container { margin-top: 30px; padding: 10px; border: 1px solid #ddd; border-radius: 5px; background-color: #eaf3e1; }
18
+ .cart-item { display: flex; justify-content: space-between; margin-bottom: 10px; }
19
  </style>
20
  </head>
21
  <body>
22
  <div class="menu-container">
23
  <h1>Welcome to the Menu</h1>
24
  <div id="menu-items"></div>
25
+ <button onclick="viewCart()">View Cart</button>
26
+ </div>
27
+
28
+ <div class="cart-container" id="cart-container" style="display:none;">
29
+ <h2>Your Cart</h2>
30
+ <div id="cart-items"></div>
31
  </div>
32
 
33
  <script>
34
  const menuItems = [
 
35
  { name: 'Samosa', price: 9, ingredients: 'Potatoes, Peas, Flour, Spices', description: 'Crispy fried pastry filled with spiced potatoes and peas.', imageUrl: 'https://via.placeholder.com/100', category: 'veg' },
36
  { name: 'Onion Pakoda', price: 10, ingredients: 'Onions, Gram Flour, Spices', description: 'Deep-fried onion fritters seasoned with herbs and spices.', imageUrl: 'https://via.placeholder.com/100', category: 'veg' },
37
  { name: 'Chilli Gobi', price: 12, ingredients: 'Cauliflower, Chili Sauce, Spices', description: 'Cauliflower florets tossed in a spicy chili sauce.', imageUrl: 'https://via.placeholder.com/100', category: 'veg' },
 
66
  ];
67
 
68
  const menuContainer = document.getElementById('menu-items');
69
+ const cart = [];
70
 
71
+ // Function to automatically display the menu
72
+ function showMenu() {
73
  menuContainer.innerHTML = ''; // Clear previous menu items
 
74
 
75
+ menuItems.forEach(item => {
76
  const div = document.createElement('div');
77
  div.classList.add('menu-item');
78
+ div.innerHTML = `<div class="details">
79
+ <img src="${item.imageUrl}" alt="${item.name}">
80
+ <div class="text">
81
+ <h3>${item.name}</h3>
82
+ <p>${item.description}</p>
83
+ <p><strong>Ingredients:</strong> ${item.ingredients}</p>
84
+ <p><strong>Price:</strong> $${item.price}</p>
85
+ <p><strong>Quantity:</strong> <input type="number" id="quantity-${item.name}" value="1" min="1" /></p>
86
+ <button onclick="addToCart('${item.name}')">Add to Cart</button>
87
+ </div>
88
+ </div>`;
89
  menuContainer.appendChild(div);
90
  });
91
  }
92
 
93
+ // Function to add items to the cart
94
+ function addToCart(itemName) {
95
+ const quantity = document.getElementById(`quantity-${itemName}`).value;
96
+ const item = menuItems.find(item => item.name === itemName);
97
+ const cartItem = { ...item, quantity: parseInt(quantity) };
98
+ cart.push(cartItem);
99
+ speak(`Added ${quantity} of ${itemName} to the cart.`);
100
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
+ // Function to view the cart
103
+ function viewCart() {
104
+ const cartContainer = document.getElementById('cart-container');
105
+ const cartItemsContainer = document.getElementById('cart-items');
106
+ cartItemsContainer.innerHTML = '';
107
+ cart.forEach(cartItem => {
108
+ const div = document.createElement('div');
109
+ div.classList.add('cart-item');
110
+ div.innerHTML = `<span>${cartItem.name} (x${cartItem.quantity}) - $${cartItem.price * cartItem.quantity}</span>`;
111
+ cartItemsContainer.appendChild(div);
112
  });
113
+ cartContainer.style.display = 'block';
114
  }
115
 
116
+ // Function for speech synthesis
117
+ function speak(text) {
118
  const msg = new SpeechSynthesisUtterance(text);
 
119
  window.speechSynthesis.speak(msg);
120
  }
121
 
122
+ window.onload = showMenu;
123
  </script>
124
  </body>
125
  </html>