nagasurendra commited on
Commit
fac2d9a
·
verified ·
1 Parent(s): 8fd9cea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +285 -254
app.py CHANGED
@@ -77,214 +77,9 @@ def filter_menu(preference):
77
  </div>
78
  """
79
  return html_content
80
- # Preserving your JavaScript for modal and cart functionality (Your original JavaScript logic)
81
- modal_and_cart_js = """
82
- <style>
83
- .cart-container {
84
- width: 90%; /* Ensure it fits the screen */
85
- margin: auto;
86
- display: flex;
87
- flex-direction: column;
88
- gap: 10px; /* Add space between cart items */
89
- }
90
- .cart-item {
91
- display: flex;
92
- flex-wrap: wrap; /* Wrap content to the next line if needed */
93
- align-items: center; /* Vertically align items */
94
- justify-content: space-between; /* Distribute space between items */
95
- width: 100%; /* Ensure it takes full width */
96
- padding: 10px;
97
- border: 1px solid #ccc;
98
- border-radius: 5px;
99
- background-color: #f9f9f9;
100
- }
101
- .cart-item span {
102
- margin-right: 10px;
103
- flex: 1; /* Allow text to take available space */
104
- min-width: 50px; /* Prevent collapsing */
105
- }
106
- .cart-item .quantity-container {
107
- display: flex;
108
- align-items: center;
109
- gap: 5px;
110
- }
111
- .cart-item button {
112
- background-color: red;
113
- color: white;
114
- border: none;
115
- padding: 5px 10px;
116
- cursor: pointer;
117
- border-radius: 5px;
118
- flex-shrink: 0; /* Prevent the button from shrinking */
119
- }
120
- .cart-total {
121
- font-size: 1.2em;
122
- font-weight: bold;
123
- text-align: center;
124
- }
125
- button {
126
- margin-top: 10px;
127
- background-color: #007bff;
128
- color: white;
129
- border: none;
130
- padding: 10px;
131
- border-radius: 5px;
132
- width: 100%;
133
- cursor: pointer;
134
- }
135
- @media (max-width: 768px) {
136
- .cart-item {
137
- flex-direction: column; /* Stack items on mobile */
138
- align-items: flex-start; /* Align to the left */
139
- }
140
- .cart-item button {
141
- align-self: flex-end; /* Place the remove button at the end */
142
- margin-top: 5px; /* Add some space on top */
143
- }
144
- }
145
- </style>
146
- <script>
147
- let cart = [];
148
- const extrasPrices = {
149
- "Thums up": 2,
150
- "Sprite": 2,
151
- "Extra Raitha": 1,
152
- "Extra Salan": 2,
153
- "Extra Onion & Lemon": 2,
154
- "Chilli Chicken": 14,
155
- "Veg Manchurian": 12
156
- };
157
- let finalized = false;
158
- function openModal(name, image2, description, price) {
159
- if (finalized) {
160
- alert("You cannot add more items after finalizing your order.");
161
- return;
162
- }
163
- const modal = document.getElementById('modal');
164
- modal.style.display = 'block';
165
- modal.style.position = 'fixed';
166
- if (window.innerWidth <= 768) {
167
- modal.style.width = '90%';
168
- modal.style.top = `${event.touches ? event.touches[0].screenY : event.clientY}px`;
169
- } else {
170
- modal.style.width = '30%';
171
- modal.style.top = `${event.clientY}px`;// Use mouse Y position for laptop
172
- }
173
- modal.style.left = '50%';
174
- modal.style.transform = 'translate(-50%, -50%)';
175
- document.getElementById('modal-image').src = image2;
176
- document.getElementById('modal-name').innerText = name;
177
- document.getElementById('modal-description').innerText = description;
178
- document.getElementById('modal-price').innerText = price;
179
- const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
180
- extrasInputs.forEach(input => input.checked = false);
181
- document.getElementById('quantity').value = 1;
182
- document.getElementById('special-instructions').value = '';
183
- }
184
- function closeModal() {
185
- document.getElementById('modal').style.display = 'none';
186
- }
187
- function addToCart() {
188
- if (finalized) {
189
- alert("You cannot add more items after finalizing your order.");
190
- return;
191
- }
192
- const name = document.getElementById('modal-name').innerText;
193
- const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
194
- const quantity = parseInt(document.getElementById('quantity').value) || 1;
195
- const instructions = document.getElementById('special-instructions').value;
196
- const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
197
- const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);
198
- const itemTotal = (price + extrasCost) * quantity;
199
- const cartItem = { name, price, quantity, instructions, extras, itemTotal, extrasQuantities: extras.map(() => 1) };
200
- cart.push(cartItem);
201
- alert(`${name} added to cart!`);
202
- updateCartDisplay();
203
- closeModal();
204
- }
205
- function updateCartDisplay() {
206
- let totalBill = 0;
207
- let cartHTML = "<div class='cart-container'>";
208
- cart.forEach((item, index) => {
209
- totalBill += item.itemTotal;
210
- const extras = item.extras.map((extra, i) => {
211
- const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
212
- const extraTotal = extrasPrices[extra] * extraQuantity;
213
- totalBill += extraTotal;
214
- return `<div class='cart-item'>
215
- <span>${extra}</span>
216
- <span>Price: $${extrasPrices[extra].toFixed(2)}</span>
217
- <div class='quantity-container'>
218
- <label for='extra-quantity-${index}-${i}'>Quantity:</label>
219
- <input type='number' id='extra-quantity-${index}-${i}' value='${extraQuantity}' min='1' style='width: 50px;' onchange='updateExtraQuantity(${index}, ${i}, this.value)'>
220
- </div>
221
- <span>Total: $${extraTotal.toFixed(2)}</span>
222
- <button style='background-color: red; color: white; border: none; padding: 5px 10px; cursor: pointer;' onclick='removeExtra(${index}, ${i})'>Remove</button>
223
- </div>`;
224
- }).join('');
225
- cartHTML += `<div class='cart-item'>
226
- <span>${item.name}</span>
227
- <span>Item Price: $${item.price.toFixed(2)}</span>
228
- <div class='quantity-container'>
229
- <label for='item-quantity-${index}'>Quantity:</label>
230
- <input type='number' id='item-quantity-${index}' value='${item.quantity}' min='1' style='width: 50px;' onchange='updateItemQuantity(${index}, this.value)'>
231
- </div>
232
- <span>Total: $${(item.price * item.quantity).toFixed(2)}</span>
233
- <button style='background-color: red; color: white; border: none; padding: 5px 10px; cursor: pointer;' onclick='removeItem(${index})'>Remove</button>
234
- </div>
235
- ${extras}
236
- <div class='cart-item'><strong>Instructions:</strong> ${item.instructions || "None"}</div>`;
237
- });
238
- cartHTML += `</div><p class='cart-total'>Total Bill: $${totalBill.toFixed(2)}</p>`;
239
- cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
240
- document.getElementById('floating-cart').innerHTML = cartHTML;
241
- }
242
- function updateItemQuantity(index, newQuantity) {
243
- const quantity = parseInt(newQuantity) || 1;
244
- cart[index].quantity = quantity;
245
- cart[index].itemTotal = cart[index].price * quantity;
246
- updateCartDisplay();
247
- }
248
- function updateExtraQuantity(cartIndex, extraIndex, newQuantity) {
249
- const quantity = parseInt(newQuantity) || 1;
250
- cart[cartIndex].extrasQuantities = cart[cartIndex].extrasQuantities || [];
251
- cart[cartIndex].extrasQuantities[extraIndex] = quantity;
252
- updateCartDisplay();
253
- }
254
- function removeExtra(cartIndex, extraIndex) {
255
- cart[cartIndex].extras.splice(extraIndex, 1);
256
- if (cart[cartIndex].extrasQuantities) {
257
- cart[cartIndex].extrasQuantities.splice(extraIndex, 1);
258
- }
259
- updateCartDisplay();
260
- }
261
- function removeItem(index) {
262
- cart.splice(index, 1);
263
- updateCartDisplay();
264
- }
265
- function submitCart() {
266
- let finalOrderHTML = "<h3>Final Order:</h3><ul>";
267
- let totalBill = 0;
268
- cart.forEach(item => {
269
- totalBill += item.itemTotal;
270
- const extras = item.extras.map((extra, i) => {
271
- const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
272
- const extraTotal = extrasPrices[extra] * extraQuantity;
273
- totalBill += extraTotal;
274
- return `${extra} (x${extraQuantity}) - $${extraTotal.toFixed(2)}`;
275
- }).join(', ');
276
- finalOrderHTML += `<li>
277
- ${item.name} (x${item.quantity}) - $${item.itemTotal.toFixed(2)}
278
- <br>Extras: ${extras}
279
- <br>Instructions: ${item.instructions || "None"}
280
- </li>`;
281
- });
282
- finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
283
- document.getElementById('final-order').innerHTML = finalOrderHTML;
284
- alert("Your final order has been submitted!");
285
- }
286
- </script>
287
- """
288
  # Authentication and Navigation Logic
289
  def authenticate_user(email, password):
290
  if check_credentials(email, password):
@@ -306,12 +101,274 @@ def navigate_to_login():
306
 
307
  def app():
308
  with gr.Blocks() as demo:
309
- # Cart & Final Order Page (Always at the Top)
310
- with gr.Column(visible=False, elem_id="cart-section") as cart_section:
311
- gr.Markdown("### Cart & Final Order Page (Always at the Top)")
312
- cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
313
- final_order_output = gr.HTML(value="", elem_id="final-order")
314
- back_to_menu_button = gr.Button("Back to Menu")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
 
316
  # Login Page
317
  with gr.Column(visible=True) as login_section:
@@ -333,27 +390,20 @@ def app():
333
  signup_button = gr.Button("Sign Up")
334
  go_to_login = gr.Button("Back to Login")
335
 
336
- # Menu Page (Below the Cart Section)
337
- with gr.Column(visible=False, elem_id="menu-section") as menu_section:
338
- gr.Markdown("### Menu Page (Below Cart Section)")
339
-
340
- # View Cart Button (Top Position)
341
- view_cart_button_top = gr.Button("View Cart")
342
- empty_div = gr.HTML('<div style="height: 20px;"></div>')
343
- # Radio button for selecting preference
344
  selected_preference = gr.Radio(
345
  choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt Free"],
346
  value="All",
347
  label="Choose a Preference",
348
  )
 
349
  menu_output = gr.HTML(value=filter_menu("All"))
350
-
351
- # View Cart Button (Original Position)
352
- view_cart_button_bottom = gr.Button("View Cart")
353
-
354
  empty_div = gr.HTML('<div style="height: 300px;"></div>')
355
 
356
- # Modal window
 
357
  modal_window = gr.HTML("""
358
  <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
359
  <div style="text-align: right;">
@@ -383,22 +433,16 @@ def app():
383
  <!-- Add to Cart Button -->
384
  <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
385
  </div>
386
- """)
387
 
388
- # Update menu dynamically based on preference
389
- selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
390
-
391
- # Layout
392
- gr.Row(view_cart_button_top) # View Cart button at the top
393
  gr.Row([selected_preference])
394
  gr.Row(menu_output)
395
- gr.Row(view_cart_button_bottom) # View Cart button at the bottom
396
  gr.Row(modal_window)
397
- gr.HTML(modal_and_cart_js)
398
 
399
- # Button Bindings
400
- # Login Button
401
- # Login Button
402
  # Button Bindings
403
  # Login Button
404
  login_button.click(
@@ -412,31 +456,18 @@ def app():
412
  inputs=[signup_name, signup_phone, signup_email, signup_password],
413
  outputs=[signup_message, login_section, signup_section],
414
  )
 
415
  go_to_signup.click(
416
  lambda: (gr.update(visible=False), gr.update(visible=True)),
417
  outputs=[login_section, signup_section],
418
  )
 
419
  go_to_login.click(
420
  lambda: (gr.update(visible=True), gr.update(visible=False)),
421
  outputs=[login_section, signup_section],
422
- )
423
- # Navigate to Cart Page (Both Buttons Use the Same Logic)
424
- view_cart_button_top.click(
425
- lambda: (gr.update(visible=True), gr.update(visible=False)),
426
- outputs=[cart_section, menu_section],
427
- )
428
- view_cart_button_bottom.click(
429
- lambda: (gr.update(visible=True), gr.update(visible=False)),
430
- outputs=[cart_section, menu_section],
431
- )
432
- back_to_menu_button.click(
433
- lambda: (gr.update(visible=False), gr.update(visible=True)),
434
- outputs=[cart_section, menu_section],
435
- )
436
 
437
  return demo
438
 
439
 
440
-
441
  if __name__ == "__main__":
442
- app().launch()
 
77
  </div>
78
  """
79
  return html_content
80
+
81
+
82
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  # Authentication and Navigation Logic
84
  def authenticate_user(email, password):
85
  if check_credentials(email, password):
 
101
 
102
  def app():
103
  with gr.Blocks() as demo:
104
+ # JavaScript for dynamic Cart Modal positioning and resizing
105
+ modal_js = """
106
+ <script>
107
+ let isCartMaximized = false; // Track maximize state for cart
108
+ function toggleCartModalSize() {
109
+ const modal = document.getElementById('cart-modal');
110
+ const maximizeBtn = document.getElementById('cart-maximize-btn');
111
+ const minimizeBtn = document.getElementById('cart-minimize-btn');
112
+
113
+ if (isCartMaximized) {
114
+ modal.style.width = '300px'; // Minimized size
115
+ modal.style.height = '400px';
116
+ modal.style.position = 'absolute';
117
+ modal.style.top = `${event.clientY}px`;
118
+ modal.style.left = `${event.clientX + 50}px`;
119
+ maximizeBtn.style.display = 'block';
120
+ minimizeBtn.style.display = 'none';
121
+ } else {
122
+ modal.style.width = '80%'; // Full-screen size
123
+ modal.style.height = '80%';
124
+ modal.style.position = 'fixed';
125
+ modal.style.top = '10%';
126
+ modal.style.left = '10%';
127
+ maximizeBtn.style.display = 'none';
128
+ minimizeBtn.style.display = 'block';
129
+ }
130
+ isCartMaximized = !isCartMaximized; // Toggle state
131
+ }
132
+
133
+ function showCartModal() {
134
+ const modal = document.getElementById('cart-modal');
135
+ modal.style.display = 'block';
136
+ modal.style.position = 'absolute';
137
+ modal.style.top = `${event.clientY}px`;
138
+ modal.style.left = `${event.clientX + 50}px`;
139
+ }
140
+
141
+ function hideCartModal() {
142
+ const modal = document.getElementById('cart-modal');
143
+ modal.style.display = 'none';
144
+ }
145
+ </script>
146
+ """
147
+
148
+ # Cart Modal Window (Initially Hidden)
149
+ cart_modal = gr.HTML(
150
+ """
151
+ <div id="cart-modal" style="display: none; width: 300px; height: 400px; position: absolute; background: white; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); z-index: 1000;">
152
+ <div style="display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #ddd;">
153
+ <h3 style="margin: 0;">Cart & Final Order</h3>
154
+ <button id="cart-maximize-btn" onclick="toggleCartModalSize()" style="background: #28a745; color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer;">Maximize</button>
155
+ <button id="cart-minimize-btn" onclick="toggleCartModalSize()" style="display: none; background: #007bff; color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer;">Minimize</button>
156
+ </div>
157
+ <div id="cart-content" style="padding: 10px; overflow-y: auto; height: calc(100% - 50px);">
158
+
159
+ <style>
160
+ .cart-container {
161
+ width: 90%; /* Ensure it fits the screen */
162
+ margin: auto;
163
+ display: flex;
164
+ flex-direction: column;
165
+ gap: 10px; /* Add space between cart items */
166
+ }
167
+ .cart-item {
168
+ display: flex;
169
+ flex-wrap: wrap; /* Wrap content to the next line if needed */
170
+ align-items: center; /* Vertically align items */
171
+ justify-content: space-between; /* Distribute space between items */
172
+ width: 100%; /* Ensure it takes full width */
173
+ padding: 10px;
174
+ border: 1px solid #ccc;
175
+ border-radius: 5px;
176
+ background-color: #f9f9f9;
177
+ }
178
+ .cart-item span {
179
+ margin-right: 10px;
180
+ flex: 1; /* Allow text to take available space */
181
+ min-width: 50px; /* Prevent collapsing */
182
+ }
183
+ .cart-item .quantity-container {
184
+ display: flex;
185
+ align-items: center;
186
+ gap: 5px;
187
+ }
188
+ .cart-item button {
189
+ background-color: red;
190
+ color: white;
191
+ border: none;
192
+ padding: 5px 10px;
193
+ cursor: pointer;
194
+ border-radius: 5px;
195
+ flex-shrink: 0; /* Prevent the button from shrinking */
196
+ }
197
+ .cart-total {
198
+ font-size: 1.2em;
199
+ font-weight: bold;
200
+ text-align: center;
201
+ }
202
+ button {
203
+ margin-top: 10px;
204
+ background-color: #007bff;
205
+ color: white;
206
+ border: none;
207
+ padding: 10px;
208
+ border-radius: 5px;
209
+ width: 100%;
210
+ cursor: pointer;
211
+ }
212
+ @media (max-width: 768px) {
213
+ .cart-item {
214
+ flex-direction: column; /* Stack items on mobile */
215
+ align-items: flex-start; /* Align to the left */
216
+ }
217
+ .cart-item button {
218
+ align-self: flex-end; /* Place the remove button at the end */
219
+ margin-top: 5px; /* Add some space on top */
220
+ }
221
+ }
222
+ </style>
223
+ <script>
224
+ let cart = [];
225
+ const extrasPrices = {
226
+ "Thums up": 2,
227
+ "Sprite": 2,
228
+ "Extra Raitha": 1,
229
+ "Extra Salan": 2,
230
+ "Extra Onion & Lemon": 2,
231
+ "Chilli Chicken": 14,
232
+ "Veg Manchurian": 12
233
+ };
234
+ let finalized = false;
235
+ function openModal(name, image2, description, price) {
236
+ if (finalized) {
237
+ alert("You cannot add more items after finalizing your order.");
238
+ return;
239
+ }
240
+ const modal = document.getElementById('modal');
241
+ modal.style.display = 'block';
242
+ modal.style.position = 'fixed';
243
+ if (window.innerWidth <= 768) {
244
+ modal.style.width = '90%';
245
+ modal.style.top = `${event.touches ? event.touches[0].screenY : event.clientY}px`;
246
+ } else {
247
+ modal.style.width = '30%';
248
+ modal.style.top = `${event.clientY}px`;// Use mouse Y position for laptop
249
+ }
250
+ modal.style.left = '50%';
251
+ modal.style.transform = 'translate(-50%, -50%)';
252
+ document.getElementById('modal-image').src = image2;
253
+ document.getElementById('modal-name').innerText = name;
254
+ document.getElementById('modal-description').innerText = description;
255
+ document.getElementById('modal-price').innerText = price;
256
+ const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
257
+ extrasInputs.forEach(input => input.checked = false);
258
+ document.getElementById('quantity').value = 1;
259
+ document.getElementById('special-instructions').value = '';
260
+ }
261
+ function closeModal() {
262
+ document.getElementById('modal').style.display = 'none';
263
+ }
264
+ function addToCart() {
265
+ if (finalized) {
266
+ alert("You cannot add more items after finalizing your order.");
267
+ return;
268
+ }
269
+ const name = document.getElementById('modal-name').innerText;
270
+ const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
271
+ const quantity = parseInt(document.getElementById('quantity').value) || 1;
272
+ const instructions = document.getElementById('special-instructions').value;
273
+ const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
274
+ const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);
275
+ const itemTotal = (price + extrasCost) * quantity;
276
+ const cartItem = { name, price, quantity, instructions, extras, itemTotal, extrasQuantities: extras.map(() => 1) };
277
+ cart.push(cartItem);
278
+ alert(`${name} added to cart!`);
279
+ updateCartDisplay();
280
+ closeModal();
281
+ }
282
+ function updateCartDisplay() {
283
+ let totalBill = 0;
284
+ let cartHTML = "<div class='cart-container'>";
285
+ cart.forEach((item, index) => {
286
+ totalBill += item.itemTotal;
287
+ const extras = item.extras.map((extra, i) => {
288
+ const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
289
+ const extraTotal = extrasPrices[extra] * extraQuantity;
290
+ totalBill += extraTotal;
291
+ return `<div class='cart-item'>
292
+ <span>${extra}</span>
293
+ <span>Price: $${extrasPrices[extra].toFixed(2)}</span>
294
+ <div class='quantity-container'>
295
+ <label for='extra-quantity-${index}-${i}'>Quantity:</label>
296
+ <input type='number' id='extra-quantity-${index}-${i}' value='${extraQuantity}' min='1' style='width: 50px;' onchange='updateExtraQuantity(${index}, ${i}, this.value)'>
297
+ </div>
298
+ <span>Total: $${extraTotal.toFixed(2)}</span>
299
+ <button style='background-color: red; color: white; border: none; padding: 5px 10px; cursor: pointer;' onclick='removeExtra(${index}, ${i})'>Remove</button>
300
+ </div>`;
301
+ }).join('');
302
+ cartHTML += `<div class='cart-item'>
303
+ <span>${item.name}</span>
304
+ <span>Item Price: $${item.price.toFixed(2)}</span>
305
+ <div class='quantity-container'>
306
+ <label for='item-quantity-${index}'>Quantity:</label>
307
+ <input type='number' id='item-quantity-${index}' value='${item.quantity}' min='1' style='width: 50px;' onchange='updateItemQuantity(${index}, this.value)'>
308
+ </div>
309
+ <span>Total: $${(item.price * item.quantity).toFixed(2)}</span>
310
+ <button style='background-color: red; color: white; border: none; padding: 5px 10px; cursor: pointer;' onclick='removeItem(${index})'>Remove</button>
311
+ </div>
312
+ ${extras}
313
+ <div class='cart-item'><strong>Instructions:</strong> ${item.instructions || "None"}</div>`;
314
+ });
315
+ cartHTML += `</div><p class='cart-total'>Total Bill: $${totalBill.toFixed(2)}</p>`;
316
+ cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
317
+ document.getElementById('floating-cart').innerHTML = cartHTML;
318
+ }
319
+ function updateItemQuantity(index, newQuantity) {
320
+ const quantity = parseInt(newQuantity) || 1;
321
+ cart[index].quantity = quantity;
322
+ cart[index].itemTotal = cart[index].price * quantity;
323
+ updateCartDisplay();
324
+ }
325
+ function updateExtraQuantity(cartIndex, extraIndex, newQuantity) {
326
+ const quantity = parseInt(newQuantity) || 1;
327
+ cart[cartIndex].extrasQuantities = cart[cartIndex].extrasQuantities || [];
328
+ cart[cartIndex].extrasQuantities[extraIndex] = quantity;
329
+ updateCartDisplay();
330
+ }
331
+ function removeExtra(cartIndex, extraIndex) {
332
+ cart[cartIndex].extras.splice(extraIndex, 1);
333
+ if (cart[cartIndex].extrasQuantities) {
334
+ cart[cartIndex].extrasQuantities.splice(extraIndex, 1);
335
+ }
336
+ updateCartDisplay();
337
+ }
338
+ function removeItem(index) {
339
+ cart.splice(index, 1);
340
+ updateCartDisplay();
341
+ }
342
+ function submitCart() {
343
+ let finalOrderHTML = "<h3>Final Order:</h3><ul>";
344
+ let totalBill = 0;
345
+ cart.forEach(item => {
346
+ totalBill += item.itemTotal;
347
+ const extras = item.extras.map((extra, i) => {
348
+ const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
349
+ const extraTotal = extrasPrices[extra] * extraQuantity;
350
+ totalBill += extraTotal;
351
+ return `${extra} (x${extraQuantity}) - $${extraTotal.toFixed(2)}`;
352
+ }).join(', ');
353
+ finalOrderHTML += `<li>
354
+ ${item.name} (x${item.quantity}) - $${item.itemTotal.toFixed(2)}
355
+ <br>Extras: ${extras}
356
+ <br>Instructions: ${item.instructions || "None"}
357
+ </li>`;
358
+ });
359
+ finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
360
+ document.getElementById('final-order').innerHTML = finalOrderHTML;
361
+ alert("Your final order has been submitted!");
362
+ }
363
+ </script>
364
+
365
+ # Authentication and Navigation Logic
366
+ <p>Your cart content will appear here.</p>
367
+ </div>
368
+ <button onclick="hideCartModal()" style="background: red; color: white; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; width: 100%;">Close</button>
369
+ </div>
370
+ """
371
+ )
372
 
373
  # Login Page
374
  with gr.Column(visible=True) as login_section:
 
390
  signup_button = gr.Button("Sign Up")
391
  go_to_login = gr.Button("Back to Login")
392
 
393
+ # Menu Page
394
+ with gr.Column(visible=False) as menu_section:
395
+ gr.Markdown("### Menu Page")
 
 
 
 
 
396
  selected_preference = gr.Radio(
397
  choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt Free"],
398
  value="All",
399
  label="Choose a Preference",
400
  )
401
+ empty_div = gr.HTML('<div style="height: 20px;"></div>')
402
  menu_output = gr.HTML(value=filter_menu("All"))
 
 
 
 
403
  empty_div = gr.HTML('<div style="height: 300px;"></div>')
404
 
405
+
406
+ # Modal window for items
407
  modal_window = gr.HTML("""
408
  <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
409
  <div style="text-align: right;">
 
433
  <!-- Add to Cart Button -->
434
  <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
435
  </div>
436
+ """)
437
 
438
+ # Render modals
 
 
 
 
439
  gr.Row([selected_preference])
440
  gr.Row(menu_output)
 
441
  gr.Row(modal_window)
442
+ gr.Row(cart_modal)
443
 
444
+ # Add JavaScript for modal functionality
445
+ gr.HTML(modal_js)
 
446
  # Button Bindings
447
  # Login Button
448
  login_button.click(
 
456
  inputs=[signup_name, signup_phone, signup_email, signup_password],
457
  outputs=[signup_message, login_section, signup_section],
458
  )
459
+ # Navigate to Signup Page
460
  go_to_signup.click(
461
  lambda: (gr.update(visible=False), gr.update(visible=True)),
462
  outputs=[login_section, signup_section],
463
  )
464
+ # Navigate Back to Login Page
465
  go_to_login.click(
466
  lambda: (gr.update(visible=True), gr.update(visible=False)),
467
  outputs=[login_section, signup_section],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
 
469
  return demo
470
 
471
 
 
472
  if __name__ == "__main__":
473
+ app().launch()