Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -125,7 +125,7 @@ def create_modal_window():
|
|
125 |
"""
|
126 |
|
127 |
modal_html = f"""
|
128 |
-
<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:
|
129 |
<div style="text-align: right;">
|
130 |
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
131 |
</div>
|
@@ -150,35 +150,25 @@ def modal_js():
|
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
let cart = [];
|
153 |
-
function openCartModal() {
|
154 |
-
const cartModal = document.getElementById('cart-modal');
|
155 |
-
const cartItemsContainer = document.getElementById('cart-items');
|
156 |
-
|
157 |
-
// Empty the current cart content and update with the latest cart items
|
158 |
-
cartItemsContainer.innerHTML = "";
|
159 |
-
|
160 |
-
// Loop through the cart and add it to the modal
|
161 |
-
cart.forEach((item, index) => {
|
162 |
-
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
163 |
-
cartItemsContainer.innerHTML += `
|
164 |
-
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
165 |
-
<h3>${item.name}</h3>
|
166 |
-
<p>Quantity: ${item.quantity}</p>
|
167 |
-
<p>Extras: ${extrasList || 'None'}</p>
|
168 |
-
<p>Special Instructions: ${item.instructions || 'None'}</p>
|
169 |
-
<p>Total Cost: $${item.totalCost.toFixed(2)}</p>
|
170 |
-
<button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
|
171 |
-
</div>
|
172 |
-
`;
|
173 |
-
});
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
}
|
179 |
|
180 |
function closeModal() {
|
181 |
-
document.getElementById('
|
182 |
}
|
183 |
|
184 |
function addToCart() {
|
@@ -192,31 +182,44 @@ def modal_js():
|
|
192 |
}));
|
193 |
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
194 |
const totalCost = (price + extrasCost) * quantity;
|
195 |
-
|
196 |
-
// Push the item to the cart
|
197 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
198 |
-
|
199 |
-
// Update the cart button text with the number of items
|
200 |
updateCartButton();
|
201 |
-
|
202 |
-
// Close the modal after adding the item
|
203 |
closeModal();
|
204 |
}
|
205 |
|
206 |
function updateCartButton() {
|
207 |
-
// Update both buttons to show the number of items in the cart
|
208 |
const cartButton = document.getElementById('cart-button');
|
209 |
-
const cartButtonTop = document.getElementById('cart-button-top');
|
210 |
-
|
211 |
cartButton.innerText = `View Cart (${cart.length} items)`;
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
}
|
214 |
|
215 |
function removeFromCart(index) {
|
216 |
-
// Remove an item from the cart and update the cart button
|
217 |
cart.splice(index, 1);
|
218 |
updateCartButton();
|
219 |
-
openCartModal();
|
220 |
}
|
221 |
|
222 |
function proceedToCheckout() {
|
@@ -253,8 +256,12 @@ with gr.Blocks() as app:
|
|
253 |
with gr.Column():
|
254 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
255 |
menu_output = gr.HTML()
|
256 |
-
gr.HTML("
|
257 |
-
|
|
|
|
|
|
|
|
|
258 |
gr.HTML(create_modal_window())
|
259 |
gr.HTML(modal_js())
|
260 |
|
|
|
125 |
"""
|
126 |
|
127 |
modal_html = f"""
|
128 |
+
<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;">
|
129 |
<div style="text-align: right;">
|
130 |
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
131 |
</div>
|
|
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
let cart = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
+
function openModal(name, image2, description, price) {
|
155 |
+
const modal = document.getElementById('modal');
|
156 |
+
modal.style.display = 'block';
|
157 |
+
modal.style.position = 'fixed';
|
158 |
+
modal.style.width = window.innerWidth <= 768 ? '90%' : '30%';
|
159 |
+
modal.style.top = `${event.clientY}px`;
|
160 |
+
modal.style.left = '50%';
|
161 |
+
modal.style.transform = 'translate(-50%, -50%)';
|
162 |
+
document.getElementById('modal-image').src = image2;
|
163 |
+
document.getElementById('modal-name').innerText = name;
|
164 |
+
document.getElementById('modal-description').innerText = description;
|
165 |
+
document.getElementById('modal-price').innerText = price;
|
166 |
+
document.getElementById('quantity').value = 1;
|
167 |
+
document.getElementById('special-instructions').value = '';
|
168 |
}
|
169 |
|
170 |
function closeModal() {
|
171 |
+
document.getElementById('modal').style.display = 'none';
|
172 |
}
|
173 |
|
174 |
function addToCart() {
|
|
|
182 |
}));
|
183 |
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
184 |
const totalCost = (price + extrasCost) * quantity;
|
|
|
|
|
185 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
|
|
|
|
186 |
updateCartButton();
|
|
|
|
|
187 |
closeModal();
|
188 |
}
|
189 |
|
190 |
function updateCartButton() {
|
|
|
191 |
const cartButton = document.getElementById('cart-button');
|
|
|
|
|
192 |
cartButton.innerText = `View Cart (${cart.length} items)`;
|
193 |
+
}
|
194 |
+
|
195 |
+
function openCartModal() {
|
196 |
+
const cartModal = document.getElementById('cart-modal');
|
197 |
+
const cartItemsContainer = document.getElementById('cart-items');
|
198 |
+
cartItemsContainer.innerHTML = "";
|
199 |
+
cart.forEach((item, index) => {
|
200 |
+
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
201 |
+
cartItemsContainer.innerHTML += `
|
202 |
+
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
203 |
+
<h3>${item.name}</h3>
|
204 |
+
<p>Quantity: ${item.quantity}</p>
|
205 |
+
<p>Extras: ${extrasList || 'None'}</p>
|
206 |
+
<p>Special Instructions: ${item.instructions || 'None'}</p>
|
207 |
+
<p>Total Cost: $${item.totalCost.toFixed(2)}</p>
|
208 |
+
<button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
|
209 |
+
</div>
|
210 |
+
`;
|
211 |
+
});
|
212 |
+
cartModal.style.display = 'block';
|
213 |
+
}
|
214 |
+
|
215 |
+
function closeCartModal() {
|
216 |
+
document.getElementById('cart-modal').style.display = 'none';
|
217 |
}
|
218 |
|
219 |
function removeFromCart(index) {
|
|
|
220 |
cart.splice(index, 1);
|
221 |
updateCartButton();
|
222 |
+
openCartModal();
|
223 |
}
|
224 |
|
225 |
function proceedToCheckout() {
|
|
|
256 |
with gr.Column():
|
257 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
258 |
menu_output = gr.HTML()
|
259 |
+
gr.HTML("""
|
260 |
+
<div id='cart-button' style='position: fixed; bottom: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>
|
261 |
+
View Cart
|
262 |
+
</div>
|
263 |
+
""")
|
264 |
+
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;'>×</button></div><h1>Your Cart</h1><div id='cart-items'></div><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button></div></div>")
|
265 |
gr.HTML(create_modal_window())
|
266 |
gr.HTML(modal_js())
|
267 |
|