nagasurendra commited on
Commit
81a86cf
·
verified ·
1 Parent(s): d1b2656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -12
app.py CHANGED
@@ -33,7 +33,7 @@ def filter_menu(preference):
33
  </div>
34
  <div style=\"flex-shrink: 0; text-align: center;\">
35
  <img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
36
- <button style=\"background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;\" onclick=\"addItemToCart('{item['Dish Name']}', '{item['Price ($)']}', '{item['Description']}')\">Add</button>
37
  </div>
38
  </div>
39
  """
@@ -68,18 +68,36 @@ modal_and_cart_js = """
68
  "Extra Onion & Lemon": 2,
69
  "Extra Fried Onion 4oz": 2
70
  };
71
- function addItemToCart(name, price, description) {
72
- const item = {
73
- name: name,
74
- price: parseFloat(price),
75
- spiceLevel: "Not Selected",
76
- quantity: 1,
77
- instructions: "",
78
- extras: [],
79
- itemTotal: parseFloat(price)
80
- };
81
- cart.push(item);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  updateCartDisplay();
 
83
  }
84
  function updateCartDisplay() {
85
  let totalBill = 0;
@@ -123,6 +141,48 @@ def app():
123
  # Final order display
124
  final_order_output = gr.HTML(value="", elem_id="final-page")
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  # Finalize Order Button
127
  finalize_button = gr.Button("Finalize Order")
128
 
@@ -136,6 +196,7 @@ def app():
136
  gr.Row([selected_preference])
137
  gr.Row(menu_output)
138
  gr.Row(cart_output)
 
139
  gr.Row(finalize_button)
140
  gr.Row(final_order_output)
141
  gr.HTML(modal_and_cart_js)
 
33
  </div>
34
  <div style=\"flex-shrink: 0; text-align: center;\">
35
  <img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
36
+ <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['Price ($)']}', '{item['Description']}')\">Add</button>
37
  </div>
38
  </div>
39
  """
 
68
  "Extra Onion & Lemon": 2,
69
  "Extra Fried Onion 4oz": 2
70
  };
71
+ function openModal(name, price, description) {
72
+ document.getElementById('modal').style.display = 'block';
73
+ document.getElementById('modal-name').innerText = name;
74
+ document.getElementById('modal-price').innerText = price;
75
+ document.getElementById('modal-description').innerText = description;
76
+ document.getElementById('modal-image').src = "";
77
+
78
+ const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
79
+ spiceLevelInputs.forEach(input => input.checked = false);
80
+ const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
81
+ extrasInputs.forEach(input => input.checked = false);
82
+ document.getElementById('quantity').value = 1;
83
+ document.getElementById('special-instructions').value = '';
84
+ }
85
+ function closeModal() {
86
+ document.getElementById('modal').style.display = 'none';
87
+ }
88
+ function addToCart() {
89
+ const name = document.getElementById('modal-name').innerText;
90
+ const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
91
+ const spiceLevel = document.querySelector('input[name="spice-level"]:checked')?.value || "Not Selected";
92
+ const quantity = parseInt(document.getElementById('quantity').value) || 1;
93
+ const instructions = document.getElementById('special-instructions').value;
94
+ const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
95
+ const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);
96
+ const itemTotal = (price + extrasCost) * quantity;
97
+ const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };
98
+ cart.push(cartItem);
99
  updateCartDisplay();
100
+ closeModal();
101
  }
102
  function updateCartDisplay() {
103
  let totalBill = 0;
 
141
  # Final order display
142
  final_order_output = gr.HTML(value="", elem_id="final-page")
143
 
144
+ # Modal window for item customization
145
+ modal_window = gr.HTML("""
146
+ <div id="modal" style="display: none; position: fixed; top: 40%; left: 50%; transform: translate(-50%, -40%); width: 50%; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
147
+ <div style="text-align: right;">
148
+ <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
149
+ </div>
150
+ <img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
151
+ <h2 id="modal-name"></h2>
152
+ <p id="modal-description"></p>
153
+ <p id="modal-price"></p>
154
+ <!-- Spice Levels -->
155
+ <label for="spice-level">Choose a Spice Level (Required):</label>
156
+ <div id="spice-level-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
157
+ <label><input type="radio" name="spice-level" value="American Mild" /> American Mild</label>
158
+ <label><input type="radio" name="spice-level" value="American Medium" /> American Medium</label>
159
+ <label><input type="radio" name="spice-level" value="American Spicy" /> American Spicy</label>
160
+ <label><input type="radio" name="spice-level" value="Indian Mild" /> Indian Mild</label>
161
+ <label><input type="radio" name="spice-level" value="Indian Medium" /> Indian Medium</label>
162
+ <label><input type="radio" name="spice-level" value="Indian Very Spicy" /> Indian Very Spicy</label>
163
+ </div>
164
+ <!-- Biryani Extras -->
165
+ <label for="biryani-extras">Biryani Extras (Optional - Choose as many as you like):</label>
166
+ <div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
167
+ <label><input type="checkbox" name="biryani-extra" value="Extra Raitha 4oz" /> Extra Raitha 4oz + $1.00</label>
168
+ <label><input type="checkbox" name="biryani-extra" value="Extra Raitha 8oz" /> Extra Raitha 8oz + $2.00</label>
169
+ <label><input type="checkbox" name="biryani-extra" value="Extra Salan 4oz" /> Extra Salan 4oz + $1.00</label>
170
+ <label><input type="checkbox" name="biryani-extra" value="Extra Salan 8oz" /> Extra Salan 8oz + $2.00</label>
171
+ <label><input type="checkbox" name="biryani-extra" value="Extra Onion" /> Extra Onion + $1.00</label>
172
+ <label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
173
+ <label><input type="checkbox" name="biryani-extra" value="Extra Fried Onion 4oz" /> Extra Fried Onion 4oz + $2.00</label>
174
+ </div>
175
+ <!-- Quantity and Special Instructions -->
176
+ <label for="quantity">Quantity:</label>
177
+ <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
178
+ <br><br>
179
+ <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
180
+ <br><br>
181
+ <!-- Add to Cart Button -->
182
+ <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
183
+ </div>
184
+ """)
185
+
186
  # Finalize Order Button
187
  finalize_button = gr.Button("Finalize Order")
188
 
 
196
  gr.Row([selected_preference])
197
  gr.Row(menu_output)
198
  gr.Row(cart_output)
199
+ gr.Row(modal_window)
200
  gr.Row(finalize_button)
201
  gr.Row(final_order_output)
202
  gr.HTML(modal_and_cart_js)