nagasurendra commited on
Commit
24a5aca
·
verified ·
1 Parent(s): ebe90dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -55
app.py CHANGED
@@ -64,15 +64,6 @@ def load_menu_from_salesforce():
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()
@@ -112,45 +103,30 @@ def filter_menu(preference):
112
 
113
  return html_content
114
 
115
- # Create Modal Window HTML
116
- def create_modal_window():
117
- add_ons = load_add_ons_from_salesforce()
118
- add_ons_html = ""
119
- for add_on in add_ons:
120
- add_ons_html += f"""
121
- <label>
122
- <input type="checkbox" name="biryani-extra" value="{add_on['Name']}" data-price="{add_on['Price__c']}" />
123
- {add_on['Name']} + ${add_on['Price__c']}
124
- </label>
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
149
  def modal_js():
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';
@@ -189,7 +165,7 @@ def modal_js():
189
 
190
  function updateCartButton() {
191
  const cartButton = document.getElementById('cart-button');
192
- cartButton.innerText = `View Cart (${cart.length} items)`;
193
  }
194
 
195
  function openCartModal() {
@@ -242,23 +218,11 @@ with gr.Blocks() as app:
242
  signup_button = gr.Button("Go to Signup")
243
  login_output = gr.Textbox(label="Status")
244
 
245
- with gr.Row(visible=False) as signup_page:
246
- with gr.Column():
247
- signup_name = gr.Textbox(label="Name")
248
- signup_email = gr.Textbox(label="Email")
249
- signup_phone = gr.Textbox(label="Phone")
250
- signup_password = gr.Textbox(label="Password", type="password")
251
- submit_signup = gr.Button("Signup")
252
- login_redirect = gr.Button("Go to Login")
253
- signup_output = gr.Textbox(label="Status")
254
-
255
  with gr.Row(visible=False) as menu_page:
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("<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()'>View Cart</div>")
260
  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;'>&times;</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>")
261
- gr.HTML(create_modal_window())
262
  gr.HTML(modal_js())
263
 
264
  login_button.click(
 
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()
 
103
 
104
  return html_content
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  # JavaScript for Modal and Cart
107
  def modal_js():
108
  modal_script = """
109
  <script>
110
  let cart = [];
111
 
112
+ // Dynamically create and append the sticky cart button
113
+ document.addEventListener("DOMContentLoaded", function () {
114
+ const cartButton = document.createElement("div");
115
+ cartButton.id = "cart-button";
116
+ cartButton.style.position = "fixed";
117
+ cartButton.style.bottom = "20px";
118
+ cartButton.style.right = "20px";
119
+ cartButton.style.background = "#28a745";
120
+ cartButton.style.color = "white";
121
+ cartButton.style.padding = "10px 20px";
122
+ cartButton.style.borderRadius = "30px";
123
+ cartButton.style.cursor = "pointer";
124
+ cartButton.style.zIndex = "1000";
125
+ cartButton.textContent = "View Cart (0 items)";
126
+ cartButton.addEventListener("click", openCartModal);
127
+ document.body.appendChild(cartButton);
128
+ });
129
+
130
  function openModal(name, image2, description, price) {
131
  const modal = document.getElementById('modal');
132
  modal.style.display = 'block';
 
165
 
166
  function updateCartButton() {
167
  const cartButton = document.getElementById('cart-button');
168
+ cartButton.textContent = `View Cart (${cart.length} items)`;
169
  }
170
 
171
  function openCartModal() {
 
218
  signup_button = gr.Button("Go to Signup")
219
  login_output = gr.Textbox(label="Status")
220
 
 
 
 
 
 
 
 
 
 
 
221
  with gr.Row(visible=False) as menu_page:
222
  with gr.Column():
223
  preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
224
  menu_output = gr.HTML()
 
225
  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;'>&times;</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>")
 
226
  gr.HTML(modal_js())
227
 
228
  login_button.click(