nagasurendra commited on
Commit
d262a2e
·
verified ·
1 Parent(s): 74ca9fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -20
app.py CHANGED
@@ -191,10 +191,6 @@ def modal_js():
191
  updateCartTotalCost(); // Update total cost displayed
192
  closeModal();
193
  }
194
- function resetAddOns() {
195
- const checkboxes = document.querySelectorAll('input[name="biryani-extra"]');
196
- checkboxes.forEach(checkbox => checkbox.checked = false); // Uncheck all add-ons
197
- }
198
  function updateCartButton() {
199
  const cartButton = document.getElementById('cart-button');
200
  cartButton.innerText = `View Cart (${cart.length} items)`;
@@ -246,24 +242,37 @@ def modal_js():
246
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
247
  totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
248
  }
249
- function submitOrder() {
250
- const orderDetails = cart.map(item => `${item.name} (x${item.quantity}) - $${item.totalCost.toFixed(2)}`).join('<br>');
251
- const totalCost = cart.reduce((total, item) => total + item.totalCost, 0).toFixed(2);
252
- document.getElementById('order-summary').innerHTML = orderDetails;
253
- document.getElementById('total-bill').innerText = `$${totalCost}`;
254
- // Close the cart modal
255
- closeCartModal();
256
- // Navigate to the final order page
257
- document.getElementById('final-order-page').style.display = 'block';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  }
259
  </script>
260
  """
261
  return modal_script
262
 
263
-
264
  # Gradio App
265
  with gr.Blocks() as app:
266
- # Login and Signup pages
267
  with gr.Row():
268
  gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
269
 
@@ -290,17 +299,17 @@ with gr.Blocks() as app:
290
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
291
  menu_output = gr.HTML()
292
  gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
293
- gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>&times;</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='submitOrder()'>Submit Order</button></div></div>")
294
  gr.HTML(create_modal_window())
295
  gr.HTML(modal_js())
296
 
297
  # Final Order Page
298
  with gr.Row(visible=False) as final_order_page:
299
  with gr.Column():
300
- gr.HTML("<h2>Final Order:</h2>")
301
- order_summary = gr.HTML()
302
- gr.HTML("<h3>Total Bill:</h3>")
303
- total_bill = gr.Textbox()
304
 
305
  login_button.click(
306
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
 
191
  updateCartTotalCost(); // Update total cost displayed
192
  closeModal();
193
  }
 
 
 
 
194
  function updateCartButton() {
195
  const cartButton = document.getElementById('cart-button');
196
  cartButton.innerText = `View Cart (${cart.length} items)`;
 
242
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
243
  totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
244
  }
245
+ function proceedToCheckout() {
246
+ // Trigger the final order page and send the cart data
247
+ const finalOrderPage = document.getElementById('final-order-section');
248
+ const cartPage = document.getElementById('cart-section');
249
+ cartPage.style.display = 'none';
250
+ finalOrderPage.style.display = 'block';
251
+
252
+ // Show the cart details on the final order page
253
+ const finalOrderItems = document.getElementById('final-order-items');
254
+ const finalOrderTotal = document.getElementById('final-order-total');
255
+ let itemsHtml = '';
256
+ let totalBill = 0;
257
+ cart.forEach(item => {
258
+ itemsHtml += `<p>${item.name} (x${item.quantity}) - $${item.totalCost.toFixed(2)}</p>`;
259
+ totalBill += item.totalCost;
260
+ });
261
+ finalOrderItems.innerHTML = itemsHtml;
262
+ finalOrderTotal.innerHTML = `Total Bill: $${totalBill.toFixed(2)}`;
263
+ }
264
+ function goBackToMenu() {
265
+ const finalOrderPage = document.getElementById('final-order-section');
266
+ const cartPage = document.getElementById('cart-section');
267
+ finalOrderPage.style.display = 'none';
268
+ cartPage.style.display = 'block';
269
  }
270
  </script>
271
  """
272
  return modal_script
273
 
 
274
  # Gradio App
275
  with gr.Blocks() as app:
 
276
  with gr.Row():
277
  gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
278
 
 
299
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
300
  menu_output = gr.HTML()
301
  gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
302
+ gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>&times;</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button></div></div>")
303
  gr.HTML(create_modal_window())
304
  gr.HTML(modal_js())
305
 
306
  # Final Order Page
307
  with gr.Row(visible=False) as final_order_page:
308
  with gr.Column():
309
+ gr.HTML("<h1>Your Final Order</h1>")
310
+ final_order_items = gr.HTML()
311
+ final_order_total = gr.HTML()
312
+ gr.Button("Go Back to Menu", elem_id="back-to-menu-button")
313
 
314
  login_button.click(
315
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")