Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,7 +52,6 @@ modal_and_cart_js = """
|
|
| 52 |
"Extra Fried Onion 4oz": 2
|
| 53 |
};
|
| 54 |
let finalized = false;
|
| 55 |
-
|
| 56 |
function openModal(name, image, description, price) {
|
| 57 |
if (finalized) {
|
| 58 |
alert("You cannot add more items after finalizing your order.");
|
|
@@ -71,11 +70,9 @@ modal_and_cart_js = """
|
|
| 71 |
document.getElementById('quantity').value = 1;
|
| 72 |
document.getElementById('special-instructions').value = '';
|
| 73 |
}
|
| 74 |
-
|
| 75 |
function closeModal() {
|
| 76 |
document.getElementById('modal').style.display = 'none';
|
| 77 |
}
|
| 78 |
-
|
| 79 |
function addToCart() {
|
| 80 |
if (finalized) {
|
| 81 |
alert("You cannot add more items after finalizing your order.");
|
|
@@ -95,7 +92,6 @@ modal_and_cart_js = """
|
|
| 95 |
updateCartDisplay();
|
| 96 |
closeModal();
|
| 97 |
}
|
| 98 |
-
|
| 99 |
function updateCartDisplay() {
|
| 100 |
let totalBill = 0;
|
| 101 |
let cartHTML = "<h3>Your Cart:</h3><ul>";
|
|
@@ -107,29 +103,28 @@ modal_and_cart_js = """
|
|
| 107 |
cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 108 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 109 |
}
|
| 110 |
-
|
| 111 |
function removeItem(index) {
|
| 112 |
cart.splice(index, 1);
|
| 113 |
updateCartDisplay();
|
| 114 |
}
|
| 115 |
-
|
| 116 |
-
function showSummary() {
|
| 117 |
if (cart.length === 0) {
|
| 118 |
-
alert("Your cart is empty. Please add items before
|
| 119 |
return;
|
| 120 |
}
|
| 121 |
finalized = true;
|
| 122 |
-
let
|
| 123 |
let totalBill = 0;
|
| 124 |
cart.forEach(item => {
|
| 125 |
totalBill += item.itemTotal;
|
| 126 |
const extras = item.extras.join(', ');
|
| 127 |
-
|
| 128 |
});
|
| 129 |
-
|
| 130 |
-
document.getElementById('summary-
|
| 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>
|
|
@@ -159,24 +154,26 @@ def app():
|
|
| 159 |
# Floating cart display
|
| 160 |
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
| 161 |
|
| 162 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
summary_container = gr.Group(visible=False, elem_id="summary-container")
|
| 164 |
with summary_container:
|
| 165 |
-
summary_output = gr.HTML(value="", elem_id="summary-
|
| 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([
|
| 180 |
gr.Row([summary_container])
|
| 181 |
gr.HTML(modal_and_cart_js)
|
| 182 |
|
|
|
|
| 52 |
"Extra Fried Onion 4oz": 2
|
| 53 |
};
|
| 54 |
let finalized = false;
|
|
|
|
| 55 |
function openModal(name, image, description, price) {
|
| 56 |
if (finalized) {
|
| 57 |
alert("You cannot add more items after finalizing your order.");
|
|
|
|
| 70 |
document.getElementById('quantity').value = 1;
|
| 71 |
document.getElementById('special-instructions').value = '';
|
| 72 |
}
|
|
|
|
| 73 |
function closeModal() {
|
| 74 |
document.getElementById('modal').style.display = 'none';
|
| 75 |
}
|
|
|
|
| 76 |
function addToCart() {
|
| 77 |
if (finalized) {
|
| 78 |
alert("You cannot add more items after finalizing your order.");
|
|
|
|
| 92 |
updateCartDisplay();
|
| 93 |
closeModal();
|
| 94 |
}
|
|
|
|
| 95 |
function updateCartDisplay() {
|
| 96 |
let totalBill = 0;
|
| 97 |
let cartHTML = "<h3>Your Cart:</h3><ul>";
|
|
|
|
| 103 |
cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 104 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 105 |
}
|
|
|
|
| 106 |
function removeItem(index) {
|
| 107 |
cart.splice(index, 1);
|
| 108 |
updateCartDisplay();
|
| 109 |
}
|
| 110 |
+
function finalizeOrder() {
|
|
|
|
| 111 |
if (cart.length === 0) {
|
| 112 |
+
alert("Your cart is empty. Please add items before finalizing.");
|
| 113 |
return;
|
| 114 |
}
|
| 115 |
finalized = true;
|
| 116 |
+
let finalOrderHTML = "<h3>Final Order:</h3><ul>";
|
| 117 |
let totalBill = 0;
|
| 118 |
cart.forEach(item => {
|
| 119 |
totalBill += item.itemTotal;
|
| 120 |
const extras = item.extras.join(', ');
|
| 121 |
+
finalOrderHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
|
| 122 |
});
|
| 123 |
+
finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 124 |
+
document.getElementById('summary-output').innerHTML = finalOrderHTML;
|
| 125 |
document.getElementById('menu-container').style.display = 'none';
|
| 126 |
document.getElementById('cart-container').style.display = 'none';
|
| 127 |
+
document.getElementById('finalize-container').style.display = 'none';
|
| 128 |
document.getElementById('summary-container').style.display = 'block';
|
| 129 |
}
|
| 130 |
</script>
|
|
|
|
| 154 |
# Floating cart display
|
| 155 |
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
| 156 |
|
| 157 |
+
# Finalize order button
|
| 158 |
+
finalize_container = gr.Group(visible=True, elem_id="finalize-container")
|
| 159 |
+
with finalize_container:
|
| 160 |
+
finalize_button = gr.Button("Finalize Order")
|
| 161 |
+
|
| 162 |
+
# Summary display 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-output")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
# Update menu dynamically based on preference
|
| 168 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
| 169 |
|
| 170 |
+
# Finalize order button click event
|
| 171 |
+
finalize_button.click(lambda: "Order finalized!", inputs=[], outputs=[])
|
| 172 |
+
|
| 173 |
# Layout
|
| 174 |
gr.Row([menu_container])
|
| 175 |
gr.Row([cart_container])
|
| 176 |
+
gr.Row([finalize_container])
|
| 177 |
gr.Row([summary_container])
|
| 178 |
gr.HTML(modal_and_cart_js)
|
| 179 |
|