Spaces:
Sleeping
Sleeping
Update templates/menu_page.html
Browse files- templates/menu_page.html +69 -99
templates/menu_page.html
CHANGED
@@ -23,7 +23,7 @@
|
|
23 |
h1 {
|
24 |
text-align: center;
|
25 |
font-size: 2.5rem;
|
26 |
-
color: #
|
27 |
margin-bottom: 30px;
|
28 |
}
|
29 |
.menu-item {
|
@@ -44,19 +44,8 @@
|
|
44 |
.order-btn:hover {
|
45 |
background-color: #45a049;
|
46 |
}
|
47 |
-
#
|
48 |
-
|
49 |
-
background-color: #4CAF50;
|
50 |
-
color: white;
|
51 |
-
border: none;
|
52 |
-
border-radius: 5px;
|
53 |
-
cursor: pointer;
|
54 |
-
font-size: 1.2rem;
|
55 |
-
display: block;
|
56 |
-
margin: 30px auto;
|
57 |
-
}
|
58 |
-
#listen-btn:hover {
|
59 |
-
background-color: #45a049;
|
60 |
}
|
61 |
</style>
|
62 |
</head>
|
@@ -75,7 +64,6 @@
|
|
75 |
<!-- Dynamic Menu Item List -->
|
76 |
<div id="menu-items"></div>
|
77 |
|
78 |
-
<button id="listen-btn">Say "Order" to order an item</button>
|
79 |
<div id="cart-summary" style="display:none;">
|
80 |
<h2>Your Cart:</h2>
|
81 |
<div id="cart-details"></div>
|
@@ -84,12 +72,9 @@
|
|
84 |
</div>
|
85 |
|
86 |
<script>
|
87 |
-
const listenButton = document.getElementById("listen-btn");
|
88 |
-
const placeOrderButton = document.getElementById("place-order-btn");
|
89 |
const cartSummary = document.getElementById("cart-summary");
|
90 |
const cartDetails = document.getElementById("cart-details");
|
91 |
const categoryButtons = document.getElementById("category-buttons");
|
92 |
-
let isListening = false;
|
93 |
let cart = []; // Global cart variable to store items
|
94 |
let menuData = {}; // Will store menu items based on categories
|
95 |
|
@@ -103,30 +88,44 @@
|
|
103 |
window.speechSynthesis.speak(msg);
|
104 |
}
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
} else if (command.includes("cart details")) {
|
121 |
-
showCartDetails();
|
122 |
-
} else {
|
123 |
-
speak("Sorry, I couldn't understand that. Please try again.");
|
124 |
-
}
|
125 |
-
};
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
};
|
131 |
|
132 |
// Function to populate the menu based on selected category
|
@@ -143,17 +142,41 @@
|
|
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 |
-
|
156 |
-
|
157 |
}
|
158 |
|
159 |
// Function to show cart details
|
@@ -171,32 +194,6 @@
|
|
171 |
}
|
172 |
}
|
173 |
|
174 |
-
// Function to handle the order process
|
175 |
-
function processOrder() {
|
176 |
-
speak("Which item would you like to order?");
|
177 |
-
recognition.start();
|
178 |
-
recognition.onresult = (event) => {
|
179 |
-
const itemName = event.results[0][0].transcript.toLowerCase();
|
180 |
-
const item = findItem(itemName);
|
181 |
-
if (item) {
|
182 |
-
speak(`You selected ${item.name}. How many would you like?`);
|
183 |
-
recognition.start();
|
184 |
-
recognition.onresult = (event) => {
|
185 |
-
const quantity = parseInt(event.results[0][0].transcript);
|
186 |
-
if (quantity) {
|
187 |
-
addToCart(item.name, quantity);
|
188 |
-
speak(`${quantity} ${item.name} added to your cart.`);
|
189 |
-
askMoreItems();
|
190 |
-
} else {
|
191 |
-
speak("Please say a valid quantity.");
|
192 |
-
}
|
193 |
-
};
|
194 |
-
} else {
|
195 |
-
speak("Sorry, I couldn't find that item. Please try again.");
|
196 |
-
}
|
197 |
-
};
|
198 |
-
}
|
199 |
-
|
200 |
// Function to ask if the user wants to order more items
|
201 |
function askMoreItems() {
|
202 |
speak("Would you like to order more items?");
|
@@ -204,7 +201,7 @@
|
|
204 |
recognition.onresult = (event) => {
|
205 |
const response = event.results[0][0].transcript.toLowerCase();
|
206 |
if (response.includes("yes")) {
|
207 |
-
|
208 |
} else {
|
209 |
showCartDetails();
|
210 |
}
|
@@ -213,36 +210,9 @@
|
|
213 |
|
214 |
// Function to find item in the menu
|
215 |
function findItem(itemName) {
|
216 |
-
const menu = menuData['
|
217 |
return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
|
218 |
}
|
219 |
-
|
220 |
-
// Function to populate the menu categories and items
|
221 |
-
window.onload = function() {
|
222 |
-
// Sample menu data for Main Course and Appetizers
|
223 |
-
menuData = {
|
224 |
-
'Main Course': [
|
225 |
-
{ name: "Chicken Biryani", price: 250 },
|
226 |
-
{ name: "Veg Biryani", price: 200 },
|
227 |
-
{ name: "Mutton Biryani", price: 300 }
|
228 |
-
],
|
229 |
-
'Appetizers': [
|
230 |
-
{ name: "Paneer Tikka", price: 180 },
|
231 |
-
{ name: "Chicken Wings", price: 220 }
|
232 |
-
]
|
233 |
-
};
|
234 |
-
|
235 |
-
// Populate categories dynamically
|
236 |
-
document.getElementById("main-course-btn").addEventListener("click", () => {
|
237 |
-
displayMenuItems('Main Course');
|
238 |
-
});
|
239 |
-
document.getElementById("appetizer-btn").addEventListener("click", () => {
|
240 |
-
displayMenuItems('Appetizers');
|
241 |
-
});
|
242 |
-
|
243 |
-
// Voice greeting for menu categories
|
244 |
-
speak("Welcome to Biryani Hub! We have the following categories: Main Course and Appetizers.");
|
245 |
-
};
|
246 |
</script>
|
247 |
|
248 |
</body>
|
|
|
23 |
h1 {
|
24 |
text-align: center;
|
25 |
font-size: 2.5rem;
|
26 |
+
color: #333;
|
27 |
margin-bottom: 30px;
|
28 |
}
|
29 |
.menu-item {
|
|
|
44 |
.order-btn:hover {
|
45 |
background-color: #45a049;
|
46 |
}
|
47 |
+
#cart-summary {
|
48 |
+
display: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
</style>
|
51 |
</head>
|
|
|
64 |
<!-- Dynamic Menu Item List -->
|
65 |
<div id="menu-items"></div>
|
66 |
|
|
|
67 |
<div id="cart-summary" style="display:none;">
|
68 |
<h2>Your Cart:</h2>
|
69 |
<div id="cart-details"></div>
|
|
|
72 |
</div>
|
73 |
|
74 |
<script>
|
|
|
|
|
75 |
const cartSummary = document.getElementById("cart-summary");
|
76 |
const cartDetails = document.getElementById("cart-details");
|
77 |
const categoryButtons = document.getElementById("category-buttons");
|
|
|
78 |
let cart = []; // Global cart variable to store items
|
79 |
let menuData = {}; // Will store menu items based on categories
|
80 |
|
|
|
88 |
window.speechSynthesis.speak(msg);
|
89 |
}
|
90 |
|
91 |
+
// Start voice recognition automatically on page load
|
92 |
+
window.onload = function() {
|
93 |
+
// Sample menu data for Main Course and Appetizers
|
94 |
+
menuData = {
|
95 |
+
'Main Course': [
|
96 |
+
{ name: "Chicken Biryani", price: 250 },
|
97 |
+
{ name: "Veg Biryani", price: 200 },
|
98 |
+
{ name: "Mutton Biryani", price: 300 }
|
99 |
+
],
|
100 |
+
'Appetizers': [
|
101 |
+
{ name: "Paneer Tikka", price: 180 },
|
102 |
+
{ name: "Chicken Wings", price: 220 }
|
103 |
+
]
|
104 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
// Populate categories dynamically
|
107 |
+
document.getElementById("main-course-btn").addEventListener("click", () => {
|
108 |
+
displayMenuItems('Main Course');
|
109 |
+
});
|
110 |
+
document.getElementById("appetizer-btn").addEventListener("click", () => {
|
111 |
+
displayMenuItems('Appetizers');
|
112 |
+
});
|
113 |
+
|
114 |
+
// Voice greeting for menu categories
|
115 |
+
speak("Welcome to Biryani Hub! We have the following categories: Main Course and Appetizers. Please say 'Main Course' or 'Appetizers' to select a category.");
|
116 |
+
|
117 |
+
// Automatically trigger voice recognition for category selection
|
118 |
+
recognition.start();
|
119 |
+
recognition.onresult = (event) => {
|
120 |
+
const categoryCommand = event.results[0][0].transcript.toLowerCase();
|
121 |
+
if (categoryCommand.includes("main course")) {
|
122 |
+
displayMenuItems('Main Course');
|
123 |
+
} else if (categoryCommand.includes("appetizers")) {
|
124 |
+
displayMenuItems('Appetizers');
|
125 |
+
} else {
|
126 |
+
speak("Sorry, I couldn't understand that. Please say 'Main Course' or 'Appetizers'.");
|
127 |
+
}
|
128 |
+
};
|
129 |
};
|
130 |
|
131 |
// Function to populate the menu based on selected category
|
|
|
142 |
<h3>${item.name}</h3>
|
143 |
<p class="price">Price: ₹${item.price}</p>
|
144 |
</div>
|
145 |
+
<button class="order-btn" onclick="addToCart('${item.name}', 1)">Order</button>
|
146 |
`;
|
147 |
menuContainer.appendChild(itemElement);
|
148 |
});
|
149 |
+
|
150 |
+
// Automatically prompt the user to order
|
151 |
+
speak("Here are the items in the selected category. Please say the item you want to order.");
|
152 |
+
recognition.start();
|
153 |
+
recognition.onresult = (event) => {
|
154 |
+
const itemName = event.results[0][0].transcript.toLowerCase();
|
155 |
+
const item = findItem(itemName);
|
156 |
+
if (item) {
|
157 |
+
speak(`You selected ${item.name}. How many would you like?`);
|
158 |
+
recognition.start();
|
159 |
+
recognition.onresult = (event) => {
|
160 |
+
const quantity = parseInt(event.results[0][0].transcript);
|
161 |
+
if (quantity) {
|
162 |
+
addToCart(item.name, quantity);
|
163 |
+
speak(`${quantity} ${item.name} added to your cart.`);
|
164 |
+
askMoreItems();
|
165 |
+
} else {
|
166 |
+
speak("Please say a valid quantity.");
|
167 |
+
}
|
168 |
+
};
|
169 |
+
} else {
|
170 |
+
speak("Sorry, I couldn't find that item. Please try again.");
|
171 |
+
}
|
172 |
+
};
|
173 |
}
|
174 |
}
|
175 |
|
176 |
// Function to add an item to the cart
|
177 |
function addToCart(itemName, quantity) {
|
178 |
+
const item = findItem(itemName);
|
179 |
+
cart.push({ name: item.name, price: item.price, quantity: quantity });
|
180 |
}
|
181 |
|
182 |
// Function to show cart details
|
|
|
194 |
}
|
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?");
|
|
|
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 |
}
|
|
|
210 |
|
211 |
// Function to find item in the menu
|
212 |
function findItem(itemName) {
|
213 |
+
const menu = menuData['Main Course']; // Default category to check first
|
214 |
return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
|
215 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
</script>
|
217 |
|
218 |
</body>
|