nagasurendra commited on
Commit
f2c84ee
·
verified ·
1 Parent(s): 2559653

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -63,7 +63,6 @@ modal_and_cart_js = """
63
  document.getElementById('modal-name').innerText = name;
64
  document.getElementById('modal-description').innerText = description;
65
  document.getElementById('modal-price').innerText = price;
66
-
67
  // Reset spice levels and extras
68
  const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
69
  spiceLevelInputs.forEach(input => input.checked = false);
@@ -114,25 +113,24 @@ modal_and_cart_js = """
114
  updateCartDisplay();
115
  }
116
 
117
- function finalizeOrder() {
118
  if (cart.length === 0) {
119
- alert("Your cart is empty. Please add items before finalizing.");
120
  return;
121
  }
122
  finalized = true;
123
- let finalOrderHTML = "<h3>Final Order:</h3><ul>";
124
  let totalBill = 0;
125
  cart.forEach(item => {
126
  totalBill += item.itemTotal;
127
  const extras = item.extras.join(', ');
128
- finalOrderHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
129
  });
130
- finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
131
- document.getElementById('final-order').innerHTML = finalOrderHTML;
132
  document.getElementById('menu-container').style.display = 'none';
133
  document.getElementById('cart-container').style.display = 'none';
134
- document.getElementById('finalize-container').style.display = 'none';
135
- document.getElementById('final-order-container').style.display = 'block';
136
  }
137
  </script>
138
  """
@@ -161,27 +159,25 @@ def app():
161
  # Floating cart display
162
  cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
163
 
164
- # Finalize order button
165
- finalize_container = gr.Group(visible=True, elem_id="finalize-container")
166
- with finalize_container:
167
- finalize_button = gr.Button("Finalize Order")
 
 
 
168
 
169
- # Final order display container
170
- final_order_container = gr.Group(visible=False, elem_id="final-order-container")
171
- with final_order_container:
172
- final_order_output = gr.HTML(value="", elem_id="final-order")
173
 
174
  # Update menu dynamically based on preference
175
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
176
 
177
- # Finalize order button click event
178
- finalize_button.click(lambda: "Finalizing order...", inputs=[], outputs=[])
179
-
180
  # Layout
181
  gr.Row([menu_container])
182
  gr.Row([cart_container])
183
- gr.Row([finalize_container])
184
- gr.Row([final_order_container])
185
  gr.HTML(modal_and_cart_js)
186
 
187
  return demo
 
63
  document.getElementById('modal-name').innerText = name;
64
  document.getElementById('modal-description').innerText = description;
65
  document.getElementById('modal-price').innerText = price;
 
66
  // Reset spice levels and extras
67
  const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
68
  spiceLevelInputs.forEach(input => input.checked = false);
 
113
  updateCartDisplay();
114
  }
115
 
116
+ function showSummary() {
117
  if (cart.length === 0) {
118
+ alert("Your cart is empty. Please add items before viewing the summary.");
119
  return;
120
  }
121
  finalized = true;
122
+ let summaryHTML = "<h3>Order Summary:</h3><ul>";
123
  let totalBill = 0;
124
  cart.forEach(item => {
125
  totalBill += item.itemTotal;
126
  const extras = item.extras.join(', ');
127
+ summaryHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
128
  });
129
+ summaryHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
130
+ document.getElementById('summary-container').innerHTML = summaryHTML;
131
  document.getElementById('menu-container').style.display = 'none';
132
  document.getElementById('cart-container').style.display = 'none';
133
+ document.getElementById('summary-container').style.display = 'block';
 
134
  }
135
  </script>
136
  """
 
159
  # Floating cart display
160
  cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
161
 
162
+ # Summary container
163
+ summary_container = gr.Group(visible=False, elem_id="summary-container")
164
+ with summary_container:
165
+ summary_output = gr.HTML(value="", elem_id="summary-container")
166
+
167
+ # Finalize Order Button
168
+ finalize_button = gr.Button("View Summary")
169
 
170
+ # Finalize order button click event
171
+ finalize_button.click(lambda: "", inputs=[], outputs=[], _js="showSummary")
 
 
172
 
173
  # Update menu dynamically based on preference
174
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
175
 
 
 
 
176
  # Layout
177
  gr.Row([menu_container])
178
  gr.Row([cart_container])
179
+ gr.Row([finalize_button])
180
+ gr.Row([summary_container])
181
  gr.HTML(modal_and_cart_js)
182
 
183
  return demo