-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.html
More file actions
395 lines (344 loc) · 12.2 KB
/
search.html
File metadata and controls
395 lines (344 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Falasطيني - Search</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<style>
body {
background-color: #e68e0c;
background-image: url("/static/bg.png");
background-repeat: repeat;
background-size: 100px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding-top: 100px;
}
header {
position: fixed;
top: 0;
width: 100%;
background-color: #fff;
padding: 15px 5%;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 999;
padding: 15px 2% 15px 10px;
}
.logo {
font-size: 24px;
font-weight: bold;
color: #2c3e50;
text-decoration: none;
}
.logo span {
color: #e74c3c;
}
.nav-links {
display: flex;
gap: 25px;
align-items: center;
}
.nav-link {
color: #2c3e50;
text-decoration: none;
font-weight: 500;
}
.categories-btn {
cursor: pointer;
display: flex;
align-items: center;
}
.dropdown-menu {
position: absolute;
top: 60px;
right: 5%;
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
width: 200px;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease-out;
}
.dropdown-menu.active {
max-height: 300px;
overflow-y: auto; /* Add this so dropdown can scroll if content overflows */
}
.menu-item a {
display: block;
padding: 10px 15px;
text-decoration: none;
color: #2c3e50;
border-bottom: 1px solid #f0f0f0;
}
.menu-item a:hover {
background-color: #f0f0f0;
color: #e74c3c;
}
.container {
max-width: 800px;
margin: auto;
padding: 20px;
}
.search-bar {
display: flex;
width: 100%;
}
.search-bar input {
flex: 1;
padding: 12px;
border-radius: 25px 0 0 25px;
border: 2px solid #ccc;
font-size: 16px;
}
.search-bar button {
padding: 0 20px;
background: #e74c3c;
color: white;
border: none;
border-radius: 0 25px 25px 0;
font-size: 18px;
cursor: pointer;
}
#searchResults {
margin-top: 30px;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.suggestions-box {
margin-top: 50px;
background: white;
padding: 20px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.suggestions-box h2 {
margin-bottom: 15px;
color: #e74c3c;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group select,
.form-group input,
.form-group textarea {
width: 100%;
padding: 10px;
border-radius: 8px;
border: 1px solid #ccc;
font-size: 14px;
}
#newProductField {
display: none;
}
.submit-btn {
margin-top: 15px;
background-color: #e74c3c;
color: white;
border: none;
padding: 12px 25px;
border-radius: 25px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<a href="/" class="logo">Falas<span>طيني</span></a>
<nav class="nav-links">
<a href="/search" class="nav-link">Search</a>
<a href="/" class="nav-link">About</a>
<div class="categories-btn" id="categoriesBtn">
Categories <i class="fas fa-chevron-down"></i>
</div>
</nav>
<div class="dropdown-menu" id="dropdownMenu">
<div class="menu-item"><a href="/category/babycare">Babycare</a></div>
<div class="menu-item"><a href="/category/biscuits">Biscuits</a></div>
<div class="menu-item"><a href="/category/restaurants">Restaurants</a></div>
<div class="menu-item"><a href="/category/bodycare">Body Care</a></div>
<div class="menu-item"><a href="/category/Cereals">Cereals</a></div>
<div class="menu-item"><a href="/category/colddrinks">Cold Drinks</a></div>
<div class="menu-item"><a href="/category/Cosmetics">Cosmetics</a></div>
<div class="menu-item"><a href="/category/dairy">Dairy</a></div>
<div class="menu-item"><a href="/category/detergents">Detergents</a></div>
<div class="menu-item"><a href="/category/flavoureddrinks">Flavoured Drinks</a></div>
<div class="menu-item"><a href="/category/icecream">Ice Cream</a></div>
<div class="menu-item"><a href="/category/icedtea">Iced Tea</a></div>
<div class="menu-item"><a href="/category/juices">Juices</a></div>
<div class="menu-item"><a href="/category/sanitarynapkins">Sanitary Napkins</a></div>
<div class="menu-item"><a href="/category/shampoos">Shampoos</a></div>
<div class="menu-item"><a href="/category/snacks">Snacks</a></div>
<div class="menu-item"><a href="/category/toothpaste">Toothpaste</a></div>
<div class="menu-item"><a href="/category/water">Water</a></div>
</div>
</header>
<div class="container">
<div class="search-bar">
<input type="text" id="searchInput" placeholder="Search for boycott products..." />
<button id="searchButton"><i class="fas fa-search"></i></button>
</div>
<div id="searchResults">Search results will appear here...</div>
<div class="suggestions-box">
<h2>Submit a Suggestion</h2>
<div class="form-group">
<label for="action">Action:</label>
<select id="action" onchange="toggleNewProductField()">
<option value="delete">Delete Product</option>
<option value="update">Update Product</option>
</select>
</div>
<div class="form-group">
<label for="productSelect">Select Product:</label>
<select id="productSelect"><option value="">-- Select --</option></select>
</div>
<div class="form-group">
<label for="categorySelect">Select Category:</label>
<select id="categorySelect"><option value="">-- Select --</option></select>
</div>
<div class="form-group">
<label for="brandSelect">Select Brand:</label>
<select id="brandSelect"><option value="">-- Select --</option></select>
</div>
<div class="form-group" id="newProductField">
<label for="newProductName">Suggested New Product Name:</label>
<input type="text" id="newProductName" placeholder="e.g. Organic Lotion X" />
</div>
<div class="form-group">
<label for="reason">Reason:</label>
<textarea id="reason" rows="3" placeholder="Enter reason..."></textarea>
</div>
<button class="submit-btn" onclick="submitSuggestion()">Submit Suggestion</button>
</div>
</div>
<script>
const categoriesBtn = document.getElementById("categoriesBtn"); /document is a built-in object that represents the HTML page/
const dropdownMenu = document.getElementById("dropdownMenu"); /grabs the element with id="dropdownMenu" from your HTML and stores it in a variable./
categoriesBtn.addEventListener("click", function (e) {
e.stopPropagation();
dropdownMenu.classList.toggle("active"); /adds or removes the active class defined in css as dropdown/
});
/to click anywhere/
document.addEventListener("click", function () { /
dropdownMenu.classList.remove("active");
});
const searchButton = document.getElementById("searchButton");
const searchInput = document.getElementById("searchInput");
const searchResults = document.getElementById("searchResults");
searchButton.addEventListener("click", () => {
const query = searchInput.value.trim(); /gets text typed in input box/
if (!query) return;
fetch(`/api/products?name=${encodeURIComponent(query)}`)
.then(res => res.json())
.then(products => { /holds the list of results returned by Flask/
searchResults.innerHTML = '';
if (products.length === 0) {
searchResults.textContent = 'No products found.';
} else {
products.forEach(p => {
const div = document.createElement("div");
div.textContent = `${p.product_name} (${p.brand_name}) - ${p.category_name} [${p.affiliation_status}]`;
searchResults.appendChild(div);
});
}
})
.catch(err => {
console.error('Search error:', err);
searchResults.textContent = 'Error loading results.';
});
});
function toggleNewProductField() {
const action = document.getElementById("action").value;
document.getElementById("newProductField").style.display = action === "update" ? "block" : "none";
}
function submitSuggestion() {
const action = document.getElementById("action").value;
const product = document.getElementById("productSelect").value;
const category = document.getElementById("categorySelect").value;
const brand = document.getElementById("brandSelect").value;
const reason = document.getElementById("reason").value;
const newProductName = document.getElementById("newProductName").value;
/Reads all the form input values using getElementById(...).value./
fetch("/api/suggestions", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
suggestion_type: action,
target_product_name: product,
target_category_name: category,
target_brand_name: brand,
reason: reason,
suggested_product_name: newProductName
})
})
.then(response => response.json())
.then(data => {
alert("Suggestion submitted successfully!");
console.log(data);
// Optionally reset form fields here
})
.catch(error => {
console.error("Error submitting suggestion:", error);
alert("Failed to submit suggestion.");
});
}
function populateDropdown(url, dropdownId) {
fetch(url)
.then(res => res.json())
.then(data => {
const dropdown = document.getElementById(dropdownId);
data.forEach(item => {
const opt = document.createElement("option");
opt.value = item;
opt.textContent = item;
dropdown.appendChild(opt);
});
});
}
populateDropdown("/api/products/list", "productSelect");
populateDropdown("/api/categories", "categorySelect");
populateDropdown("/api/brands", "brandSelect");
document.getElementById("productSelect").addEventListener("change", function() {
const selectedProduct = this.value;
if (!selectedProduct) {
// Clear brand and category selects if no product selected
document.getElementById("brandSelect").value = "";
document.getElementById("categorySelect").value = "";
return;
}
fetch(`/api/product/details?product_name=${encodeURIComponent(selectedProduct)}`)
.then(res => res.json())
.then(data => {
if (data.error) {
console.warn("Product details not found");
document.getElementById("brandSelect").value = "";
document.getElementById("categorySelect").value = "";
} else {
// Set the brand and category selects to the fetched values
document.getElementById("brandSelect").value = data.brand_name || "";
document.getElementById("categorySelect").value = data.category_name || "";
}
})
.catch(err => {
console.error("Error fetching product details:", err);
document.getElementById("brandSelect").value = "";
document.getElementById("categorySelect").value = "";
});
});
</script>
</body>
</html>