Spaces:
Running
Running
Update templates/menu_page.html
Browse files- templates/menu_page.html +80 -57
templates/menu_page.html
CHANGED
@@ -63,13 +63,18 @@
|
|
63 |
<body>
|
64 |
|
65 |
<div class="menu-container">
|
66 |
-
<h1>Welcome to
|
|
|
67 |
|
68 |
-
<!--
|
69 |
-
<div id="
|
70 |
-
|
|
|
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>
|
@@ -83,8 +88,11 @@
|
|
83 |
const placeOrderButton = document.getElementById("place-order-btn");
|
84 |
const cartSummary = document.getElementById("cart-summary");
|
85 |
const cartDetails = document.getElementById("cart-details");
|
|
|
86 |
let isListening = false;
|
87 |
let cart = []; // Global cart variable to store items
|
|
|
|
|
88 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
89 |
recognition.lang = "en-US";
|
90 |
recognition.interimResults = false;
|
@@ -108,7 +116,6 @@
|
|
108 |
console.log("User said:", command);
|
109 |
// Add logic to recognize specific items or trigger actions based on the command
|
110 |
if (command.includes("order")) {
|
111 |
-
// Process ordering logic here (e.g., find item in menu and add to cart)
|
112 |
processOrder();
|
113 |
} else if (command.includes("cart details")) {
|
114 |
showCartDetails();
|
@@ -122,7 +129,49 @@
|
|
122 |
speak("Sorry, I couldn't understand that. Please try again.");
|
123 |
};
|
124 |
|
125 |
-
// Function to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
function processOrder() {
|
127 |
speak("Which item would you like to order?");
|
128 |
recognition.start();
|
@@ -135,7 +184,7 @@
|
|
135 |
recognition.onresult = (event) => {
|
136 |
const quantity = parseInt(event.results[0][0].transcript);
|
137 |
if (quantity) {
|
138 |
-
addToCart(item, quantity);
|
139 |
speak(`${quantity} ${item.name} added to your cart.`);
|
140 |
askMoreItems();
|
141 |
} else {
|
@@ -162,64 +211,38 @@
|
|
162 |
};
|
163 |
}
|
164 |
|
165 |
-
// Function to show cart details
|
166 |
-
function showCartDetails() {
|
167 |
-
if (cart.length > 0) {
|
168 |
-
let cartHtml = "";
|
169 |
-
cart.forEach(item => {
|
170 |
-
cartHtml += `<p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>`;
|
171 |
-
});
|
172 |
-
cartDetails.innerHTML = cartHtml;
|
173 |
-
cartSummary.style.display = "block";
|
174 |
-
speak(`Your cart contains ${cart.length} items.`);
|
175 |
-
} else {
|
176 |
-
speak("Your cart is empty.");
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
// Function to add an item to the cart
|
181 |
-
function addToCart(item, quantity) {
|
182 |
-
cart.push({ name: item.name, price: item.price, quantity: quantity });
|
183 |
-
}
|
184 |
-
|
185 |
// Function to find item in the menu
|
186 |
function findItem(itemName) {
|
187 |
-
const menu = [
|
188 |
-
{ name: "Chicken Biryani", price: 250 },
|
189 |
-
{ name: "Veg Biryani", price: 200 },
|
190 |
-
{ name: "Mutton Biryani", price: 300 }
|
191 |
-
];
|
192 |
return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
|
193 |
}
|
194 |
|
195 |
-
// Function to populate the menu
|
196 |
window.onload = function() {
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
</div>
|
210 |
-
<button class="order-btn" onclick="addToCart(${item.name}, 1)">Order</button>
|
211 |
-
</div>
|
212 |
-
`;
|
213 |
-
});
|
214 |
-
document.getElementById('menu-items').innerHTML = menuContent;
|
215 |
|
216 |
-
//
|
217 |
-
|
218 |
-
|
219 |
-
itemsText += item.name + ", ";
|
220 |
});
|
221 |
-
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
223 |
</script>
|
224 |
|
225 |
</body>
|
|
|
63 |
<body>
|
64 |
|
65 |
<div class="menu-container">
|
66 |
+
<h1>Welcome to Biryani Hub</h1>
|
67 |
+
<h3 id="category-title">Please select a category:</h3>
|
68 |
|
69 |
+
<!-- Buttons for selecting categories -->
|
70 |
+
<div id="category-buttons">
|
71 |
+
<button id="main-course-btn">Main Course</button>
|
72 |
+
<button id="appetizer-btn">Appetizers</button>
|
73 |
</div>
|
74 |
|
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>
|
|
|
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 |
+
|
96 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
97 |
recognition.lang = "en-US";
|
98 |
recognition.interimResults = false;
|
|
|
116 |
console.log("User said:", command);
|
117 |
// Add logic to recognize specific items or trigger actions based on the command
|
118 |
if (command.includes("order")) {
|
|
|
119 |
processOrder();
|
120 |
} else if (command.includes("cart details")) {
|
121 |
showCartDetails();
|
|
|
129 |
speak("Sorry, I couldn't understand that. Please try again.");
|
130 |
};
|
131 |
|
132 |
+
// Function to populate the menu based on selected category
|
133 |
+
function displayMenuItems(category) {
|
134 |
+
const menuContainer = document.getElementById('menu-items');
|
135 |
+
menuContainer.innerHTML = ''; // Clear previous menu
|
136 |
+
|
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 |
+
cart.push({ name: itemName, price: 250, quantity: quantity });
|
156 |
+
speak(`${itemName} added to your cart.`);
|
157 |
+
}
|
158 |
+
|
159 |
+
// Function to show cart details
|
160 |
+
function showCartDetails() {
|
161 |
+
if (cart.length > 0) {
|
162 |
+
let cartHtml = "";
|
163 |
+
cart.forEach(item => {
|
164 |
+
cartHtml += `<p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>`;
|
165 |
+
});
|
166 |
+
cartDetails.innerHTML = cartHtml;
|
167 |
+
cartSummary.style.display = "block";
|
168 |
+
speak(`Your cart contains ${cart.length} items.`);
|
169 |
+
} else {
|
170 |
+
speak("Your cart is empty.");
|
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();
|
|
|
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 {
|
|
|
211 |
};
|
212 |
}
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
// Function to find item in the menu
|
215 |
function findItem(itemName) {
|
216 |
+
const menu = menuData['Biryanis']; // Default category to check first
|
|
|
|
|
|
|
|
|
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>
|