geethareddy commited on
Commit
66c0eb4
·
verified ·
1 Parent(s): 2887f28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -49
app.py CHANGED
@@ -112,7 +112,7 @@ def filter_menu(preference):
112
 
113
  return html_content
114
 
115
- # Create Modal Window HTML
116
  def create_modal_window():
117
  add_ons = load_add_ons_from_salesforce()
118
  add_ons_html = ""
@@ -157,7 +157,7 @@ def modal_js():
157
  modal.style.display = 'block';
158
  modal.style.position = 'fixed';
159
  modal.style.width = window.innerWidth <= 768 ? '90%' : '30%';
160
- modal.style.top = ${event.clientY}px;
161
  modal.style.left = '50%';
162
  modal.style.transform = 'translate(-50%, -50%)';
163
  document.getElementById('modal-image').src = image2;
@@ -193,15 +193,15 @@ def modal_js():
193
  }
194
  function updateCartButton() {
195
  const cartButton = document.getElementById('cart-button');
196
- cartButton.innerText = View Cart (${cart.length} items);
197
  }
198
  function openCartModal() {
199
  const cartModal = document.getElementById('cart-modal');
200
  const cartItemsContainer = document.getElementById('cart-items');
201
  cartItemsContainer.innerHTML = "";
202
  cart.forEach((item, index) => {
203
- const extrasList = item.extras.map(extra => ${extra.name} x<input type="number" value="${extra.quantity}" min="1" style="width: 50px;" onchange="updateCartItem(${index}, 'extra', this.value)" /> (+$${(extra.price * extra.quantity).toFixed(2)})).join(', ');
204
- cartItemsContainer.innerHTML +=
205
  <div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
206
  <h3>${item.name}</h3>
207
  <p>Quantity: <input type="number" value="${item.quantity}" min="1" style="width: 50px;" onchange="updateCartItem(${index}, 'item', this.value)" /></p>
@@ -210,7 +210,7 @@ def modal_js():
210
  <p>Total Cost: $<span id="item-${index}-total">${item.totalCost.toFixed(2)}</span></p>
211
  <button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
212
  </div>
213
- ;
214
  });
215
  cartModal.style.display = 'block';
216
  }
@@ -234,13 +234,13 @@ def modal_js():
234
  const price = item.price;
235
  const extrasCost = item.extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
236
  item.totalCost = (price * item.quantity) + extrasCost;
237
- document.getElementById(item-${index}-total).innerText = item.totalCost.toFixed(2);
238
  updateCartTotalCost(); // Update total cost displayed
239
  }
240
  function updateCartTotalCost() {
241
  const totalCostElement = document.getElementById('cart-total-cost');
242
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
243
- totalCostElement.innerText = Total Cart Cost: $${totalCartCost.toFixed(2)};
244
  }
245
  function proceedToCheckout() {
246
  alert("Proceeding to checkout...");
@@ -253,44 +253,3 @@ def modal_js():
253
  </script>
254
  """
255
  return modal_script
256
-
257
- # Gradio App
258
- with gr.Blocks() as app:
259
- with gr.Row():
260
- gr.HTML("<h1 style='text-align: center;'>Welcome to Biryani Hub</h1>")
261
-
262
- with gr.Row(visible=True) as login_page:
263
- with gr.Column():
264
- login_email = gr.Textbox(label="Email")
265
- login_password = gr.Textbox(label="Password", type="password")
266
- login_button = gr.Button("Login")
267
- signup_button = gr.Button("Go to Signup")
268
- login_output = gr.Textbox(label="Status")
269
-
270
- with gr.Row(visible=False) as signup_page:
271
- with gr.Column():
272
- signup_name = gr.Textbox(label="Name")
273
- signup_email = gr.Textbox(label="Email")
274
- signup_phone = gr.Textbox(label="Phone")
275
- signup_password = gr.Textbox(label="Password", type="password")
276
- submit_signup = gr.Button("Signup")
277
- login_redirect = gr.Button("Go to Login")
278
- signup_output = gr.Textbox(label="Status")
279
-
280
- with gr.Row(visible=False) as menu_page:
281
- with gr.Column():
282
- preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
283
- menu_output = gr.HTML()
284
- 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>")
285
- 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>")
286
- gr.HTML(create_modal_window())
287
- gr.HTML(modal_js())
288
-
289
- login_button.click(
290
- lambda email, password: (gr.update(visible=False), gr.update(visible=True), gr.update(value=filter_menu("All")), "Login successful!")
291
- if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), gr.update(), "Invalid email or password."),
292
- [login_email, login_password], [login_page, menu_page, menu_output, login_output]
293
- )
294
- preference.change(lambda pref: filter_menu(pref), [preference], menu_output)
295
-
296
- app.launch()
 
112
 
113
  return html_content
114
 
115
+ # Create Modal Window for Add-ons and Quantity
116
  def create_modal_window():
117
  add_ons = load_add_ons_from_salesforce()
118
  add_ons_html = ""
 
157
  modal.style.display = 'block';
158
  modal.style.position = 'fixed';
159
  modal.style.width = window.innerWidth <= 768 ? '90%' : '30%';
160
+ modal.style.top = `${event.clientY}px`;
161
  modal.style.left = '50%';
162
  modal.style.transform = 'translate(-50%, -50%)';
163
  document.getElementById('modal-image').src = image2;
 
193
  }
194
  function updateCartButton() {
195
  const cartButton = document.getElementById('cart-button');
196
+ cartButton.innerText = `View Cart (${cart.length} items)`;
197
  }
198
  function openCartModal() {
199
  const cartModal = document.getElementById('cart-modal');
200
  const cartItemsContainer = document.getElementById('cart-items');
201
  cartItemsContainer.innerHTML = "";
202
  cart.forEach((item, index) => {
203
+ const extrasList = item.extras.map(extra => `${extra.name} x<input type="number" value="${extra.quantity}" min="1" style="width: 50px;" onchange="updateCartItem(${index}, 'extra', this.value)" /> (+$${(extra.price * extra.quantity).toFixed(2)})`).join(', ');
204
+ cartItemsContainer.innerHTML += `
205
  <div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
206
  <h3>${item.name}</h3>
207
  <p>Quantity: <input type="number" value="${item.quantity}" min="1" style="width: 50px;" onchange="updateCartItem(${index}, 'item', this.value)" /></p>
 
210
  <p>Total Cost: $<span id="item-${index}-total">${item.totalCost.toFixed(2)}</span></p>
211
  <button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
212
  </div>
213
+ `;
214
  });
215
  cartModal.style.display = 'block';
216
  }
 
234
  const price = item.price;
235
  const extrasCost = item.extras.reduce((total, extra) => total + (extra.price * extra.quantity), 0);
236
  item.totalCost = (price * item.quantity) + extrasCost;
237
+ document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
238
  updateCartTotalCost(); // Update total cost displayed
239
  }
240
  function updateCartTotalCost() {
241
  const totalCostElement = document.getElementById('cart-total-cost');
242
  totalCartCost = cart.reduce((total, item) => total + item.totalCost, 0);
243
+ totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
244
  }
245
  function proceedToCheckout() {
246
  alert("Proceeding to checkout...");
 
253
  </script>
254
  """
255
  return modal_script