nagasurendra commited on
Commit
20c55b6
·
verified ·
1 Parent(s): 743245c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -18
app.py CHANGED
@@ -64,6 +64,15 @@ def load_menu_from_salesforce():
64
  except Exception as e:
65
  return []
66
 
 
 
 
 
 
 
 
 
 
67
  # Function to filter menu items
68
  def filter_menu(preference):
69
  menu_data = load_menu_from_salesforce()
@@ -102,13 +111,46 @@ def filter_menu(preference):
102
 
103
  return html_content
104
 
105
- # JavaScript for Modal and Cart Functionality
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  def modal_js():
107
  modal_script = """
108
  <script>
109
  let cart = [];
110
  let totalCartCost = 0;
111
-
112
  function openModal(name, image2, description, price) {
113
  const modal = document.getElementById('modal');
114
  modal.style.display = 'block';
@@ -124,29 +166,24 @@ def modal_js():
124
  document.getElementById('quantity').value = 1;
125
  document.getElementById('special-instructions').value = '';
126
  }
127
-
128
  function closeModal() {
129
  document.getElementById('modal').style.display = 'none';
130
  }
131
-
132
  function addToCart() {
133
  const name = document.getElementById('modal-name').innerText;
134
  const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
135
  const quantity = parseInt(document.getElementById('quantity').value) || 1;
136
  const instructions = document.getElementById('special-instructions').value;
137
- const extrasCost = 0; // For simplicity, no extras are added here
138
- const totalCost = price * quantity + extrasCost;
139
  cart.push({ name, quantity, instructions, totalCost });
140
  totalCartCost += totalCost;
141
  updateCartButton();
142
  closeModal();
143
  }
144
-
145
  function updateCartButton() {
146
  const cartButton = document.getElementById('cart-button');
147
  cartButton.innerText = `View Cart (${cart.length} items)`;
148
  }
149
-
150
  function submitCart() {
151
  if (cart.length === 0) {
152
  alert("Cart is empty. Please add items!");
@@ -193,14 +230,14 @@ with gr.Blocks() as app:
193
  with gr.Column():
194
  preference = gr.Radio(["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
195
  menu_output = gr.HTML()
196
- submit_cart_button = gr.Button("Submit Cart")
197
- cart_summary = gr.HTML(label="Cart Summary")
 
198
 
199
  # Navigation and Functionality
200
  login_button.click(
201
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), filter_menu("All"), "Login successful!")
202
- if login(email, password)[0] == "Login successful!"
203
- else (gr.update(), gr.update(), "Invalid email or password."),
204
  [login_email, login_password],
205
  [login_page, menu_page, menu_output, login_output]
206
  )
@@ -223,10 +260,4 @@ with gr.Blocks() as app:
223
  [login_page, signup_page]
224
  )
225
 
226
- submit_cart_button.click(
227
- lambda: "Order submitted successfully!",
228
- [],
229
- [cart_summary]
230
- )
231
-
232
  app.launch()
 
64
  except Exception as e:
65
  return []
66
 
67
+ # Function to load add-ons data
68
+ def load_add_ons_from_salesforce():
69
+ try:
70
+ query = "SELECT Name, Price__c FROM Add_Ons__c"
71
+ result = sf.query(query)
72
+ return result['records']
73
+ except Exception as e:
74
+ return []
75
+
76
  # Function to filter menu items
77
  def filter_menu(preference):
78
  menu_data = load_menu_from_salesforce()
 
111
 
112
  return html_content
113
 
114
+ # Function to create modal window for cart and add-ons
115
+ def create_modal_window():
116
+ add_ons = load_add_ons_from_salesforce()
117
+ add_ons_html = ""
118
+ for add_on in add_ons:
119
+ add_ons_html += f"""
120
+ <label>
121
+ <input type="checkbox" name="biryani-extra" value="{add_on['Name']}" data-price="{add_on['Price__c']}" />
122
+ {add_on['Name']} + ${add_on['Price__c']}
123
+ </label>
124
+ <br>
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;">&times;</button>
131
+ </div>
132
+ <img id="modal-image" style="width: 100%; height: 300px; border-radius: 8px; margin-bottom: 20px;" />
133
+ <h2 id="modal-name"></h2>
134
+ <p id="modal-description"></p>
135
+ <p id="modal-price"></p>
136
+ <label for="biryani-extras"><strong>Add-ons :</strong></label>
137
+ <div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
138
+ {add_ons_html}
139
+ </div>
140
+ <label for="quantity">Quantity:</label>
141
+ <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
142
+ <textarea id="special-instructions" placeholder="Add your special instructions here..." style="width: 100%; height: 60px;"></textarea>
143
+ <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>
144
+ </div>
145
+ """
146
+ return modal_html
147
+
148
+ # JavaScript for modal and cart functionality
149
  def modal_js():
150
  modal_script = """
151
  <script>
152
  let cart = [];
153
  let totalCartCost = 0;
 
154
  function openModal(name, image2, description, price) {
155
  const modal = document.getElementById('modal');
156
  modal.style.display = 'block';
 
166
  document.getElementById('quantity').value = 1;
167
  document.getElementById('special-instructions').value = '';
168
  }
 
169
  function closeModal() {
170
  document.getElementById('modal').style.display = 'none';
171
  }
 
172
  function addToCart() {
173
  const name = document.getElementById('modal-name').innerText;
174
  const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
175
  const quantity = parseInt(document.getElementById('quantity').value) || 1;
176
  const instructions = document.getElementById('special-instructions').value;
177
+ const totalCost = price * quantity;
 
178
  cart.push({ name, quantity, instructions, totalCost });
179
  totalCartCost += totalCost;
180
  updateCartButton();
181
  closeModal();
182
  }
 
183
  function updateCartButton() {
184
  const cartButton = document.getElementById('cart-button');
185
  cartButton.innerText = `View Cart (${cart.length} items)`;
186
  }
 
187
  function submitCart() {
188
  if (cart.length === 0) {
189
  alert("Cart is empty. Please add items!");
 
230
  with gr.Column():
231
  preference = gr.Radio(["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
232
  menu_output = gr.HTML()
233
+ gr.HTML(create_modal_window())
234
+ gr.HTML(modal_js())
235
+ gr.HTML("<div id='cart-summary'></div>")
236
 
237
  # Navigation and Functionality
238
  login_button.click(
239
  lambda email, password: (gr.update(visible=False), gr.update(visible=True), filter_menu("All"), "Login successful!")
240
+ if login(email, password)[0] == "Login successful!" else (gr.update(), gr.update(), login(email, password)[0]),
 
241
  [login_email, login_password],
242
  [login_page, menu_page, menu_output, login_output]
243
  )
 
260
  [login_page, signup_page]
261
  )
262
 
 
 
 
 
 
 
263
  app.launch()