generated from nighthawkcoders/Nighthawk-Pages
-
Notifications
You must be signed in to change notification settings - Fork 2
/
recipe.html
598 lines (543 loc) · 23.6 KB
/
recipe.html
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
---
layout: base
title: Personal Recipes
permalink: /recipe
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Personal Recipes</title>
<style>
body {
font-family: "Arial", sans-serif;
margin: 0;
padding: 0;
background-image: url("https://files.catbox.moe/1m85ow.png");
background-size: cover;
background-repeat: no-repeat;
background-position: top;
text-align: center;
color: #333;
}
h1,
h2,
h4 {
font-family: "Georgia", serif;
}
#diary-title-container {
background-color: rgba(192, 175, 132, 0.8);
padding: 50px 20px;
text-align: center;
border-bottom: 3px solid #c29191;
}
#diary-title-container h1 {
margin: 0;
font-size: 3em;
color: #333;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
#diary {
width: 70%;
margin: 20px auto;
padding: 20px;
border: 1px solid #c29191;
border-radius: 10px;
background-color: rgba(255, 255, 255, 0.9);
text-align: left;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
.data-container {
background-color: white;
border: 2px solid #ccc;
padding: 20px;
margin: 20px auto;
max-width: 800px;
text-align: center;
overflow: auto;
height: 350px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
.recipe-buttons {
padding: 15px 30px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 30px;
width: 300px;
margin: 20px auto;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.3s ease;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
select#tagSearch option {
padding: 5px 0; /* Add padding to create space between options */
font-size: 1em;
border: 2px solid black;
}
select#tagSearch {
width: 70%;
padding: 40px;
font-size: 1em;
border: 2px solid #4caf50;
border-radius: 5px;
background-color: white;
color: #333;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
select#tagSearch:hover,
select#tagSearch:focus {
border-color: #45a049;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
select#tagSearch option {
font-size: 1em;
}
.recipe-buttons:hover {
background-color: #45a049;
transform: scale(1.05);
}
.recipe-buttons:focus {
outline: none;
}
.recipe-buttons {
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
width: 300px;
margin: 10px auto;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.3s ease;
}
.recipe-buttons:hover {
background-color: #45a049;
transform: scale(1.05);
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
h4 {
text-align: center !important;
}
th,
td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
word-wrap: break-word;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
#error {
color: rgb(71, 32, 32);
font-size: 24px;
margin-top: 10px;
}
input,
select {
margin: 6px;
padding: 10px;
text-align: center;
border: 2px solid rgb(65, 101, 117);
border-radius: 4px;
width: calc(100% - 24px);
max-width: 500px;
}
label {
display: block;
margin: 10px 0 5px;
text-align: left;
}
h2 {
color: white;
background-color: rgba(0, 0, 0, 0.5);
padding: 10px;
border-radius: 5px;
}
form {
margin: 15px auto;
max-width: 600px;
padding: 20px;
background-color: rgba(255, 255, 255, 0.9);
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
text-align: left;
}
li {
margin-bottom: 5px;
}
#recipeContainer {
display: none;
text-align: center;
}
#hideButton {
display: none;
}
#homeButton {
position: fixed;
top: 20px;
left: 20px;
font-size: 16px;
text-decoration: none;
color: #333;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #f2f2f2;
}
/* Custom checkbox styles */
.tag-checkbox-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: 10px 0;
}
.tag-checkbox {
position: relative;
margin: 5px;
}
.tag-checkbox input[type="checkbox"] {
display: none;
}
.tag-checkbox label {
padding: 10px 15px;
border: 2px solid #4caf50;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease, color 0.3s ease;
}
.tag-checkbox input[type="checkbox"]:checked + label {
background-color: #4caf50;
color: white;
}
</style>
</head>
<body class="sandiego-background">
<a id="homeButton" href="index">Home</a>
<div id="diary-title-container">
<h1 class="title">Personal Recipes</h1>
</div>
<br />
<br />
<h2 id="subtitle">Recipe:</h2>
<form id="recipeForm" class="form-control">
<div>
<label for="recipename">Recipe Name:</label>
<input type="text" id="recipename" name="recipename" required />
</div>
<div>
<label for="healthyingredients">Healthy Ingredients:</label>
<input type="text" id="healthyingredients" name="healthyingredients" required />
</div>
<div id="stepsContainer">
<label for="recipesteps">Steps of Recipe:</label>
<div id="stepInputs">
<div>
<input type="text" class="recipestep" name="recipestep" required />
</div>
</div>
<button type="button" onclick="addStep()">Add Step</button>
</div>
<div>
<label for="difficulty">Difficulty of Recipe:</label>
<input type="text" id="difficulty" name="difficulty" required />
</div>
<div>
<label for="tags">Tags:</label>
<div class="tag-checkbox-container">
<div class="tag-checkbox">
<input type="checkbox" id="tag-vegan" name="tags" value="vegan" />
<label for="tag-vegan">Vegan</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-vegetarian" name="tags" value="vegetarian" />
<label for="tag-vegetarian">Vegetarian</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-meat" name="tags" value="meat" />
<label for="tag-meat">Meat</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-healthy" name="tags" value="healthy" />
<label for="tag-healthy">Healthy</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-quick" name="tags" value="quick" />
<label for="tag-quick">Quick</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-asian" name="tags" value="asian" />
<label for="tag-asian">Asian</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-allergen-friendly" name="tags" value="allergen-friendly" />
<label for="tag-allergen-friendly">Allergen-friendly</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-dairy-free" name="tags" value="dairy-free" />
<label for="tag-dairy-free">Dairy-free</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-lunch" name="tags" value="lunch" />
<label for="tag-lunch">Lunch</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-breakfast" name="tags" value="breakfast" />
<label for="tag-breakfast">Breakfast</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-cost-effective" name="tags" value="cost-effective" />
<label for="tag-cost-effective">Cost-effective</label>
</div>
<div class="tag-checkbox">
<input type="checkbox" id="tag-dairy" name="tags" value="dairy" />
<label for="tag-dairy">Dairy</label>
</div>
</div>
</div>
</form>
<button class="recipe-buttons" onclick="recipe()">New Entry</button>
<p id="error"></p>
<hr />
<button class="recipe-buttons" onclick="fetchRecipe()">Load Personal Recipes</button>
<div class="recipe-container">
<div>
<h4><label for="tagSearch">Search by Tag:</label></h4>
<select id="tagSearch" name="tagSearch" multiple> </select>
<!-- Add a search button -->
<button class="recipe-buttons" onclick="filterRecipes()">Search</button>
</div>
</div>
<div id="recipeContainer">
<div class="data-container">
<h2 id="subtitle">Your Recipes:</h2>
<div id="data"></div>
</div>
</div>
<button id="hideButton" class="recipe-buttons" onclick="hideRecipes()">Hide Personal Recipes</button>
<script>
function addStep() {
const stepsContainer = document.getElementById("stepInputs");
const newStepInput = document.createElement("div");
newStepInput.innerHTML = `<input type="text" class="recipestep" name="recipestep" required>`;
stepsContainer.appendChild(newStepInput);
}
function recipe() {
let recipename = document.getElementById("recipename").value;
let healthyingredients = document.getElementById("healthyingredients").value;
let recipesteps = Array.from(document.querySelectorAll(".recipestep"))
.map((input, index) => `${index + 1}. ${input.value}`)
.join("<br>");
let difficulty = document.getElementById("difficulty").value;
// Collect selected tags and join them into a single string separated by commas
let tags = Array.from(document.querySelectorAll('input[name="tags"]:checked'))
.map((checkbox) => checkbox.value)
.join(","); // Join tags with commas
if (!recipename || !healthyingredients || !recipesteps || !difficulty) {
document.getElementById("error").innerHTML = "Please fill in all fields.";
return;
}
let data = {
recipename: recipename,
healthyingredients: healthyingredients,
recipesteps: recipesteps,
difficulty: difficulty,
tags: tags, // Include tags as a single string separated by commas
};
// Send data to backend
fetch("http://127.0.0.1:8432/api/recipes/make", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => {
if (response.ok) {
document.getElementById("error").innerHTML = "Recipes updated!";
} else {
return response.json().then((errorData) => {
if (errorData && errorData.message) {
document.getElementById("error").innerHTML = errorData.message;
} else {
document.getElementById("error").innerHTML = "Error submitting recipe";
}
});
}
})
.catch((error) => {
console.error("Error:", error);
document.getElementById("error").innerHTML = "Error submitting recipe";
});
}
function fetchRecipe() {
let options = {
method: "GET",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
};
fetch("http://127.0.0.1:8432/api/recipes/read", options)
.then((response) => {
if (response.ok) {
return response.json();
} else {
throw new Error("Network response was not ok.");
}
})
.then((response) => {
let dataContainer = document.getElementById("data");
dataContainer.innerHTML = ""; // Clear previous data
if (response.length > 0) {
document.getElementById("recipeContainer").style.display = "block"; // Show the container if there are recipes
document.getElementById("hideButton").style.display = "block"; // Show the Hide button
let table = document.createElement("table");
let headerRow = table.insertRow();
let headers = ["Recipe Name", "Healthy Ingredients", "Recipe Steps", "Difficulty", "Tags"];
headers.forEach((headerText) => {
let header = document.createElement("th");
header.textContent = headerText;
headerRow.appendChild(header);
});
response.forEach((item) => {
let row = table.insertRow();
let rowData = [
item.recipename,
item.healthyingredients,
item.recipesteps
.split("<br>")
.map((step) => `<li>${step}</li>`)
.join(""),
item.difficulty,
item.tags
.split(",")
.map((tag) => `<span class="tag">${tag}</span>`)
.join(", "), // Convert tags string to list and format them with commas
];
rowData.forEach((cellData) => {
let cell = row.insertCell();
cell.innerHTML = cellData;
});
});
dataContainer.appendChild(table);
} else {
document.getElementById("recipeContainer").style.display = "none"; // Hide the container if there are no recipes
document.getElementById("hideButton").style.display = "none"; // Hide the button if there are no recipes
}
})
.catch((error) => {
console.error("Error fetching data:", error);
document.getElementById("error").innerHTML = "Error fetching recipes";
});
}
function hideRecipes() {
document.getElementById("recipeContainer").style.display = "none"; // Hide the recipe container
document.getElementById("hideButton").style.display = "none"; // Hide the button itself
}
// Function to populate the select element with predefined tags
function populateTags() {
const tagSelect = document.getElementById("tagSearch");
const tagCheckboxes = document.querySelectorAll('input[name="tags"]');
tagCheckboxes.forEach((tagCheckbox) => {
const option = document.createElement("option");
option.value = tagCheckbox.value.toLowerCase();
option.textContent = tagCheckbox.value;
tagSelect.appendChild(option);
});
}
// Call the function to populate the select element
populateTags();
// Function to filter recipes based on the selected tag
// Function to filter recipes based on the selected tags
function filterRecipes() {
let selectedTags = Array.from(document.querySelectorAll("#tagSearch option:checked"))
.map((option) => option.value.toLowerCase()) // Collect selected tags
.join(","); // Join tags with commas
// Send a POST request to the backend with the comma-separated tags string
fetch("http://127.0.0.1:8432/api/recipes/search", {
method: "POST",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
body: JSON.stringify({ tags: selectedTags }), // Send selectedTags as a string
})
.then((response) => {
if (response.ok) {
return response.json();
} else {
throw new Error("Network response was not ok.");
}
})
.then((data) => {
// Populate the table with the fetched recipes
populateRecipeTable(data);
})
.catch((error) => {
console.error("Error fetching data:", error);
document.getElementById("error").innerHTML = "Error fetching recipes";
});
}
// Function to populate the table with fetched recipes
function populateRecipeTable(recipes) {
const dataContainer = document.getElementById("data");
const recipeContainer = document.getElementById("recipeContainer");
if (recipes.length > 0) {
// Create table
let table = document.createElement("table");
let headerRow = table.insertRow();
let headers = ["Recipe Name", "Healthy Ingredients", "Recipe Steps", "Difficulty", "Tags"];
headers.forEach((headerText) => {
let header = document.createElement("th");
header.textContent = headerText;
headerRow.appendChild(header);
});
// Populate table with recipes
recipes.forEach((recipe) => {
let row = table.insertRow();
let rowData = [
recipe.recipename,
recipe.healthyingredients,
recipe.recipesteps
.split("<br>")
.map((step) => `<li>${step}</li>`)
.join(""),
recipe.difficulty,
recipe.tags
.split(",")
.map((tag) => `<span class="tag">${tag}</span>`)
.join(", "), // Convert tags string to list and format them with commas
];
rowData.forEach((cellData) => {
let cell = row.insertCell();
cell.innerHTML = cellData;
});
});
// Replace existing output in recipeContainer
recipeContainer.innerHTML = "";
recipeContainer.appendChild(table);
} else {
// Show error message if no recipes found
document.getElementById("error").innerHTML = "No recipes found for the selected tags.";
recipeContainer.innerHTML = "";
}
}
</script>
</body>
</html>