lokesh341 commited on
Commit
5e824a1
·
verified ·
1 Parent(s): a728ee2

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +149 -156
templates/menu_page.html CHANGED
@@ -62,162 +62,155 @@
62
  display: none;
63
  }
64
  </style>
65
- </head>
66
- <body>
67
 
68
- <!-- Page 1: Welcome and Category Selection -->
69
- <div id="page1" class="menu-container">
70
- <h1>Welcome to Biryani Hub menu</h1>
71
- <h3 id="category-title">Please select a category:</h3>
72
- <button id="main-course-btn">Main Course</button>
73
- <button id="appetizer-btn">Appetizers</button>
74
- </div>
75
-
76
- <!-- Page 2: Main Course Menu -->
77
- <div id="main-course-page" class="menu-container" style="display: none;">
78
- <h1>Main Course Menu</h1>
79
- <div id="main-course-items"></div>
80
- <button id="back-to-category-btn">Back to Category Selection</button>
81
- </div>
82
-
83
- <!-- Page 3: Appetizers Menu -->
84
- <div id="appetizer-page" class="menu-container" style="display: none;">
85
- <h1>Appetizers Menu</h1>
86
- <div id="appetizer-items"></div>
87
- <button id="back-to-category-btn2">Back to Category Selection</button>
88
- </div>
89
-
90
- <script>
91
- // Sample menu data
92
- const menuData = {
93
- 'Main Course': [
94
- { name: "Chicken Biryani", price: 250 },
95
- { name: "Veg Biryani", price: 200 },
96
- { name: "Mutton Biryani", price: 300 }
97
- ],
98
- 'Appetizers': [
99
- { name: "Paneer Tikka", price: 180 },
100
- { name: "Chicken Wings", price: 220 }
101
- ]
102
- };
103
-
104
- // Selectors for pages and buttons
105
- const categoryButtons = document.getElementById('page1');
106
- const mainCoursePage = document.getElementById('main-course-page');
107
- const appetizerPage = document.getElementById('appetizer-page');
108
- const backToCategoryBtns = document.querySelectorAll('[id^="back-to-category-btn"]');
109
- let cart = []; // Global cart variable to store items
110
- let menuData = {}; // Will store menu items based on categories
111
-
112
- // Event listeners for buttons to navigate between pages
113
- document.getElementById("main-course-btn").addEventListener("click", () => {
114
- categoryButtons.style.display = "none";
115
- mainCoursePage.style.display = "block";
116
- displayMenuItems('Main Course');
117
- });
118
-
119
- document.getElementById("appetizer-btn").addEventListener("click", () => {
120
- categoryButtons.style.display = "none";
121
- appetizerPage.style.display = "block";
122
- displayMenuItems('Appetizers');
123
- });
124
-
125
- backToCategoryBtns.forEach(button => {
126
- button.addEventListener("click", () => {
127
- mainCoursePage.style.display = "none";
128
- appetizerPage.style.display = "none";
129
- categoryButtons.style.display = "block";
130
- });
131
- });
132
-
133
- // Function to populate the menu based on selected category
134
- function displayMenuItems(category) {
135
- const menuContainer = category === 'Main Course' ? document.getElementById('main-course-items') : document.getElementById('appetizer-items');
136
- menuContainer.innerHTML = '';
137
- if (menuData[category]) {
138
- menuData[category].forEach(item => {
139
- const itemElement = document.createElement('div');
140
- itemElement.classList.add('menu-item');
141
- itemElement.innerHTML = `
142
- <div class="details">
143
- <h3>${item.name}</h3>
144
- <p class="price">Price: ₹${item.price}</p>
145
- </div>
146
- <button class="order-btn" onclick="addToCart('${item.name}', 1)">Order</button>
147
- `;
148
- menuContainer.appendChild(itemElement);
149
- });
150
- }
151
- }
152
-
153
- // Function to add an item to the cart
154
- function addToCart(itemName, quantity) {
155
- const item = findItem(itemName);
156
- cart.push({ name: item.name, price: item.price, quantity: quantity });
157
- displayCartSummary();
158
- }
159
-
160
- // Function to show cart details
161
- function displayCartSummary() {
162
- let cartHtml = "";
163
- cart.forEach(item => {
164
- cartHtml += `<p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>`;
165
- });
166
- const cartSummary = document.getElementById("cart-summary");
167
- cartSummary.innerHTML = cartHtml;
168
- cartSummary.style.display = "block";
169
- }
170
-
171
- // Function to find item in the menu
172
- function findItem(itemName) {
173
- const menu = menuData['Main Course']; // Default category to check first
174
- return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
175
- }
176
-
177
- // Voice greeting for menu categories
178
- const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
179
- recognition.lang = "en-US";
180
- recognition.interimResults = false;
181
- function speak(text) {
182
- const msg = new SpeechSynthesisUtterance(text);
183
- window.speechSynthesis.speak(msg);
184
- }
185
-
186
- window.onload = function() {
187
- // Sample menu data for Main Course and Appetizers
188
- menuData = {
189
- 'Main Course': [
190
- { name: "Chicken Biryani", price: 250 },
191
- { name: "Veg Biryani", price: 200 },
192
- { name: "Mutton Biryani", price: 300 }
193
- ],
194
- 'Appetizers': [
195
- { name: "Paneer Tikka", price: 180 },
196
- { name: "Chicken Wings", price: 220 }
197
- ]
198
- };
199
-
200
- // Automatically greet the user and prompt for category selection
201
- speak("Welcome to Biryani Hub! We have the following categories: Main Course and Appetizers. Please say 'Main Course' or 'Appetizers' to select a category.");
202
-
203
- // Automatically trigger voice recognition for category selection
204
- recognition.start();
205
- recognition.onresult = (event) => {
206
- const categoryCommand = event.results[0][0].transcript.toLowerCase();
207
- if (categoryCommand.includes("main course")) {
208
- displayMenuItems('Main Course');
209
- mainCoursePage.style.display = "block";
210
- categoryButtons.style.display = "none";
211
- } else if (categoryCommand.includes("appetizers")) {
212
- displayMenuItems('Appetizers');
213
- appetizerPage.style.display = "block";
214
- categoryButtons.style.display = "none";
215
- } else {
216
- speak("Sorry, I couldn't understand that. Please say 'Main Course' or 'Appetizers'.");
217
  }
218
- };
219
- };
220
- </script>
221
 
222
- </body>
223
- </html>
 
62
  display: none;
63
  }
64
  </style>
 
 
65
 
66
+ <div class="menu-container">
67
+ <h1>Welcome to Biryani Hub menu</h1>
68
+ <h3 id="category-title">Please select a category:</h3>
69
+
70
+ <!-- Buttons for selecting categories -->
71
+ <div id="category-buttons">
72
+ <button id="main-course-btn">Main Course</button>
73
+ <button id="appetizer-btn">Appetizers</button>
74
+ </div>
75
+
76
+ <!-- Dynamic Menu Item List -->
77
+ <div id="menu-items"></div>
78
+
79
+ <div id="cart-summary" style="display:none;">
80
+ <h2>Your Cart:</h2>
81
+ <div id="cart-details"></div>
82
+ <button id="place-order-btn">Place Final Order</button>
83
+ </div>
84
+ </div>
85
+
86
+ <script>
87
+ const cartSummary = document.getElementById("cart-summary");
88
+ const cartDetails = document.getElementById("cart-details");
89
+ const categoryButtons = document.getElementById("category-buttons");
90
+ let cart = []; // Global cart variable to store items
91
+ let menuData = {}; // Will store menu items based on categories
92
+ const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
93
+ recognition.lang = "en-US";
94
+ recognition.interimResults = false;
95
+ // Function to speak text
96
+ function speak(text) {
97
+ const msg = new SpeechSynthesisUtterance(text);
98
+ window.speechSynthesis.speak(msg);
99
+ }
100
+ // Start voice recognition automatically on page load
101
+ window.onload = function() {
102
+ // Sample menu data for Main Course and Appetizers
103
+ menuData = {
104
+ 'Main Course': [
105
+ { name: "Chicken Biryani", price: 250 },
106
+ { name: "Veg Biryani", price: 200 },
107
+ { name: "Mutton Biryani", price: 300 }
108
+ ],
109
+ 'Appetizers': [
110
+ { name: "Paneer Tikka", price: 180 },
111
+ { name: "Chicken Wings", price: 220 }
112
+ ]
113
+ };
114
+ // Populate categories dynamically
115
+ document.getElementById("main-course-btn").addEventListener("click", () => {
116
+ displayMenuItems('Main Course');
117
+ });
118
+ document.getElementById("appetizer-btn").addEventListener("click", () => {
119
+ displayMenuItems('Appetizers');
120
+ });
121
+ // Voice greeting for menu categories
122
+ speak("Welcome to Biryani Hub! We have the following categories: Main Course and Appetizers. Please say 'Main Course' or 'Appetizers' to select a category.");
123
+ // Automatically trigger voice recognition for category selection
124
+ recognition.start();
125
+ recognition.onresult = (event) => {
126
+ const categoryCommand = event.results[0][0].transcript.toLowerCase();
127
+ if (categoryCommand.includes("main course")) {
128
+ displayMenuItems('Main Course');
129
+ } else if (categoryCommand.includes("appetizers")) {
130
+ displayMenuItems('Appetizers');
131
+ } else {
132
+ speak("Sorry, I couldn't understand that. Please say 'Main Course' or 'Appetizers'.");
133
+ }
134
+ };
135
+ };
136
+ // Function to populate the menu based on selected category
137
+ function displayMenuItems(category) {
138
+ const menuContainer = document.getElementById('menu-items');
139
+ menuContainer.innerHTML = ''; // Clear previous menu
140
+ if (menuData[category]) {
141
+ menuData[category].forEach(item => {
142
+ const itemElement = document.createElement('div');
143
+ itemElement.classList.add('menu-item');
144
+ itemElement.innerHTML =
145
+ <div class="details">
146
+ <h3>${item.name}</h3>
147
+ <p class="price">Price: ₹${item.price}</p>
148
+ </div>
149
+ <button class="order-btn" onclick="addToCart('${item.name}', 1)">Order</button>
150
+ ;
151
+ menuContainer.appendChild(itemElement);
152
+ });
153
+ // Automatically prompt the user to order
154
+ speak("Here are the items in the selected category. Please say the item you want to order.");
155
+ recognition.start();
156
+ recognition.onresult = (event) => {
157
+ const itemName = event.results[0][0].transcript.toLowerCase();
158
+ const item = findItem(itemName);
159
+ if (item) {
160
+ speak(You selected ${item.name}. How many would you like?);
161
+ recognition.start();
162
+ recognition.onresult = (event) => {
163
+ const quantity = parseInt(event.results[0][0].transcript);
164
+ if (quantity) {
165
+ addToCart(item.name, quantity);
166
+ speak(${quantity} ${item.name} added to your cart.);
167
+ askMoreItems();
168
+ } else {
169
+ speak("Please say a valid quantity.");
170
+ }
171
+ };
172
+ } else {
173
+ speak("Sorry, I couldn't find that item. Please try again.");
174
+ }
175
+ };
176
+ }
177
+ }
178
+ // Function to add an item to the cart
179
+ function addToCart(itemName, quantity) {
180
+ const item = findItem(itemName);
181
+ cart.push({ name: item.name, price: item.price, quantity: quantity });
182
+ }
183
+ // Function to show cart details
184
+ function showCartDetails() {
185
+ if (cart.length > 0) {
186
+ let cartHtml = "";
187
+ cart.forEach(item => {
188
+ cartHtml += <p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>;
189
+ });
190
+ cartDetails.innerHTML = cartHtml;
191
+ cartSummary.style.display = "block";
192
+ speak(Your cart contains ${cart.length} items.);
193
+ } else {
194
+ speak("Your cart is empty.");
195
+ }
196
+ }
197
+ // Function to ask if the user wants to order more items
198
+ function askMoreItems() {
199
+ speak("Would you like to order more items?");
200
+ recognition.start();
201
+ recognition.onresult = (event) => {
202
+ const response = event.results[0][0].transcript.toLowerCase();
203
+ if (response.includes("yes")) {
204
+ recognition.start();
205
+ } else {
206
+ showCartDetails();
207
+ }
208
+ };
209
+ }
210
+ // Function to find item in the menu
211
+ function findItem(itemName) {
212
+ const menu = menuData['Main Course']; // Default category to check first
213
+ return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
 
214
  }
215
+ </script>
 
 
216