forked from nighthawkcoders/teacher_portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe.html
243 lines (227 loc) · 8.75 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
---
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-size: cover;
background-repeat: no-repeat;
background-position: top;
text-align: center;
}
#diary-title-container {
background-color: rgb(192, 175, 132);
background-size: cover;
background-repeat: no-repeat;
background-position: top;
color: black; /* Black text */
padding: 50px 20px;
text-align: center;
}
#diary {
width: 70%; /* Adjust width as needed */
margin: 0 auto; /* Center the textarea */
padding: 10px;
border: 1px solid #c29191;
border-radius: 8px;
text-align: center;
}
/* Center text inside diary-container */
.diary-container {
text-align: center;
}
/* Style the data container */
.data-container {
background-color: white;
border: 2px solid #ccc; /* Border style */
padding: 20px; /* Padding inside the container */
margin: 20px auto; /* Center the container */
max-width: 600px; /* Maximum width of the container */
text-align:center;
}
.recipe-buttons {
padding: 10px 20px; /* Padding around the button text */
background-color: #bdc8d4; /* Button background color */
color: rgb(0, 0, 0); /* Button text color */
border: none; /* Remove button border */
border-radius: 5px; /* Rounded corners */
width: 700px;
margin: 0 auto;
cursor: pointer; /* Show pointer cursor on hover */
transition: background-color 0.3s ease; /* Smooth transition for background color */
}
/* Hover effect for the button */
.recipe-buttons:hover {
background-color: #0056b3; /* Darker background color on hover */
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
input {
margin: 6px;
background-color: #ffffff;
padding: 5px;
text-align: center;
border: 2px solid rgb(65, 101, 117);
}
h2 {
color: white;
}
form {
margin: 15px;
}
</style>
</head>
<body class='sandiego-background'>
<!-- Home button linking to index.html -->
<a id="homeButton" href="index" style="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;">Home</a>
<div id='diary-title-container'>
<h1 class='title'>Personal Recipes</h1>
</div>
<br>
<br>
<div class="recipe-container">
<h2 id="subtitle">Recipe:</h2>
<form id="recipeForm" class="form-control">
<div>
<label for="journalname">Mood:</label>
<input type="text" id="journalname" name="journalname" required>
</div>
<div>
<label for="prompt">What are you writing about?</label>
<input type="text" id="prompt" name="prompt" required>
</div>
<div id="stepsContainer">
<label for="entry">Type here:</label>
<div id="stepInputs">
<div>
<input type="text" class="entry" name="entry" required>
</div>
</div>
<button type="button" onclick="addStep()">Add Step</button>
</div>
<div>
<label for="selfcare">Self-care</label>
<input type="text" id="selfcare" name="selfcare" required>
</div>
</form>
<button class="recipe-buttons" onclick="recipe()">New Entry</button>
<br>
<br>
<button class="recipe-buttons" onclick="fetchRecipe()">Load Personal Recipes</button>
<p id="error"></p>
<div class="data-container">
<h3 id='subtitle'>Your Recipes:</h2>
<div id="data"></div>
</div>
</div>
<script>
function addStep() {
const stepsContainer = document.getElementById("stepInputs");
const newStepInput = document.createElement("div");
newStepInput.innerHTML = `<input type="text" class="entry" name="entry" required>`;
stepsContainer.appendChild(newStepInput);
}
function recipe() {
let journalname = document.getElementById("journalname").value;
let prompt = document.getElementById("prompt").value;
let entry = Array.from(document.querySelectorAll('.entry')).map((input, index) => `${index + 1}. ${input.value}`).join('<br>');
let selfcare = document.getElementById("selfcare").value;
let data = {
"journalname": journalname,
"prompt": prompt,
"entry": entry,
"selfcare": selfcare,
};
fetch('http://127.0.0.1:8086/api/recipes/make', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => {
if (response.ok) {
document.getElementById("error").innerHTML = "Journal updated!";
fetchJournal();
} else {
return response.json().then(errorData => {
if (errorData && errorData.message) {
document.getElementById("error").innerHTML = errorData.message;
} else {
document.getElementById("error").innerHTML = "Error submitting journal";
}
});
}
})
.catch(error => {
console.error("Error:", error);
document.getElementById("error").innerHTML = "Error submitting journal";
});
}
function fetchJournal() {
let options = {
method: 'GET',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
};
fetch("http://127.0.0.1:8086/api/recipes/read", options)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Network response was not ok.');
}
})
.then(response => {
let table = document.createElement("table");
let headerRow = table.insertRow();
let headers = ["Journal Name", "Prompt", "Entry", "Self Care"];
headers.forEach(headerText => {
let header = document.createElement("th");
let textNode = document.createTextNode(headerText);
header.appendChild(textNode);
headerRow.appendChild(header);
});
let dataContainer = document.getElementById("data");
dataContainer.innerHTML = "";
response.forEach(item => {
let row = table.insertRow();
let rowData = [item.journalname, item.prompt, item.entry.split('<br>').map(step => `<li>${step}</li>`).join(''), item.selfcare];
rowData.forEach(cellData => {
let cell = row.insertCell();
let textNode = document.createElement('ul');
textNode.innerHTML = cellData;
cell.appendChild(textNode);
});
});
dataContainer.appendChild(table);
})
.catch(error => {
console.error('Error fetching data:', error);
document.getElementById("error").innerHTML = "Error fetching journal";
});
}
</script>
</body>
</html>