nagasurendra commited on
Commit
dd345b4
·
verified ·
1 Parent(s): 536706d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -44
app.py CHANGED
@@ -24,15 +24,15 @@ def filter_menu(preference):
24
  html_content = ""
25
  for _, item in filtered_data.iterrows():
26
  html_content += f"""
27
- <div style=\"display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);\">
28
- <div style=\"flex: 1; margin-right: 15px;\">
29
- <h3 style=\"margin: 0; font-size: 18px;\">{item['Dish Name']}</h3>
30
- <p style=\"margin: 5px 0; font-size: 16px; color: #888;\">${item['Price ($)']}</p>
31
- <p style=\"margin: 5px 0; font-size: 14px; color: #555;\">{item['Description']}</p>
32
  </div>
33
- <div style=\"flex-shrink: 0; text-align: center;\">
34
- <img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
35
- <button style=\"background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;\" onclick=\"openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')\">Add</button>
36
  </div>
37
  </div>
38
  """
@@ -40,6 +40,43 @@ def filter_menu(preference):
40
 
41
  # JavaScript for modal and cart behavior
42
  modal_and_cart_js = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  <script>
44
  let cart = [];
45
  const extrasPrices = {
@@ -62,10 +99,8 @@ modal_and_cart_js = """
62
  modal.style.display = 'block';
63
  modal.style.position = 'fixed';
64
  if (window.innerWidth <= 768) {
65
- // For mobile devices
66
  modal.style.width = '90%';
67
  } else {
68
- // For laptops or larger screens
69
  modal.style.width = '30%';
70
  }
71
  modal.style.top = '15%';
@@ -75,7 +110,6 @@ modal_and_cart_js = """
75
  document.getElementById('modal-name').innerText = name;
76
  document.getElementById('modal-description').innerText = description;
77
  document.getElementById('modal-price').innerText = price;
78
- // Reset extras
79
  const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
80
  extrasInputs.forEach(input => input.checked = false);
81
  document.getElementById('quantity').value = 1;
@@ -107,48 +141,39 @@ modal_and_cart_js = """
107
 
108
  function updateCartDisplay() {
109
  let totalBill = 0;
110
- let cartHTML = "<h3>Your Cart:</h3><ul style='list-style: none; padding: 0;'>";
111
  cart.forEach((item, index) => {
112
  totalBill += item.itemTotal;
113
  const extras = item.extras.map((extra, i) => {
114
  const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
115
  const extraTotal = extrasPrices[extra] * extraQuantity;
116
  totalBill += extraTotal;
117
- return `<li>
118
- <div style='display: flex; justify-content: space-between; align-items: center;'>
119
- <span>${extra}</span>
120
- <span>Price: $${extrasPrices[extra].toFixed(2)}</span>
121
- <div>
122
- <label for='extra-quantity-${index}-${i}'>Quantity:</label>
123
- <input type='number' id='extra-quantity-${index}-${i}' value='${extraQuantity}' min='1' style='width: 50px;' onchange='updateExtraQuantity(${index}, ${i}, this.value)'>
124
- </div>
125
- <span>Total: $${extraTotal.toFixed(2)}</span>
126
- <input type='checkbox' id='extra-remove-${index}-${i}' onclick='removeExtra(${index}, ${i})'> Remove
127
  </div>
128
- </li>`;
 
 
129
  }).join('');
130
 
131
- cartHTML += `<li style='border-bottom: 1px solid #ddd; margin-bottom: 10px;'>
132
- <div style='display: flex; justify-content: space-between; align-items: center;'>
133
- <span>${item.name}</span>
134
- <span>Item Price: $${item.price.toFixed(2)}</span>
135
- <div>
136
- <label for='item-quantity-${index}'>Quantity:</label>
137
- <input type='number' id='item-quantity-${index}' value='${item.quantity}' min='1' style='width: 50px;' onchange='updateItemQuantity(${index}, this.value)'>
138
- </div>
139
- <span>Total: $${(item.price * item.quantity).toFixed(2)}</span>
140
- <input type='checkbox' id='item-remove-${index}' onclick='removeItem(${index})'> Remove
141
  </div>
142
- <div style='margin-left: 20px;'>
143
- <h4>Extras:</h4>
144
- <ul style='list-style: none; padding: 0;'>${extras}</ul>
145
- </div>
146
- <div style='margin-left: 20px;'>
147
- <strong>Instructions:</strong> ${item.instructions || "None"}
148
- </div>
149
- </li>`;
150
  });
151
- cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
152
  cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
153
  document.getElementById('floating-cart').innerHTML = cartHTML;
154
  }
@@ -176,8 +201,8 @@ modal_and_cart_js = """
176
  }
177
 
178
  function removeItem(index) {
179
- cart.splice(index, 1); // Remove the item from the cart array
180
- updateCartDisplay(); // Re-render the cart display
181
  }
182
 
183
  function submitCart() {
 
24
  html_content = ""
25
  for _, item in filtered_data.iterrows():
26
  html_content += f"""
27
+ <div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
28
+ <div style="flex: 1; margin-right: 15px;">
29
+ <h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
30
+ <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
31
+ <p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
32
  </div>
33
+ <div style="flex-shrink: 0; text-align: center;">
34
+ <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
35
+ <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')">Add</button>
36
  </div>
37
  </div>
38
  """
 
40
 
41
  # JavaScript for modal and cart behavior
42
  modal_and_cart_js = """
43
+ <style>
44
+ .cart-container {
45
+ border: 1px solid #ddd;
46
+ border-radius: 8px;
47
+ padding: 15px;
48
+ margin-bottom: 15px;
49
+ background-color: #f9f9f9;
50
+ display: flex;
51
+ flex-direction: column;
52
+ gap: 10px;
53
+ }
54
+ .cart-item {
55
+ display: flex;
56
+ justify-content: space-between;
57
+ align-items: center;
58
+ border-bottom: 1px solid #ddd;
59
+ padding: 10px 0;
60
+ }
61
+ .cart-item:last-child {
62
+ border-bottom: none;
63
+ }
64
+ .cart-item span {
65
+ font-size: 16px;
66
+ margin-right: 10px;
67
+ }
68
+ .cart-item .quantity-container {
69
+ display: flex;
70
+ align-items: center;
71
+ gap: 5px;
72
+ }
73
+ .cart-total {
74
+ font-size: 18px;
75
+ font-weight: bold;
76
+ text-align: right;
77
+ margin-top: 10px;
78
+ }
79
+ </style>
80
  <script>
81
  let cart = [];
82
  const extrasPrices = {
 
99
  modal.style.display = 'block';
100
  modal.style.position = 'fixed';
101
  if (window.innerWidth <= 768) {
 
102
  modal.style.width = '90%';
103
  } else {
 
104
  modal.style.width = '30%';
105
  }
106
  modal.style.top = '15%';
 
110
  document.getElementById('modal-name').innerText = name;
111
  document.getElementById('modal-description').innerText = description;
112
  document.getElementById('modal-price').innerText = price;
 
113
  const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
114
  extrasInputs.forEach(input => input.checked = false);
115
  document.getElementById('quantity').value = 1;
 
141
 
142
  function updateCartDisplay() {
143
  let totalBill = 0;
144
+ let cartHTML = "<div class='cart-container'>";
145
  cart.forEach((item, index) => {
146
  totalBill += item.itemTotal;
147
  const extras = item.extras.map((extra, i) => {
148
  const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
149
  const extraTotal = extrasPrices[extra] * extraQuantity;
150
  totalBill += extraTotal;
151
+ return `<div class='cart-item'>
152
+ <span>${extra}</span>
153
+ <span>Price: $${extrasPrices[extra].toFixed(2)}</span>
154
+ <div class='quantity-container'>
155
+ <label for='extra-quantity-${index}-${i}'>Quantity:</label>
156
+ <input type='number' id='extra-quantity-${index}-${i}' value='${extraQuantity}' min='1' style='width: 50px;' onchange='updateExtraQuantity(${index}, ${i}, this.value)'>
 
 
 
 
157
  </div>
158
+ <span>Total: $${extraTotal.toFixed(2)}</span>
159
+ <input type='checkbox' id='extra-remove-${index}-${i}' onclick='removeExtra(${index}, ${i})'> Remove
160
+ </div>`;
161
  }).join('');
162
 
163
+ cartHTML += `<div class='cart-item'>
164
+ <span>${item.name}</span>
165
+ <span>Item Price: $${item.price.toFixed(2)}</span>
166
+ <div class='quantity-container'>
167
+ <label for='item-quantity-${index}'>Quantity:</label>
168
+ <input type='number' id='item-quantity-${index}' value='${item.quantity}' min='1' style='width: 50px;' onchange='updateItemQuantity(${index}, this.value)'>
 
 
 
 
169
  </div>
170
+ <span>Total: $${(item.price * item.quantity).toFixed(2)}</span>
171
+ <input type='checkbox' id='item-remove-${index}' onclick='removeItem(${index})'> Remove
172
+ </div>
173
+ ${extras}
174
+ <div class='cart-item'><strong>Instructions:</strong> ${item.instructions || "None"}</div>`;
 
 
 
175
  });
176
+ cartHTML += `</div><p class='cart-total'>Total Bill: $${totalBill.toFixed(2)}</p>`;
177
  cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
178
  document.getElementById('floating-cart').innerHTML = cartHTML;
179
  }
 
201
  }
202
 
203
  function removeItem(index) {
204
+ cart.splice(index, 1);
205
+ updateCartDisplay();
206
  }
207
 
208
  function submitCart() {