Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +162 -76
templates/index.html
CHANGED
|
@@ -805,91 +805,177 @@
|
|
| 805 |
});
|
| 806 |
}
|
| 807 |
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
displayMenuItems(menuItems);
|
| 824 |
-
}
|
| 825 |
-
})
|
| 826 |
-
.catch(error => {
|
| 827 |
-
addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
|
| 828 |
-
});
|
| 829 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
-
function displayMenuItems(menuItems) {
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
|
| 851 |
-
|
| 852 |
-
|
| 853 |
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
|
| 887 |
-
|
| 888 |
-
|
| 889 |
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
}
|
| 893 |
|
| 894 |
|
| 895 |
|
|
|
|
| 805 |
});
|
| 806 |
}
|
| 807 |
|
| 808 |
+
function fetchRecipeItems(params) {
|
| 809 |
+
fetch('/get_recipe_items', { // Change endpoint to '/get_recipe_items'
|
| 810 |
+
method: 'POST',
|
| 811 |
+
headers: { 'Content-Type': 'application/json' },
|
| 812 |
+
body: JSON.stringify(params)
|
| 813 |
+
})
|
| 814 |
+
.then(response => response.json())
|
| 815 |
+
.then(data => {
|
| 816 |
+
if (data.error) {
|
| 817 |
+
addMessage('bot', `Sorry, there was an error fetching recipe items: ${data.error}`);
|
| 818 |
+
} else {
|
| 819 |
+
const recipeItems = data.recipe_items || [];
|
| 820 |
+
addMessage('bot', 'Here are some recipes based on your selection:');
|
| 821 |
+
currentStep = 'recipe_display';
|
| 822 |
+
displayRecipeItems(recipeItems);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
}
|
| 824 |
+
})
|
| 825 |
+
.catch(error => {
|
| 826 |
+
addMessage('bot', `Error: Unable to connect to the recipe database. ${error.message}`);
|
| 827 |
+
});
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
function displayRecipeItems(recipeItems) {
|
| 831 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 832 |
+
if (!chatMessages) {
|
| 833 |
+
console.error('Chat messages container not found for recipe items!');
|
| 834 |
+
return;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
// Clear previous recipe items if they exist
|
| 838 |
+
let recipeItemsList = document.querySelector('.recipe-items-list');
|
| 839 |
+
if (!recipeItemsList) {
|
| 840 |
+
recipeItemsList = document.createElement('div');
|
| 841 |
+
recipeItemsList.className = 'recipe-items-list';
|
| 842 |
+
chatMessages.appendChild(recipeItemsList);
|
| 843 |
+
} else {
|
| 844 |
+
// Clear existing items to avoid duplication
|
| 845 |
+
recipeItemsList.innerHTML = '';
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
// Log to verify the recipes being fetched
|
| 849 |
+
console.log('Fetched recipe items:', recipeItems);
|
| 850 |
+
|
| 851 |
+
// If recipeItems is an empty array, add a message indicating no items found
|
| 852 |
+
if (recipeItems.length === 0) {
|
| 853 |
+
const noItemsMessage = document.createElement('div');
|
| 854 |
+
noItemsMessage.textContent = 'No recipes available at the moment.';
|
| 855 |
+
recipeItemsList.appendChild(noItemsMessage);
|
| 856 |
+
} else {
|
| 857 |
+
recipeItems.forEach(item => {
|
| 858 |
+
const recipeItem = document.createElement('div');
|
| 859 |
+
recipeItem.className = 'recipe-item';
|
| 860 |
+
const img = document.createElement('img');
|
| 861 |
+
img.src = item.image_url || 'https://via.placeholder.com/120';
|
| 862 |
+
img.alt = item.name;
|
| 863 |
+
const name = document.createElement('div');
|
| 864 |
+
name.textContent = item.name;
|
| 865 |
+
const button = document.createElement('button');
|
| 866 |
+
button.textContent = 'Add to Cart';
|
| 867 |
+
button.onclick = () => {
|
| 868 |
+
selectedRecipeItem = item;
|
| 869 |
+
addMessage('bot', `Great choice! Would you like to customize your recipe further?`);
|
| 870 |
+
const options = [
|
| 871 |
+
{ text: 'Yes', class: 'green' },
|
| 872 |
+
{ text: 'No', class: 'red' }
|
| 873 |
+
];
|
| 874 |
+
currentStep = 'customization';
|
| 875 |
+
displayOptions(options);
|
| 876 |
+
};
|
| 877 |
+
recipeItem.appendChild(img);
|
| 878 |
+
recipeItem.appendChild(name);
|
| 879 |
+
recipeItem.appendChild(button);
|
| 880 |
+
recipeItemsList.appendChild(recipeItem);
|
| 881 |
+
});
|
| 882 |
+
}
|
| 883 |
+
|
| 884 |
+
// Ensure the display is scrolled to the latest message
|
| 885 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 886 |
+
|
| 887 |
+
// Log that recipe items were displayed
|
| 888 |
+
console.log('Recipe items displayed');
|
| 889 |
+
}
|
| 890 |
+
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
|
| 895 |
+
// function fetchMenuItems(params) {
|
| 896 |
+
// fetch('/get_menu_items', {
|
| 897 |
+
// method: 'POST',
|
| 898 |
+
// headers: { 'Content-Type': 'application/json' },
|
| 899 |
+
// body: JSON.stringify(params)
|
| 900 |
+
// })
|
| 901 |
+
// .then(response => response.json())
|
| 902 |
+
// .then(data => {
|
| 903 |
+
// if (data.error) {
|
| 904 |
+
// addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
|
| 905 |
+
// } else {
|
| 906 |
+
// const menuItems = data.menu_items || [];
|
| 907 |
+
// addMessage('bot', 'Here are some dishes based on your selection:');
|
| 908 |
+
// currentStep = 'menu_display';
|
| 909 |
+
// displayMenuItems(menuItems);
|
| 910 |
+
// }
|
| 911 |
+
// })
|
| 912 |
+
// .catch(error => {
|
| 913 |
+
// addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
|
| 914 |
+
// });
|
| 915 |
+
// }
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
+
// function displayMenuItems(menuItems) {
|
| 920 |
+
// const chatMessages = document.getElementById('chatMessages');
|
| 921 |
+
// if (!chatMessages) {
|
| 922 |
+
// console.error('Chat messages container not found for menu items!');
|
| 923 |
+
// return;
|
| 924 |
+
// }
|
| 925 |
|
| 926 |
+
// // Clear previous menu items if they exist
|
| 927 |
+
// let menuItemsList = document.querySelector('.menu-items-list');
|
| 928 |
+
// if (!menuItemsList) {
|
| 929 |
+
// menuItemsList = document.createElement('div');
|
| 930 |
+
// menuItemsList.className = 'menu-items-list';
|
| 931 |
+
// chatMessages.appendChild(menuItemsList);
|
| 932 |
+
// } else {
|
| 933 |
+
// // Clear existing items to avoid duplication
|
| 934 |
+
// menuItemsList.innerHTML = '';
|
| 935 |
+
// }
|
| 936 |
|
| 937 |
+
// // Log to verify the dishes being fetched
|
| 938 |
+
// console.log('Fetched menu items:', menuItems);
|
| 939 |
|
| 940 |
+
// // If menuItems is an empty array, add a message indicating no items found
|
| 941 |
+
// if (menuItems.length === 0) {
|
| 942 |
+
// const noItemsMessage = document.createElement('div');
|
| 943 |
+
// noItemsMessage.textContent = 'No dishes available at the moment.';
|
| 944 |
+
// menuItemsList.appendChild(noItemsMessage);
|
| 945 |
+
// } else {
|
| 946 |
+
// menuItems.forEach(item => {
|
| 947 |
+
// const menuItem = document.createElement('div');
|
| 948 |
+
// menuItem.className = 'menu-item';
|
| 949 |
+
// const img = document.createElement('img');
|
| 950 |
+
// img.src = item.image_url || 'https://via.placeholder.com/120';
|
| 951 |
+
// img.alt = item.name;
|
| 952 |
+
// const name = document.createElement('div');
|
| 953 |
+
// name.textContent = item.name;
|
| 954 |
+
// const button = document.createElement('button');
|
| 955 |
+
// button.textContent = 'Add to Cart';
|
| 956 |
+
// button.onclick = () => {
|
| 957 |
+
// selectedMenuItem = item;
|
| 958 |
+
// addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
|
| 959 |
+
// const options = [
|
| 960 |
+
// { text: 'Yes', class: 'green' },
|
| 961 |
+
// { text: 'No', class: 'red' }
|
| 962 |
+
// ];
|
| 963 |
+
// currentStep = 'customization';
|
| 964 |
+
// displayOptions(options);
|
| 965 |
+
// };
|
| 966 |
+
// menuItem.appendChild(img);
|
| 967 |
+
// menuItem.appendChild(name);
|
| 968 |
+
// menuItem.appendChild(button);
|
| 969 |
+
// menuItemsList.appendChild(menuItem);
|
| 970 |
+
// });
|
| 971 |
+
// }
|
| 972 |
|
| 973 |
+
// // Ensure the display is scrolled to the latest message
|
| 974 |
+
// chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 975 |
|
| 976 |
+
// // Log that menu items were displayed
|
| 977 |
+
// console.log('Menu items displayed');
|
| 978 |
+
// }
|
| 979 |
|
| 980 |
|
| 981 |
|