-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.html
More file actions
383 lines (339 loc) · 16.9 KB
/
client.html
File metadata and controls
383 lines (339 loc) · 16.9 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
<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recipe Hub | Premium Collection</title>
<style>
:root {
--brand-black: #1a1a1a;
--brand-gold: #c6a667;
--brand-light-gold: #dfc18d;
--brand-cream: #f9f7f2;
--brand-white: #ffffff;
--brand-gray: #f2f2f2;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Assistant', 'Segoe UI', sans-serif;
background-color: var(--brand-cream);
color: var(--brand-black);
line-height: 1.6;
}
header {
background-color: var(--brand-black);
color: var(--brand-white);
padding: 1.5rem;
text-align: center;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
position: sticky;
top: 0;
z-index: 100;
border-bottom: 3px solid var(--brand-gold);
}
header h1 {
font-size: 2.2rem;
letter-spacing: 2px;
font-weight: 800;
color: var(--brand-gold);
text-transform: uppercase;
}
nav { margin-top: 1.5rem; display: flex; gap: 1rem; justify-content: center; }
nav button {
background: transparent;
color: var(--brand-gold);
border: 1.5px solid var(--brand-gold);
padding: 0.7rem 1.8rem;
border-radius: 50px;
cursor: pointer;
font-weight: 600;
transition: all 0.3s ease;
text-transform: uppercase;
font-size: 0.9rem;
}
nav button:hover {
background: var(--brand-gold);
color: var(--brand-black);
}
.container { max-width: 1100px; margin: 3rem auto; padding: 0 1.5rem; }
.recipes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2.5rem; }
.recipe-card {
background: var(--brand-white);
border-radius: 15px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
transition: transform 0.4s ease;
border: 1px solid rgba(198, 166, 103, 0.2);
cursor: pointer;
}
.recipe-card:hover { transform: translateY(-10px); }
.recipe-card img { width: 100%; height: 250px; object-fit: cover; filter: brightness(0.95); }
.recipe-card-content { padding: 1.5rem; text-align: center; }
.recipe-card h3 { color: var(--brand-black); font-size: 1.4rem; margin-bottom: 0.5rem; font-weight: 700; }
.recipe-card p { color: var(--brand-gold); font-weight: 600; }
.recipe-detail {
background: var(--brand-white);
border-radius: 20px;
padding: 3rem;
box-shadow: 0 20px 50px rgba(0,0,0,0.1);
max-width: 850px;
margin: 0 auto;
border: 1px solid var(--brand-gray);
}
.recipe-detail img {
width: 100%;
max-height: 450px;
object-fit: cover;
border-radius: 12px;
margin-bottom: 2rem;
border: 2px solid var(--brand-gold);
}
.recipe-detail h2 { color: var(--brand-black); font-size: 2.5rem; border-bottom: 2px solid var(--brand-gold); display: inline-block; margin-bottom: 1.5rem; }
.ingredients-list { list-style: none; padding: 0; margin-top: 1rem; }
.ingredients-list li {
padding: 8px 0;
border-bottom: 1px solid var(--brand-gray);
display: flex;
align-items: center;
}
.ingredients-list li::before { content: "•"; color: var(--brand-gold); font-weight: bold; margin-left: 10px; }
.ai-chat-box {
background: var(--brand-black);
color: var(--brand-white);
border-radius: 20px;
padding: 2rem;
margin-top: 3rem;
}
.chat-messages {
height: 250px;
background: #2a2a2a;
border-radius: 12px;
padding: 1.5rem;
margin-bottom: 1.5rem;
border: 1px solid var(--brand-gold);
overflow-y: auto;
}
.user-msg { background: var(--brand-gold); color: var(--brand-black); font-weight: 600; padding: 10px; border-radius: 10px; margin-bottom: 10px; align-self: flex-start; }
.ai-msg { background: #3d3d3d; color: var(--brand-white); border: 1px solid rgba(198, 166, 103, 0.3); padding: 10px; border-radius: 10px; margin-bottom: 10px; }
.chat-input-area { display: flex; gap: 10px; }
.chat-input-area input {
flex: 1;
background: #2a2a2a;
border: 1px solid var(--brand-gold);
color: var(--brand-white);
padding: 12px 20px;
border-radius: 50px;
outline: none;
}
.admin-section {
background: var(--brand-white);
border-radius: 20px;
padding: 2.5rem;
box-shadow: 0 10px 40px rgba(0,0,0,0.05);
margin-bottom: 2.5rem;
}
.form-group { margin-bottom: 1.5rem; text-align: right; }
.form-group label { display: block; color: var(--brand-gold); text-transform: uppercase; font-size: 0.85rem; letter-spacing: 1px; font-weight: bold; margin-bottom: 5px; }
.form-group input, .form-group textarea, .form-group select {
width: 100%; border: 1px solid var(--brand-gray);
background: var(--brand-cream);
border-radius: 8px;
padding: 14px;
font-family: inherit;
}
.btn-primary {
padding: 12px 30px;
border-radius: 50px;
cursor: pointer;
font-weight: bold;
background: var(--brand-black);
color: var(--brand-gold);
border: 2px solid var(--brand-gold);
text-transform: uppercase;
letter-spacing: 1px;
transition: 0.3s;
}
.btn-primary:hover { background: var(--brand-gold); color: var(--brand-black); }
.hidden { display: none; }
</style>
</head>
<body>
<header>
<h1>Recipe Hub</h1>
<nav>
<button onclick="showPage('home')">קולקציית מתכונים</button>
<button onclick="showPage('admin')">מרכז ניהול</button>
</nav>
</header>
<div class="container">
<div id="homePage">
<div class="recipes-grid" id="recipesGrid"></div>
</div>
<div id="recipeDetailPage" class="hidden">
<button class="btn-primary" style="margin-bottom:2rem;" onclick="showPage('home')">חזרה לקולקציה</button>
<div id="recipeDetailContent"></div>
</div>
<div id="adminPage" class="hidden">
<div class="admin-section">
<h2 id="adminFormTitle" style="color:var(--brand-black); margin-bottom:2rem; font-weight:800;">יצירת מתכון חדש</h2>
<form id="recipeForm">
<input type="hidden" id="editingRecipeId">
<div class="form-group"><label>שם היצירה</label><input type="text" id="recipeName" required></div>
<div class="form-group">
<label>קטגוריה</label>
<select id="categoryId"><option value="1">Recipe Hub Dairy</option><option value="2">Meat Collection</option><option value="3">Sweet Endings</option></select>
</div>
<div class="form-group"><label>מרכיבים</label><textarea id="products" rows="3" required placeholder="הפרידו בין מרכיבים בפסיק"></textarea></div>
<div class="form-group"><label>הוראות הכנה</label><textarea id="preparationMethod" rows="4" required></textarea></div>
<div class="form-group"><label>זמן עבודה (דקות)</label><input type="number" id="prepTime" required></div>
<div class="form-group"><label>קישור לתמונה מהאינטרנט</label><input type="text" id="imageUrl" placeholder="https://example.com/image.jpg"></div>
<button type="submit" id="submitBtn" class="btn-primary">אישור ושמירה</button>
<button type="button" id="cancelBtn" class="btn hidden" style="margin-right:10px;" onclick="cancelEdit()">ביטול</button>
</form>
</div>
<div class="admin-section">
<h2 style="color:var(--brand-black); margin-bottom:1.5rem;">ניהול תפריט</h2>
<div id="adminList"></div>
</div>
</div>
</div>
<script>
const API_URL = 'http://127.0.0.1:8000';
function formatIngredients(rawText) {
let cleanText = rawText.replace(/[\[\]"']/g, '');
let ingredients = cleanText.split(/[,|\n]/);
let html = '<ul class="ingredients-list">';
ingredients.forEach(item => {
if(item.trim()) html += `<li>${item.trim()}</li>`;
});
html += '</ul>';
return html;
}
// הוספת תמונה ברירת מחדל למקרה שהשדה ב-DB ריק
const DEFAULT_IMG = 'https://images.unsplash.com/photo-1551024601-bec78aea704b?w=800';
async function loadRecipes() {
try {
const res = await fetch(`${API_URL}/recipes`);
const recipes = await res.json();
const grid = document.getElementById('recipesGrid');
grid.innerHTML = recipes.map(r => `
<div class="recipe-card" onclick="showRecipeDetail(${r.RecipeCode})">
<img src="${r.ImageUrl || DEFAULT_IMG}" onerror="this.src='${DEFAULT_IMG}'">
<div class="recipe-card-content">
<h3>${r.RecipeName}</h3>
<p>${r.PrepTime} MIN PREP</p>
</div>
</div>
`).join('');
} catch(e) { console.error(e); }
}
async function showRecipeDetail(id) {
try {
const res = await fetch(`${API_URL}/recipes/id/${id}`);
const r = await res.json();
document.getElementById('recipeDetailContent').innerHTML = `
<div class="recipe-detail">
<img src="${r.ImageUrl || DEFAULT_IMG}" onerror="this.src='${DEFAULT_IMG}'">
<h2>${r.RecipeName}</h2>
<div style="margin-top:1.5rem;"><h3>✨ מרכיבים:</h3>${formatIngredients(r.Products)}</div>
<div style="margin-top:1.5rem;"><h3>👩🍳 הוראות הכנה:</h3><p>${r.PreparationMethod}</p></div>
<div class="ai-chat-box">
<h3 style="color:var(--brand-gold); margin-bottom:1rem;">🤖 ה-AI של Recipe Hub מחכה לשאלות שלך</h3>
<div class="chat-messages" id="chatMsgs"></div>
<div class="chat-input-area">
<input type="text" id="aiQuery" placeholder="יש לך שאלה על המתכון?"
onkeypress="if(event.key === 'Enter') askAI(${id})">
<button class="btn-primary" id="aiBtn" onclick="askAI(${id})">שאל</button>
</div>
</div>
</div>`;
showPage('detail');
} catch(e) { alert("שגיאה בטעינת הפרטים"); }
}
async function askAI(recipeId) {
const input = document.getElementById('aiQuery');
const chat = document.getElementById('chatMsgs');
const btn = document.getElementById('aiBtn');
const question = input.value.trim();
if(!question) return;
chat.innerHTML += `<div class="user-msg"><b>את/ה:</b> ${question}</div>`;
input.value = "";
const loadingId = "load_" + Date.now();
chat.innerHTML += `<div class="ai-msg" id="${loadingId}"><i>השף שלנו בודק... ⏳</i></div>`;
chat.scrollTop = chat.scrollHeight;
btn.disabled = true;
try {
const res = await fetch(`${API_URL}/recipes/${recipeId}/ask`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({question: question})
});
const data = await res.json();
document.getElementById(loadingId).innerHTML = `<b>Recipe Hub AI:</b> ${data.answer}`;
} catch(e) { document.getElementById(loadingId).innerHTML = "שגיאת תקשורת עם העוזר"; }
btn.disabled = false;
chat.scrollTop = chat.scrollHeight;
}
document.getElementById('recipeForm').addEventListener('submit', async (e) => {
e.preventDefault();
const recipeId = document.getElementById('editingRecipeId').value;
const data = {
RecipeName: document.getElementById('recipeName').value,
CategoryID: parseInt(document.getElementById('categoryId').value),
Products: document.getElementById('products').value,
PreparationMethod: document.getElementById('preparationMethod').value,
PrepTime: parseInt(document.getElementById('prepTime').value),
ImageUrl: document.getElementById('imageUrl').value, // שליחת שדה התמונה
CommentCount: 0, TotalPoints: 0
};
const method = recipeId ? 'PUT' : 'POST';
const url = recipeId ? `${API_URL}/recipes/update/${recipeId}` : `${API_URL}/recipes`;
await fetch(url, { method: method, headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data) });
cancelEdit(); loadRecipes(); showPage('home');
});
async function loadAdminList() {
const res = await fetch(`${API_URL}/recipes`);
const data = await res.json();
document.getElementById('adminList').innerHTML = data.map(r => `
<div class="admin-recipe-item" style="display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid #eee; padding:10px 0;">
<span style="font-weight:700;">${r.RecipeName}</span>
<div>
<button class="btn-primary" style="padding:5px 15px; font-size:12px;" onclick="startEdit(${r.RecipeCode})">Edit</button>
<button class="btn-primary" style="padding:5px 15px; font-size:12px; border-color:red; color:red;" onclick="deleteRecipe(${r.RecipeCode})">Delete</button>
</div>
</div>
`).join('');
}
function startEdit(id) {
fetch(`${API_URL}/recipes/id/${id}`).then(res => res.json()).then(r => {
document.getElementById('editingRecipeId').value = id;
document.getElementById('recipeName').value = r.RecipeName;
document.getElementById('categoryId').value = r.CategoryID;
document.getElementById('products').value = r.Products;
document.getElementById('preparationMethod').value = r.PreparationMethod;
document.getElementById('prepTime').value = r.PrepTime;
document.getElementById('imageUrl').value = r.ImageUrl || ''; // טעינת הקישור לעריכה
document.getElementById('adminFormTitle').innerText = "עריכת יצירה קיימת";
document.getElementById('cancelBtn').classList.remove('hidden');
window.scrollTo({top: 0, behavior: 'smooth'});
});
}
function cancelEdit() {
document.getElementById('recipeForm').reset();
document.getElementById('editingRecipeId').value = "";
document.getElementById('adminFormTitle').innerText = "יצירת מתכון חדש";
document.getElementById('cancelBtn').classList.add('hidden');
}
async function deleteRecipe(id) { if(confirm("למחוק מהתפריט?")) { await fetch(`${API_URL}/recipes/${id}`, {method: 'DELETE'}); loadAdminList(); loadRecipes(); } }
function showPage(p) {
document.getElementById('homePage').classList.add('hidden');
document.getElementById('adminPage').classList.add('hidden');
document.getElementById('recipeDetailPage').classList.add('hidden');
if(p==='home') document.getElementById('homePage').classList.remove('hidden');
if(p==='admin') { document.getElementById('adminPage').classList.remove('hidden'); loadAdminList(); }
if(p==='detail') document.getElementById('recipeDetailPage').classList.remove('hidden');
}
loadRecipes();
</script>
</body>
</html>