Skip to content

Commit

Permalink
new commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eylulozatman committed Jan 17, 2024
1 parent 3bc503c commit 8605084
Show file tree
Hide file tree
Showing 24 changed files with 685 additions and 140 deletions.
2 changes: 1 addition & 1 deletion Icons/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
267 changes: 186 additions & 81 deletions dashboard.js → scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,23 @@ function toggleFavorite(element) {
element.style.cursor = 'pointer';
}

function setRating(rating) {
const stars = document.querySelectorAll('.star');

for (let i = 0; i < stars.length; i++) {
if (i < rating) {
stars[i].innerHTML = '★'; // Seçilen yıldızları yıldız simgesiyle doldur
stars[i].style.color = 'gold'; // Sarı renk yap
} else {
stars[i].innerHTML = '☆'; // Diğer yıldızları boş bırak
stars[i].style.color = 'black'; // Siyah renk yap
}
}

function setRating(rating, starContainer) {
const stars = starContainer.querySelectorAll('.star');

for (let i = 0; i < stars.length; i++) {
if (i < rating) {
stars[i].innerHTML = '★';
stars[i].style.color = 'gold';
} else {
stars[i].innerHTML = '☆';
stars[i].style.color = 'black';
}
}
}

//post (starContainer,rating)



const days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
Expand Down Expand Up @@ -203,75 +206,76 @@ function toggleFavorite(element) {



const fetchData = async () => {
try {
const response = await fetch('https://recipiebeckend.azurewebsites.net/recipes/all-recipes');
const data = await response.json();

const recipesList = document.getElementById('recipesList');

data.forEach((recipe, index) => {
// Create a new column for each recipe
const recipeDiv = document.createElement('div');
recipeDiv.classList.add('recipe-item');

const link = document.createElement('a');
link.href = 'your_new_page_url.html';

// Image
const imgDiv = document.createElement('div');
imgDiv.classList.add('imgDiv');
const img = document.createElement('img');
img.src = recipe.photoPath;
img.alt = 'Recipe Photo';

// Apply CSS to constrain image size
img.style.maxWidth = '100%'; // Adjust this value as needed
img.style.height = '100%'; // Maintain aspect ratio

link.appendChild(img);
imgDiv.appendChild(link);

// Create stars
const starContainer = document.createElement('div');
starContainer.classList.add('rating');
for (let i = 1; i <= 5; i++) {
const star = document.createElement('span');
star.classList.add('star');
star.textContent = '☆';
star.onmouseover = () => hoverStar(star);
star.onclick = () => setRating(i);
starContainer.appendChild(star);
}

// Create heart
const heart = document.createElement('span');
heart.classList.add('favorite-heart');
heart.src = 'Gifs/heart.gif'; // Replace with the actual path to your animated GIF
heart.alt = 'Animated Heart';
heart.onclick = () => toggleFavorite(heart);
// heart.textContent = '♥';
// heart.onclick = () => toggleFavorite(heart);

// Title
const titleDiv = document.createElement('div');
titleDiv.classList.add('titleDiv');
titleDiv.textContent = recipe.title;

// Append stars and heart to the recipeDiv
recipeDiv.appendChild(imgDiv);
recipeDiv.appendChild(titleDiv);
recipeDiv.appendChild(starContainer);
recipeDiv.appendChild(heart);
recipesList.appendChild(recipeDiv);
});
} catch (error) {
console.error('Error fetching or displaying data:', error);
}
};

// fetchData fonksiyonunu çağırarak dataları al ve içeriği doldur
fetchData();
// const fetchData = async () => {
// try {
// // const response = await fetch('https://recipiebeckend.azurewebsites.net/recipes/all-recipes');
// const data = await response.json();

// const recipesList = document.getElementById('recipesList');

// data.forEach((recipe, index) => {
// // Create a new column for each recipe
// const recipeDiv = document.createElement('div');
// recipeDiv.classList.add('recipe-item');

// const link = document.createElement('a');
// link.href = 'your_new_page_url.html';

// // Image
// const imgDiv = document.createElement('div');
// imgDiv.classList.add('imgDiv');
// const img = document.createElement('img');
// img.src = recipe.photoPath;
// img.alt = 'Recipe Photo';

// // Apply CSS to constrain image size
// img.style.maxWidth = '100%'; // Adjust this value as needed
// img.style.height = '100%'; // Maintain aspect ratio

// link.appendChild(img);
// imgDiv.appendChild(link);

// // Create stars
// const starContainer = document.createElement('div');
// starContainer.classList.add('rating');
// for (let i = 1; i <= 5; i++) {
// const star = document.createElement('span');
// star.classList.add('star');
// star.textContent = '☆';
// star.onmouseover = () => hoverStar(star);
// star.onclick = () => setRating(i,starContainer);
// starContainer.appendChild(star);
// }
// recipeDiv.appendChild(starContainer);

// // Create heart
// const heart = document.createElement('span');
// heart.classList.add('favorite-heart');
// heart.src = 'Gifs/heart.gif'; // Replace with the actual path to your animated GIF
// heart.alt = 'Animated Heart';
// heart.onclick = () => toggleFavorite(heart);
// // heart.textContent = '♥';
// // heart.onclick = () => toggleFavorite(heart);

// // Title
// const titleDiv = document.createElement('div');
// titleDiv.classList.add('titleDiv');
// titleDiv.textContent = recipe.title;

// // Append stars and heart to the recipeDiv
// recipeDiv.appendChild(imgDiv);
// recipeDiv.appendChild(titleDiv);
// recipeDiv.appendChild(starContainer);
// recipeDiv.appendChild(heart);
// recipesList.appendChild(recipeDiv);
// });
// } catch (error) {
// console.error('Error fetching or displaying data:', error);
// }
// };

// // fetchData fonksiyonunu çağırarak dataları al ve içeriği doldur
// fetchData();


//Call jQuery before below code
Expand Down Expand Up @@ -325,6 +329,107 @@ function toggleFavorite(element) {
}


// Function to create a recipe element based on the provided recipe data
const createRecipeElement = (recipe) => {
// Create a new column for each recipe
const recipeDiv = document.createElement('div');
recipeDiv.classList.add('recipe-item');

const link = document.createElement('a');
link.href = 'your_new_page_url.html';

// Image
const imgDiv = document.createElement('div');
imgDiv.classList.add('imgDiv');
const img = document.createElement('img');
img.src = recipe.photoPath;
img.alt = 'Recipe Photo';

// Apply CSS to constrain image size
img.style.maxWidth = '100%'; // Adjust this value as needed
img.style.height = '100%'; // Maintain aspect ratio

link.appendChild(img);
imgDiv.appendChild(link);

// Create stars
const starContainer = document.createElement('div');
starContainer.classList.add('rating');
for (let i = 1; i <= 5; i++) {
const star = document.createElement('span');
star.classList.add('star');
star.textContent = '☆';
star.onmouseover = () => hoverStar(star);
star.onclick = () => setRating(i, starContainer);
starContainer.appendChild(star);
}
recipeDiv.appendChild(starContainer);

// Create heart
const heart = document.createElement('span');
heart.classList.add('favorite-heart');
heart.src = 'Gifs/heart.gif'; // Replace with the actual path to your animated GIF
heart.alt = 'Animated Heart';
heart.onclick = () => toggleFavorite(heart);
heart.textContent = '♥';
heart.onclick = () => toggleFavorite(heart);

// Title
const titleDiv = document.createElement('div');
titleDiv.classList.add('titleDiv');
titleDiv.textContent = recipe.title;

// Append stars and heart to the recipeDiv
recipeDiv.appendChild(imgDiv);
recipeDiv.appendChild(titleDiv);
recipeDiv.appendChild(starContainer);
recipeDiv.appendChild(heart);

return recipeDiv;
};

// Function to display recipes in the dashboard
const displayDashboard = (recipes) => {
const recipesList = document.getElementById('recipesList');

// Clear the existing content before adding new recipes
recipesList.innerHTML = '';

recipes.forEach((recipe, index) => {
const recipeElement = createRecipeElement(recipe);
recipesList.appendChild(recipeElement);
});
};

// Function to fetch data from the API
const fetchData = async () => {
try {
const response = await fetch('https://recipiebeckend.azurewebsites.net/recipes/all-recipes');
const data = await response.json();

// Call displayDashboard to render the fetched data
displayDashboard(data);
} catch (error) {
console.error('Error fetching or displaying data:', error);
}
};

// Call fetchData to initiate the process
fetchData();

const fetchDataByMealType = async (mealType) => {
try {
// Modify the endpoint based on the mealType parameter
const apiUrl = `https://recipiebeckend.azurewebsites.net/recipes/getRecipesByMeal?mealType=${mealType}`;

const response = await fetch(apiUrl);
const data = await response.json();

displayDashboard(data);
} catch (error) {
console.error('Error fetching or displaying data:', error);
}
};



Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion logIn.js → scripts/logIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function loginUser() {
};

// Make the POST request to your Java backend
fetch('https://recipiebeckend.azurewebsites.net/auth/login', {
fetch('https://recipiebeckend.azurewebsites.net/auth/login2', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
73 changes: 73 additions & 0 deletions scripts/recipe-book.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Geçici veritabanı
let recipes = [
{
title: "Spaghetti Bolognese",
ingredients: "Pasta, Ground Beef, Tomato Sauce, Onion, Garlic, Olive Oil, Salt, Pepper",
description: "Classic Italian dish with a rich meat sauce."
},
{
title: "Chicken Alfredo",
ingredients: "Fettuccine, Chicken Breast, Heavy Cream, Parmesan Cheese, Butter, Garlic, Salt, Pepper",
description: "Creamy pasta dish with grilled chicken."
},
{
title: "Vegetarian Stir-Fry",
ingredients: "Tofu, Broccoli, Bell Peppers, Carrots, Soy Sauce, Ginger, Garlic, Sesame Oil",
description: "Healthy and flavorful stir-fried vegetables with tofu."
}
];

document.addEventListener("DOMContentLoaded", function () {
const recipeContainer = document.querySelector(".recipe-book-container");

// Show recipes when the page is loaded
showRecipes();

// Add New Recipe sayfasından gelen verileri al ve veritabanına ekle
function addRecipe() {
const title = document.getElementById("recipe-title").value;
const ingredients = document.getElementById("recipe-ingredients").value;
const description = document.getElementById("recipe-description").value;

if (title && ingredients && description) {
// Yeni tarifi veritabanına ekle
recipes.push({
title: title,
ingredients: ingredients,
description: description
});

// Tarif eklendikten sonra tarifleri göster
showRecipes();

// Add New Recipe sayfasını temizle
document.getElementById("recipe-form").reset();
} else {
alert("Please fill in all fields.");
}
}

// Sayfa yüklendiğinde formun submit işlemini dinle
const recipeForm = document.getElementById("recipe-form");
recipeForm.addEventListener("submit", function (event) {
event.preventDefault(); // Sayfanın yeniden yüklenmesini önle
addRecipe(); // Tarifi ekle
});
});

// Function to display recipes in the recipe container
function showRecipes() {
const recipeContainer = document.querySelector(".recipe-book-container");
recipeContainer.innerHTML = "";

recipes.forEach(recipe => {
const recipeItem = document.createElement("div");
recipeItem.classList.add("recipe-item");
recipeItem.innerHTML = `
<h2>${recipe.title}</h2>
<p><strong>Ingredients:</strong> ${recipe.ingredients}</p>
<p><strong>Description:</strong> ${recipe.description}</p>
`;
recipeContainer.appendChild(recipeItem);
});
}
File renamed without changes.
Loading

0 comments on commit 8605084

Please sign in to comment.