DSatishchandra commited on
Commit
6cca62e
·
verified ·
1 Parent(s): 38c3cc9

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +244 -15
templates/menu.html CHANGED
@@ -1,23 +1,252 @@
1
  <!DOCTYPE html>
2
- <html>
3
  <head>
 
 
4
  <title>Menu</title>
5
- <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  </head>
7
  <body>
8
- <h1>Biryani Hub - Menu</h1>
9
- <a href="/cart">View Cart</a>
10
- <div class="menu">
11
- {% for item in menu_items %}
12
- <div class="menu-item">
13
- <img src="{{ item.Image1__c }}" alt="Food Image">
14
- <h3>{{ item.Name }}</h3>
15
- <p>{{ item.Description__c }}</p>
16
- <p>${{ item.Price__c }}</p>
17
- <button onclick="addToCart('{{ item.Name }}', {{ item.Price__c }})">Add</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  </div>
19
- {% endfor %}
 
20
  </div>
21
- <script src="{{ url_for('static', filename='js/app.js') }}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  </body>
23
- </html>
 
1
  <!DOCTYPE html>
2
+ <html lang="en">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Menu</title>
7
+ <!-- Bootstrap CSS -->
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ font-family: Arial, sans-serif;
12
+ background-color: #f8f9fa;
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+ .container {
17
+ max-width: 900px;
18
+ }
19
+ .menu-card {
20
+ max-width: 350px;
21
+ border-radius: 15px;
22
+ overflow: hidden;
23
+ background-color: #fff;
24
+ margin: auto;
25
+ }
26
+ .menu-image {
27
+ height: 200px;
28
+ width: 100%;
29
+ object-fit: cover;
30
+ border-radius: 15px 15px 0 0;
31
+ }
32
+ .card-title {
33
+ font-size: 1.2rem;
34
+ font-weight: bold;
35
+ }
36
+ .card-text {
37
+ font-size: 1rem;
38
+ color: #6c757d;
39
+ }
40
+ .btn-primary {
41
+ font-size: 0.9rem;
42
+ border-radius: 20px;
43
+ width: 100px;
44
+ }
45
+ .filter-container {
46
+ margin-bottom: 15px;
47
+ }
48
+ .addons-container {
49
+ max-height: 150px;
50
+ overflow-y: auto;
51
+ border: 1px solid #ddd;
52
+ padding: 10px;
53
+ background-color: #f8f9fa;
54
+ border-radius: 5px;
55
+ }
56
+ .addons-container::-webkit-scrollbar {
57
+ width: 6px;
58
+ }
59
+ .addons-container::-webkit-scrollbar-thumb {
60
+ background-color: #aaa;
61
+ border-radius: 3px;
62
+ }
63
+ .addons-container::-webkit-scrollbar-track {
64
+ background-color: #f1f1f1;
65
+ }
66
+ .view-cart-container {
67
+ position: fixed;
68
+ bottom: 20px;
69
+ right: 20px;
70
+ z-index: 999;
71
+ }
72
+ .view-cart-button {
73
+ background-color: #007bff;
74
+ color: #fff;
75
+ padding: 10px 20px;
76
+ border-radius: 50px;
77
+ font-size: 1rem;
78
+ font-weight: bold;
79
+ text-decoration: none;
80
+ box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ }
85
+ .view-cart-button:hover {
86
+ background-color: #0056b3;
87
+ text-decoration: none;
88
+ }
89
+ </style>
90
  </head>
91
  <body>
92
+ <div class="container mt-4">
93
+ <h1 class="text-center">Menu</h1>
94
+
95
+ <!-- Filter Section -->
96
+ <form method="get" action="/menu" class="text-center mb-4">
97
+ <label for="category" class="form-label fw-bold">Filter by Category:</label>
98
+ <select id="category" name="category" class="form-select" onchange="this.form.submit()">
99
+ <option value="All" {% if selected_category == 'All' %}selected{% endif %}>All</option>
100
+ {% for category in categories %}
101
+ <option value="{{ category }}" {% if selected_category == category %}selected{% endif %}>
102
+ {{ category }}
103
+ </option>
104
+ {% endfor %}
105
+ </select>
106
+ </form>
107
+
108
+ <!-- Menu Items -->
109
+ <div class="row">
110
+ {% for item in food_items %}
111
+ <div class="col-md-6 mb-4">
112
+ <div class="card menu-card">
113
+ <img src="{{ item.Image1__c }}" class="card-img-top menu-image" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
114
+ <div class="card-body">
115
+ <h5 class="card-title">{{ item.Name }}</h5>
116
+ <p class="card-text">${{ item.Price__c }}</p>
117
+ <p class="card-text"><small class="text-muted">{{ item.Category__c }}</small></p>
118
+ <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModal"
119
+ onclick="showItemDetails('{{ item.Name }}', '{{ item.Price__c }}', '{{ item.Image1__c }}', '{{ item.Description__c }}')">
120
+ Add +
121
+ </button>
122
+ </div>
123
+ </div>
124
  </div>
125
+ {% endfor %}
126
+ </div>
127
  </div>
128
+
129
+ <!-- View Cart Button -->
130
+ <div class="view-cart-container">
131
+ <a href="/cart" class="view-cart-button">
132
+ View Cart
133
+ </a>
134
+ </div>
135
+
136
+ <!-- Modal for Item Details -->
137
+ <div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
138
+ <div class="modal-dialog modal-dialog-centered">
139
+ <div class="modal-content">
140
+ <div class="modal-header">
141
+ <h5 class="modal-title" id="itemModalLabel">Item Details</h5>
142
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
143
+ </div>
144
+ <div class="modal-body">
145
+ <!-- Item Image -->
146
+ <img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
147
+ <!-- Item Name -->
148
+ <h5 id="modal-name" class="fw-bold text-center"></h5>
149
+ <!-- Item Price -->
150
+ <p id="modal-price" class="text-muted text-center"></p>
151
+ <!-- Item Description -->
152
+ <p id="modal-description" class="text-secondary"></p>
153
+ <!-- Add-ons -->
154
+ <div id="modal-addons" class="modal-addons mt-4">
155
+ <h6>Add-ons</h6>
156
+ <div id="addons-list" class="addons-container">Loading add-ons...</div>
157
+ </div>
158
+ </div>
159
+ <div class="modal-footer">
160
+ <button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
161
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
162
+ </div>
163
+ </div>
164
+ </div>
165
+ </div>
166
+
167
+ <!-- JavaScript -->
168
+ <script>
169
+ function showItemDetails(name, price, image, description) {
170
+ // Set modal content dynamically
171
+ document.getElementById('modal-name').innerText = name;
172
+ document.getElementById('modal-price').innerText = `$${price}`;
173
+ document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
174
+ document.getElementById('modal-description').innerText = description || 'No description available.';
175
+ document.getElementById('addons-list').innerHTML = 'Loading add-ons...';
176
+ // Fetch add-ons dynamically based on item Name
177
+ fetch(`/api/addons?item_name=${encodeURIComponent(name)}`)
178
+ .then(response => response.json())
179
+ .then(data => {
180
+ const addonsList = document.getElementById('addons-list');
181
+ addonsList.innerHTML = ''; // Clear previous content
182
+ if (!data.success || !data.addons || data.addons.length === 0) {
183
+ addonsList.innerHTML = 'No add-ons available.';
184
+ return;
185
+ }
186
+ // Populate the add-ons list
187
+ data.addons.forEach(addon => {
188
+ const listItem = document.createElement('div');
189
+ listItem.innerHTML = `
190
+ <input type="checkbox" id="addon-${addon.Id}" value="${addon.Id}" />
191
+ <label for="addon-${addon.Id}">${addon.Name} - $${addon.Price__c}</label>
192
+ `;
193
+ addonsList.appendChild(listItem);
194
+ });
195
+ })
196
+ .catch(err => {
197
+ console.error('Error fetching add-ons:', err);
198
+ document.getElementById('addons-list').innerHTML = 'Unable to fetch add-ons. Please try again later.';
199
+ });
200
+ }
201
+ function addToCartFromModal() {
202
+ const itemName = document.getElementById('modal-name').innerText; // Get item name
203
+ const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', '')); // Get item price
204
+ const itemImage = document.getElementById('modal-img').src; // Get item image
205
+ const selectedAddOns = Array.from(
206
+ document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
207
+ ).map(addon => addon.value); // Collect selected add-ons
208
+
209
+ // Ensure itemName and itemPrice are present
210
+ if (!itemName || !itemPrice) {
211
+ alert('Failed to add item to cart. Please try again.');
212
+ return;
213
+ }
214
+
215
+ // Create the payload to send to the backend
216
+ const cartPayload = {
217
+ itemName: itemName, // Food item name
218
+ itemPrice: itemPrice,
219
+ itemImage: itemImage, // Image URL
220
+ addons: selectedAddOns
221
+ };
222
+
223
+ // Send the payload to the server
224
+ fetch('/cart/add', {
225
+ method: 'POST',
226
+ headers: {
227
+ 'Content-Type': 'application/json',
228
+ },
229
+ body: JSON.stringify(cartPayload)
230
+ })
231
+ .then(response => response.json())
232
+ .then(data => {
233
+ if (data.success) {
234
+ alert('Item added to cart successfully!');
235
+ window.location.href = '/cart'; // Redirect to the cart page
236
+ } else {
237
+ console.error('Error adding item to cart:', data.error);
238
+ alert(data.error || 'Failed to add item to cart.');
239
+ }
240
+ })
241
+ .catch(err => {
242
+ console.error('Error adding item to cart:', err);
243
+ alert('An error occurred while adding the item to the cart.');
244
+ });
245
+ }
246
+
247
+ </script>
248
+
249
+ <!-- Bootstrap JS -->
250
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
251
  </body>
252
+ </html>